I just can't understand why the gl_ClipDistance doesn't work. The result is the same as I didn't set the gl_ClipDistance.
I had set "glEnable(GL_CLIP_DISTANCE0) ;glEnable(GL_CLIP_DISTANCE1) ;"by application.
the vertex shader is like this:
#version 410
uniform mat4 mvpMatrix;
//.......some other uniforms here
in vec2 vVertex;
uniform vec4 clip_plane=vec4(1.0,1.0,0.0,0.85);
uniform vec4 clip_sphere=vec4(0.0,0.0,0.0,10.0);void main(void)
{
//........some other code,include vec2 worldPos
vec4 worldPosition=vec4(worldPos.x,height,worldPos.y,1.0);
gl_ClipDistance[0]=dot(worldPosition,clip_plane);
gl_ClipDistance[1]=length(worldPosition.xyz/worldPosition.w-clip_sphere.xyz)-clip_sphere.w;
gl_Position = mvpMatrix * position;
}
I tried to only set "glEnable(GL_CLIP_DISTANCE0)"and"gl_ClipDistance[0]=-1.0" ,but what make me confused is that my model just still stay there,didn't disappear.
Anybody know how this happen?
Solved! Go to Solution.
The problem is solved.The code is right. GPU is the key. When I change the AMD card to NVIDIA card, the code works well.
The problem is solved.The code is right. GPU is the key. When I change the AMD card to NVIDIA card, the code works well.
Hi!
Try to size the gl_ClipDistance array in the shader and see if that solves it. (e.g. "out float gl_ClipDistance[6]").
Although this shouldn't be needed if indexed with a constant integer (like you already are), I found that it solved a similar issue for me on my R9 290. (note: my notebook's GTX550M didn't complain, similar to your findings)
ionutcava 撰写:
Try to size the gl_ClipDistance array in the shader and see if that solves it. (e.g. "out float gl_ClipDistance[6]").
Did you solve your problem by this? I tried,but it didn't work.
Sorry for the late reply. Here's how I'm setting clip planes in the vert shader and it's working fine for me on AMD, NVidia and Intel:
#if defined(VERT_SHADER)
out float gl_ClipDistance[MAX_CLIP_PLANES];
void setClipPlanes(in vec4 worldSpaceVertex) {
# if MAX_CLIP_PLANES > 0
gl_ClipDistance[0] = dot(worldSpaceVertex, dvd_clip_plane[0]);
# endif
# if MAX_CLIP_PLANES > 1
gl_ClipDistance[1] = dot(worldSpaceVertex, dvd_clip_plane[1]);
# endif
.........
}
#endif