## Rendering a reflection about an arbitrary plane

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
So I've rendered reflections ( for water ) in the past, but my reflections were restricted to a plane described as simply a function of Z ( where Z is up ).

My code looked something like so ( taken from my water demo, leaving out clip planes ):
Code:
```glPushMatrix(); glTranslatef( 0.0f, 0.0f, _currentWaterLevel ); glScalef( 1.0, 1.0, -1.0 ); glTranslatef( 0.0f, 0.0f, -_currentWaterLevel ); renderScene(); glPopMatrix();```

What I'm wondering, is how I can reflect about an arbitrary plane, described in (a,b,c,d) format. I imagine a matrix can be constructed which would represent the inversion, but I'm weak. Any suggestions?
Member
Posts: 45
Joined: 2006.07
Post: #2
I'm pretty sure you can use one of these: http://en.wikipedia.org/wiki/Householder_reflection

Let n = (a, b, c) be the normal of the plane and let p be some point the plane passes through. Then make the 3x3 matrix H = I - 2nn^T =

Code:
```[ 1-2*a^2,  -2*a*b,  -2*a*c] [  -2*a*b, 1-2*b^2,  -2*b*c] [  -2*a*c,  -2*b*c, 1-2*c^2]```

Then do something like
Code:
```glTranslatef(px, py, pz) glMultMatrixf(H) glTranslatef(-px, -py, -pz);```
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
That looks like what I'm looking for. I'll give it a stab ( unfortunately, I won't be able to for a couple more days, as I work out the render to FBO pipeline in my current codebase ).

Thanks!
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
It's been a few weeks, but as of last night reflection rendering in my code is robust, flexible, reasonably fast, and works like a champ. I wanted to post a couple screenshots just to show off.

Thanks for the help! Without the householder transform I'd never have gotten this working!