Clipping to do Reflection and Refraction maps

Hi,

I’m currently following a tutorial to add some water on my game, and in this tutorial, the author uses the GraphicsDevice.ClipPlane property but it doesn’t exists in MonoGame.

How can I solve this problem and get my refractive map from a plane?

Thanks in advance.

Tutorial: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Refraction_map.php

You can use HLSL clip(…) function instead of the GraphicsDevice.ClipPlanes.
Shawn Hargreaves describes the whole thing here: http://xboxforums.create.msdn.com/forums/t/56786.aspx

I recommend using an oblique view frustum (“Lengyel’s Frustum”) instead of a clip plane.

See:

  • Lengyel, Eric. “Oblique View Frustum Depth Projection and Clipping”. Journal of Game Development, Vol. 1, No. 2 (2005), Charles River Media, pp. 5–16. Online: http://www.terathon.com/code/oblique.html

Hello!

Thanks for your replies! I’ll try to used that :slightly_smiling:

I have a little question more thow; should I implement the “clipping” in all my shaders or can I create a common shader only for clipping?

Like, when I want to clip something, I draw my model or terrain with his effect and also with the clipping effect. Do you think it’s possible?

Thanks

That isn’t how shaders/effects work.

You need to include the clipping code in your vertex shader used for rendering. You can use #includes in your HLSL code to share that code between several shaders.

Oh I see, thanks for the tip @Tom :slight_smile:

I’ll create a “Common” shader that I will include in my shaders for Clipping then.