Anonymous Login
2021-09-18 05:12 UTC

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0001841OpenClonkEngine - Renderingpublic2017-08-12 15:07
Assigned ToLuchs 
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:

Patch with workaround: - 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 Files
  • png file icon cc72dd0365c146c4a959bd6772e57989.png (838,889 bytes) 2016-11-01 19:40
  • ? file icon alt-patch.glsl (979 bytes) 2016-11-27 00:02
  • diff file icon alt-patch-2.diff (1,013 bytes) 2016-11-27 19:52 -
    diff --git a/planet/Graphics.ocg/LandscapeShader.glsl b/planet/Graphics.ocg/LandscapeShader.glsl
    index fd26967..92e2b41 100644
    --- a/planet/Graphics.ocg/LandscapeShader.glsl
    +++ b/planet/Graphics.ocg/LandscapeShader.glsl
    @@ -105,7 +105,7 @@ slice(material)
     	int matMapIx = f2i(landscapePx.r);
     	vec4 matMap = queryMatMap(2*matMapIx);
     	vec4 matMapX = queryMatMap(2*matMapIx+1);
    -	float materialIx = f2i(matMap.a) / 256.0 * materialDepth;
    +	float materialIx = int(matMap.a * (materialDepth - 1) + 0.5);
     	vec3 matEmit = matMap.rgb;
     	vec3 matSpot = matMapX.rgb * 255.9f / 16.0f;
     	float matAngle = matMapX.a;
    @@ -117,7 +117,7 @@ slice(material)
     	int matMapIx2 = f2i(landscapePx2.r);
     	vec4 matMap2 = queryMatMap(2*matMapIx2);
     	vec4 matMapX2 = queryMatMap(2*matMapIx2+1);
    -	float materialIx2 = f2i(matMap2.a) / 256.0 * materialDepth;
    +	float materialIx2 = int(matMap2.a * (materialDepth - 1) + 0.5);
     	vec3 matEmit2 = matMap2.rgb;
     	vec3 matSpot2 = matMapX2.rgb * 255.9f / 16.0f;
     	float matAngle2 = matMapX2.a;
    diff file icon alt-patch-2.diff (1,013 bytes) 2016-11-27 19:52 +




Luchs (administrator)

ck: You wrote the current renderer, I think. Any idea what would cause this?


Clonk-Karl (administrator)

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?


Luchs (administrator)

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.


Luchs (administrator)

The alternative patch does not work on o11c's system.


occ (reporter)

Hi! There's been a check-in that references this bug. For more information you can visit the repository browser at this address:

Changeset 88361ab by Armin Burgmeier <>
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.


Clonk-Karl (administrator)

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.


Clonk-Karl (administrator)

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.


Luchs (administrator)

>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.


occ (reporter)

Hi! There's been a check-in that references this bug. For more information you can visit the repository browser at this address:

Changeset 02fa5ab by Armin Burgmeier <>
Fix material/texture selection in landscape shader (0001841)


Luchs (administrator)

Fulgen reported seeing the same problem and that the second patch fixes it. I pushed that patch to the repository now.

-Issue History
Date Modified Username Field Change
2016-11-01 19:34 Luchs New Issue
2016-11-01 19:36 Luchs Note Added: 0005479
2016-11-01 19:40 Luchs File Added: cc72dd0365c146c4a959bd6772e57989.png
2016-11-27 00:02 Clonk-Karl File Added: alt-patch.glsl
2016-11-27 00:02 Clonk-Karl Note Added: 0005505
2016-11-27 11:18 Luchs Note Added: 0005506
2016-11-27 18:11 Luchs Note Added: 0005507
2016-11-27 19:25 occ Note Added: 0005508
2016-11-27 19:35 Clonk-Karl Note Added: 0005509
2016-11-27 19:52 Clonk-Karl File Added: alt-patch-2.diff
2016-11-27 19:52 Clonk-Karl Note Added: 0005510
2016-11-27 23:00 Luchs Note Added: 0005511
2017-08-12 15:05 occ Note Added: 0005716
2017-08-12 15:07 Luchs Assigned To => Luchs
2017-08-12 15:07 Luchs Status new => resolved
2017-08-12 15:07 Luchs Resolution open => fixed
2017-08-12 15:07 Luchs Fixed in Version => 8.0
2017-08-12 15:07 Luchs Note Added: 0005717
+Issue History