Jump to content
  • Advertisement
Sign in to follow this  

Basic Reflections with shader

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

I have been struggling with trying to implement basic reflections with a shader. I am polishing up a grad students projects which is a hockey game. Trying to add some reflection support for the ice. Here is what I do:

glScale3f(1, -1, 1)
glScale3f(1, 1, 1)

I have verified that the reflection frame buffer generates the proper texture containing the reflection of the scene. I rendered it in orth mode to the screen so I can verify.

The problem is in my vertex shader. It is spitting on terrible texture coordinates. The reflections are appearing in the wrong spot. To avoid cutting apart my very large shader to get at just the reflection stuff I was hoping to find a tutorial or example on reflections using shaders in GLSL. Sadly I found no such example. So I am here on gamedev asking if someone can guide the shader step in this process.


Share this post

Link to post
Share on other sites
It sounds like you trying to mix two different ways of doing reflections. Here are the steps I use to render reflections. Stick to them and you won't have any issues.

NOTE: This only works with scene AND camera +Y as up.

void preRenderScene() {
// Begin rendering to the framebuffer

// Preserve previous matrix

// Reset the matrix

// Scale the scene by (-1, 1, 1)
glScalef(-1.0f, 1.0f, 1.0f);

// Invert the camera over the plane of reflection
CameraPosition.x, 2.0f * height - CameraPosition.y, CameraPosition.z,
CameraCenter.x, 2.0f * height - CameraCenter.y, CameraCenter.z,
0.0f, -1.0f, 0.0

// Draw the reflected objects

// Restore the previous matrix

// Finish the FBO

void renderScene() {
// Draw the objects

// Draw the Ice

void renderObjects() {
// Apply the camera
CameraPosition.x, CameraPosition.y, CameraPosition.z,
CameraCenter.x, CameraCenter.y, CameraCenter.z,
0.0f, 1.0f, 0.0f

// Extract the frustum
// Render the objects

void renderIce() {
// Your code here

All this will work. If it doesn't, you either don't have +Y as up, or your shader has problems.

Additional Note: glScalef(1, 1, 1) does NOTHING.

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!