Advertisement Jump to content
Sign in to follow this  

Direction needed for writing a reflection shader

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

Hello, I have been scouring the net for example code or even a very good explanation for writing a reflection shader. What I am trying to do is I have a room with chairs and table and the texture for the floor is a marble looking texture. I want to write a reflection shader so the floor looks like it's reflecting the furniture in the room. I am using D3D 9.0c. I am pretty new to the world of shaders. I would assume that I would have to render to the stencil buffer and then invert the scene. But as far as rendering this to a texture and then wrap the texture to the floor, I'm not exactly sure how to go about it so it actually looks realistic. If anyone can explain, reference to a sample or article, I would really appreciate it. Thanks!

Share this post

Link to post
Share on other sites
As you said, it consists of two parts:

1) Rendering the view from the mirror to a texture.
2) Applying this "mirror texture" to your marble floor.

Step 1 can be done with a clipping plane and render targets (aka "render to texture"). Step 2 requires "Projective Texture Mapping" (aka "projected texture coordinates"). All of these features are available without shaders, but of course can be done with shaders as well.

Another good search term to find some tutorials might be "planar reflections".

There is another way to do this effect though, which I don't recommend, which is the stencil buffer technique. Using this approach, you don't use a render target -- instead the reflections (i.e. view from the mirror) are drawn last, and are masked out by the stencil buffer.
I prefer the render target technique as it combines easier with other effects, and can be enhanced with extra details with some more shader code - such as distorting the reflection using a bump map of some kind.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!