// 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?
clip planes in shaders
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:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement