Jump to content

  • Log In with Google      Sign In   
  • Create Account

Reflection and Clipping Plane


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 hdlopesrocha   Members   -  Reputation: 145

Like
0Likes
Like

Posted 20 June 2012 - 06:32 PM

Hi again!

I'm on an adventure with the reflection in the water.

I have 3 Render Targets:
- Down Target - where I draw everything below the water height
- Reflect Target - where I draw everything reflected
- Up Target - where I draw everything above the water height

Then I start Render with that order with:
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

here is a screenshot:
Posted Image


Now my problem is to remove the down part from the reflection. By other words, render the down part only where is Water (remove the red area).

PS: I draw the water in the down target. Ignore the trees in the down target.

Any Advice?
Thanks ;-)

Sponsor:

#2 xycsoscyx   GDNet+   -  Reputation: 318

Like
1Likes
Like

Posted 20 June 2012 - 06:42 PM

One simple way would be to use the stencil buffer. Before you draw your reflections, make a stencil of the water (so render the water plane like you normally would, only writing to the stencil buffer), then when you render your reflections, only draw in the stencil area.

#3 hdlopesrocha   Members   -  Reputation: 145

Like
0Likes
Like

Posted 20 June 2012 - 06:47 PM

One simple way would be to use the stencil buffer. Before you draw your reflections, make a stencil of the water (so render the water plane like you normally would, only writing to the stencil buffer), then when you render your reflections, only draw in the stencil area.



And how can I write to the stencil buffer?

Thanks ;-)

#4 xycsoscyx   GDNet+   -  Reputation: 318

Like
1Likes
Like

Posted 20 June 2012 - 06:59 PM

I'm not sure the specifics with XNA, but here's a good tutorial which explains stencil shadows in XNA. The operations are the same and the tutorial seems to explain some of the general stencil ideas and what it does.

http://msdn.microsoft.com/en-us/library/bb464050(v=xnagamestudio.30).aspx

The basic idea is that the stencil buffer is part of your depth buffer, when you create your device and specify a depth buffer format, you specify one that includes a stencil channel. You can then render into that just like you do the depth/color buffers, but you can also do tests against the values as well. When you render the stencil, you basically just render your water to create it's shape in the stencil buffer. Then when you render your reflections, you test against that shape to see if you should render a pixel or not, only pixels inside your stencil (inside the water shape) will pass the test and be drawn.

#5 hdlopesrocha   Members   -  Reputation: 145

Like
0Likes
Like

Posted 20 June 2012 - 08:26 PM

Thank you, thank you, thank you, thank you, thank you, thank you.
I am so happy :-)
Here is the result:

Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS