Skip to main content
gamedev.net
🔒 Locked

Clipping planes in Shader Model 2.0

Started by lsdogsdnbgj 3 replies 3.3k views
Original Post
lsdogsdnbgj
lsdogsdnbgj
Hi everyone,

I'm trying to add refraction to my water engine, and I am having a little trouble with using a clipping plane (I only need to render stuff below the water into my refraction map) in my shader. How can I implement this?

Thanks!
belfegor
belfegor

I am not sure and i had no time to test it but there is a HLSL clip function, so you might use point-plane relationship function for parameter, something like:


void VertexMain(...)
{
    ...
    OUT.worlPos = mul( IN.Position, World );
}
 
float4 plane; // water plane
 
void PixelMain()
{
    ...
    clip( dot( IN.worldPos, plane.xyz ) + plane.w );
}

BTW. Isn't clipping used for reflection and not for refraction?

lsdogsdnbgj
lsdogsdnbgj

I might give that a try, thanks! I was thinking of finding the distance of the point from the plane, but I didn't know about the clip() function. I actually tried without clipping, and you're right - it works just fine. I guess it makes sense since you only sample from the part of the image which shows the underwater stuff anyway. For some reason the Rastertek tutorial on refraction mapping uses clipping - maybe it's slightly faster to not render the whole scene to the refraction map? Anyway, here's how it looks:


[attachment=15982:RefractingWater3.png]

[attachment=15983:RefractingWater1.png]

belfegor
belfegor

Nice results. smile.png

lsdogsdnbgj
lsdogsdnbgj
Thanks! It's cool that this method works for frosted glass too. Also, it works more efficiently of I only draw a new refraction map when the camera has moved.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.