Sign in to follow this  

clip planes in shaders

This topic is 4338 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

okay, so with shaders standard clip planes dont work. Now my problem is i need clipping. So my idea is to upload my clip plane in world space, i could easily change this to the appropriate space if it wont work correctly. In my vertex shader, i transform this using the inverse transpose of model * view * projection model is simply identity ATM. so i have my plane: normal: 0,1,0 distance from origin = 0 so: 0,1,0,0 a plane facing strait up. this gets uploaded to my vertex shader, and transformed: OUT.position = mul( modelViewProjection, float4(IN.position, 1.0) ); OUT.clipPlane = mul( modelViewProjectionIT, cPlane); then in my pixel shader, i check what side of the plane the pixel is on:
	// check side of plane		
	float value = IN.clipPlane.x * IN.position.x + IN.clipPlane.y * IN.position.y + IN.clipPlane.z * IN.position.z - IN.clipPlane.w;
	
	if (value >= 0)
	{
		OUT.colour = float4(1, 0, 0, 0); //front and on
	}
	else
	{
		OUT.colour = float4(0, 1, 0, 0); // back
		clip(-1);
	}
so seems no clipping is occuring in this case. if i change it to use model * view * projection i get clipping along my plane, but it then depends on if i look up or down as to which side of the plane is being clipped. Any ideas?

Share this post


Link to post
Share on other sites

This topic is 4338 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this