pouët.net

Go to bottom

gl_ClipDistance nightmare

category: code [glöplog]
 
Hello.

I've implemented some custom clipping planes, and it looks that they work (at least with points), but I can't make it work with a geometry shader (transforms lines to triangle strips for wide lines) running.

If I don't touch the gl_ClipDistance values into the geometry shader I don't have clipping, ok. But I haven't found a way of copying the values.

This way I get a ERROR: 0:38: Indirect index into implicitly-sized array
Code:out float gl_ClipDistance[]; void main() { ... gl_Position = vec4(p0.xy + offset * w0, gl_in[0].gl_Position.zw); for ( int i = 0; i < MAX_CLIP_PLANES; ++i ) gl_ClipDistance[i] = gl_in[0].gl_ClipDistance[i]; _vertex_color = _color[0]; EmitVertex();


This way the compiler hangs.
Code:out float gl_ClipDistance[]; void main() { ... gl_Position = vec4(p0.xy + offset * w0, gl_in[0].gl_Position.zw); gl_ClipDistance = gl_in[0].gl_ClipDistance; _vertex_color = _color[0]; EmitVertex();


Now I get, ERROR: Input of geometry shader '<in gl_PerVertex.gl_ClipDistance>' differs in type/qualifiers to that written by vertex shader.
It doesn't matter if gl_ClipDistance is defined with a size or not.
Code:out float gl_ClipDistance[]; void main() { ... gl_Position = vec4(p0.xy + offset * w0, gl_in[0].gl_Position.zw); gl_ClipDistance[0] = gl_in[0].gl_ClipDistance[0]; _vertex_color = _color[0]; EmitVertex();


This is my vertex shader.
Code: #ifdef GL_ES precision highp float; #endif #define MAX_CLIP_PLANES 6 layout(std140) uniform ClipPlanes { uniform vec4 clipPlanes[MAX_CLIP_PLANES]; }; out float gl_ClipDistance[MAX_CLIP_PLANES]; void applyClipping(mat4 modelMatrix, vec3 position) { for ( int i = 0; i < MAX_CLIP_PLANES; ++i ) gl_ClipDistance[i] = dot(modelMatrix * vec4(position, 1.0), clipPlanes[i]); } layout(location = 0) in vec3 position; flat out vec4 _color; void main (void) { gl_Position = modelViewProjectionMatrix * vec4(position, 1.0); applyClipping(modelMatrix, position); }


Thanks.
added on the 2015-10-29 12:43:35 by swapd0 swapd0
Sorry, I fotgot to change the category.
added on the 2015-10-29 13:13:43 by swapd0 swapd0
Ok, partial fixed.

I've to call applyClipping() into geometry shader, not into vertex shader. But it looks that the lines are clipped "too early".
added on the 2015-10-29 13:35:59 by swapd0 swapd0
Fixed.

I don't understand why I couldn't find the error between yesterday and this morning, but some minutes after I post here I realized what I was doing wrong.
added on the 2015-10-29 14:54:07 by swapd0 swapd0
Sometimes all it takes is a cardboard programmer or something to facilitate the similar rubber duck debugging to see the problem you spent so long on already. While I don't practice the latter, I've also found temporarily giving up and going off to other things or sleeping causes me to see it almost right away when I come back because I've lost most of the context I had and have to step through it again.

login

Go to top