cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

yan_qingsong
Adept I

why the gl_ClipDistance[] doesn't work?

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?

0 Likes
1 Solution
yan_qingsong
Adept I

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.

View solution in original post

0 Likes
4 Replies
yan_qingsong
Adept I

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.

0 Likes

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)

0 Likes

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.

0 Likes

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

0 Likes