Jump to content
  • Advertisement
Sign in to follow this  

Clipping planes and shaders?

This topic is 3428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to insert a clipping plane to clip a sphere that I am rendering with Cg shaders:
GLdouble plane[4] = {0.0, 0.0, 1.0, -10 };
glPushMatrix();
glClipPlane(GL_CLIP_PLANE0, plane);
glEnable(GL_CLIP_PLANE0);

    // Loading and binding the vertex and fragment program.
    render_sphere();

glDisable(GL_CLIP_PLANE0);
glPopMatrix();


But nothing happens, the whole sphere is rendered. How do I get the clipping plane to actually clip the sphere?

Share this post


Link to post
Share on other sites
Advertisement
no to sure about clipping planes + shaders (clipping planes are outdated though)
u can implement clipping yourself in a shader eg in glsl


uniform vec4 plane; // xyz=normal, w=dist
varying vec3 pos;


if ( dot( plane.xyz, pos ) - P.w < 0.0 )
discard;

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
no to sure about clipping planes + shaders (clipping planes are outdated though)
u can implement clipping yourself in a shader eg in glsl


uniform vec4 plane; // xyz=normal, w=dist
varying vec3 pos;


if ( dot( plane.xyz, pos ) - P.w < 0.0 )
discard;



What is "P.w"?

Share this post


Link to post
Share on other sites
Quote:
Original post by mlt
Quote:
Original post by zedz
no to sure about clipping planes + shaders (clipping planes are outdated though)
u can implement clipping yourself in a shader eg in glsl


uniform vec4 plane; // xyz=normal, w=dist
varying vec3 pos;


if ( dot( plane.xyz, pos ) - P.w < 0.0 )
discard;
What is "P.w"?
Presumably he meant plane.w

As to your original question, how big is your sphere? It may be entirely to one side of the plane.

Share this post


Link to post
Share on other sites
In the vertex program I pass the position in clip-space to the fragment program:

	
OUT.clip_pos = mul(ModelViewProj, IN.position);



I also pass the clipping-plane height to the fragment program in clip-space:

	

// height is currently 0.7.
OUT.clip_plane_height = mul(ModelViewProj, float4(0.0,0.0,height,0.0)).z;



Then in the fragment program I clip the fragment if its below the plane height:


if (clip_pos.y < clip_plane_height) {
clip(float4(0.0, 0.0, 0.0, -10));
}



But its wrong as can be seen from the below images:

http://img87.imageshack.us/img87/4756/clippf1.jpg

http://img71.imageshack.us/img71/883/clip2kl8.jpg


The gray plane corresponds to the clipping-plane in z = 0.7, but the fragments clipped totally ignores this plane. Any hints are very appreciated!



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!