Jump to content
  • Advertisement
Sign in to follow this  
george7378

Clipping planes in Shader Model 2.0

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

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!

Share this post


Link to post
Share on other sites
Advertisement

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?

Edited by belfegor

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!