Jump to content
  • Advertisement
Sign in to follow this  

clip planes in shaders

This topic is 4648 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
		OUT.colour = float4(0, 1, 0, 0); // back
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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!