OpenClonk Bugtracker - OpenClonk
View Issue Details
0001841OpenClonkEngine - Renderingpublic2016-11-01 19:342017-08-12 15:07
ReporterLuchs 
Assigned ToLuchs 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformGNU G++OSLinuxOS Version 
Product Versiongit master 
Target Version8.0Fixed in Version8.0 
Summary0001841: Landscape shader selects wrong material texture
DescriptionIRC user o11c reported in #openclonk that on their system, the landscape textures are mixed up.

Example screenshot: http://picpaste.com/pics/cc72dd0365c146c4a959bd6772e57989.1477815063.png

Patch with workaround: https://gist.github.com/o11c/4524a20f53aab8554d6e265d5fcfcb99 - 0.5 breaks it on my system, smaller values between 0.1 and 0.4 seem to work.

Additional InformationOpenGL renderer string: Gallium 0.4 on AMD ARUBA (DRM 2.45.0 / 4.7.0-1-amd64, LLVM 3.8.1)
TagsNo tags attached.
Attached Filespng cc72dd0365c146c4a959bd6772e57989.png (838,889) 2016-11-01 19:40
https://bugs.openclonk.org/file_download.php?file_id=658&type=bug
? alt-patch.glsl (979) 2016-11-27 00:02
https://bugs.openclonk.org/file_download.php?file_id=662&type=bug
diff alt-patch-2.diff (1,013) 2016-11-27 19:52
https://bugs.openclonk.org/file_download.php?file_id=663&type=bug

Notes
(0005479)
Luchs   
2016-11-01 19:36   
ck: You wrote the current renderer, I think. Any idea what would cause this?
(0005505)
Clonk-Karl   
2016-11-27 00:02   
I always found the float/integer index conversions in that shader somewhat spooky. Attached another suggestion that makes the code simpler instead of more complex. Any chance we can try that on the system that showed incorrect textures?

Does the workaround with 0.5 work an that system? What about 0.1 to 0.4?
(0005506)
Luchs   
2016-11-27 11:18   
I'll forward it to o11c. 0.1 to 0.4 worked for both him and me, I think. 0.5 only worked for him.
(0005507)
Luchs   
2016-11-27 18:11   
The alternative patch does not work on o11c's system.
(0005508)
occ   
2016-11-27 19:25   
Hi! There's been a check-in that references this bug. For more information you can visit the repository browser at this address:
https://git.openclonk.org/openclonk.git/commitdiff/88361ab606a3905f497077cb13f173483030e165

Changeset 88361ab by Armin Burgmeier <armin@arbur.net>
Use NEAREST texture filtering for material map

The material map is 1D texture that contains information about every
material-texture combination. There is no point in linear filtering,
i.e. trying to interpolate between two materials such as gold and granite
or whichever two materials happen to be adjacent in the material map texture.

This might or might not be relevant to 0001841, but should be more correct
behavior in any case.

(0005509)
Clonk-Karl   
2016-11-27 19:35   
For some reason it seems that on o11c's system the index read from the material map is somewhat lower that it should be (for some materials at least--from the screenshot it doesn't look like all materials are screwed up). I'm not exactly sure how that could consistently happen, but I've found that when looking up that index in the material map (which is a 1D texture), the interpolation mode is set to linear. I don't know if/when that interpolation would kick in given the texture coordinate we use to look it up, but I changed it to nearest-neighbor instead, which seems more appropriate.

I would expect that every offset between 0.0 and 0.49999 should work, given my understanding of how sampler2DArray works. So I would suggest to try out the new snapshot with "nearest"-interpolation for the material map texture, and if that does not help, add a 0.25 fudge factor.
(0005510)
Clonk-Karl   
2016-11-27 19:52   
Hm, thinking some more I actually believe the previous patch was wrong: it should be "materialDepth - 1", because we need to map the number from the texture between 0 and materialDepth exclusive. Attached another patch that does this... would be great if you could give that a try as well.
(0005511)
Luchs   
2016-11-27 23:00   
>for some materials at least--from the screenshot it doesn't look like all materials are screwed up

I think that's just because there are multiple adjacent earth/sand/rock textures, so it's the wrong texture, but still the correct material.
(0005716)
occ   
2017-08-12 15:05   
Hi! There's been a check-in that references this bug. For more information you can visit the repository browser at this address:
https://git.openclonk.org/openclonk.git/commitdiff/02fa5abc660710952064b8e35462e61bbbbc53d8

Changeset 02fa5ab by Armin Burgmeier <armin@arbur.net>
Fix material/texture selection in landscape shader (0001841)

(0005717)
Luchs   
2017-08-12 15:07   
Fulgen reported seeing the same problem and that the second patch fixes it. I pushed that patch to the repository now.

Issue History
2016-11-01 19:34LuchsNew Issue
2016-11-01 19:36LuchsNote Added: 0005479
2016-11-01 19:40LuchsFile Added: cc72dd0365c146c4a959bd6772e57989.png
2016-11-27 00:02Clonk-KarlFile Added: alt-patch.glsl
2016-11-27 00:02Clonk-KarlNote Added: 0005505
2016-11-27 11:18LuchsNote Added: 0005506
2016-11-27 18:11LuchsNote Added: 0005507
2016-11-27 19:25occNote Added: 0005508
2016-11-27 19:35Clonk-KarlNote Added: 0005509
2016-11-27 19:52Clonk-KarlFile Added: alt-patch-2.diff
2016-11-27 19:52Clonk-KarlNote Added: 0005510
2016-11-27 23:00LuchsNote Added: 0005511
2017-08-12 15:05occNote Added: 0005716
2017-08-12 15:07LuchsAssigned To => Luchs
2017-08-12 15:07LuchsStatusnew => resolved
2017-08-12 15:07LuchsResolutionopen => fixed
2017-08-12 15:07LuchsFixed in Version => 8.0
2017-08-12 15:07LuchsNote Added: 0005717