Skip to content

Commit 7f7c958

Browse files
committed
Fix undefined gl_ClipDistance and use uint for std140 bool
Change `bool clipEnabled` to `uint clipEnabled` in the default-material shader UBO. GLSL bool has implementation-defined std140 layout; uint is portable and matches the SPIR-V decompiled output. Add an else-branch writing `gl_ClipDistance[0] = 1.0` when clipping is disabled. Without this, gl_ClipDistance is undefined and some drivers cull geometry unexpectedly.
1 parent 7fb789f commit 7f7c958

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

code/graphics/shaders/compiled/default-material.vert.spv.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ void main()
3737
{
3838
gl_ClipDistance[0] = dot(_22.clipEquation, _22.modelMatrix * vertPosition);
3939
}
40+
else
41+
{
42+
gl_ClipDistance[0] = 1.0;
43+
}
4044
}
4145

code/graphics/shaders/default-material.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ layout (binding = 1, std140) uniform genericData {
2222

2323
float intensity;
2424
float alphaThreshold;
25-
bool clipEnabled;
25+
uint clipEnabled;
2626
};
2727

2828
layout(binding = 2) uniform sampler2DArray baseMap;

code/graphics/shaders/default-material.vert

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ layout (binding = 1, std140) uniform genericData {
2727

2828
float intensity;
2929
float alphaThreshold;
30-
bool clipEnabled;
30+
uint clipEnabled;
3131
};
3232

3333
void main()
@@ -36,7 +36,9 @@ void main()
3636
fragColor = vertColor * color;
3737
gl_Position = projMatrix * modelViewMatrix * vertPosition;
3838

39-
if (clipEnabled) {
39+
if (clipEnabled != 0u) {
4040
gl_ClipDistance[0] = dot(clipEquation, modelMatrix * vertPosition);
41+
} else {
42+
gl_ClipDistance[0] = 1.0;
4143
}
4244
}

0 commit comments

Comments
 (0)