Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently I am trying to reflect a sky sphere into a flat piece of geometry which is acting as water. The sphere is very small, it follows the camera on all 3 axis and the z-buffer is turned off so it appears behind everything else.

Can someone please tell me how I can reflect the world matrix on a xz plane. And should I the plane be the water height or the camera height.

Thank you.

share|improve this question

Given a general plane with equation A*x + B*y + C*z + D = 0, the reflection matrix for this plane is:

1 - 2*A*A,    -2*A*B,    -2*A*C, 0,
   -2*B*A, 1 - 2*B*B,    -2*B*C, 0,
   -2*C*A,    -2*C*B, 1 - 2*C*C, 0,
   -2*A*D,    -2*B*D,    -2*C*D, 1

This is for OpenGL, so you might need to transpose the matrix for DirectX or something. Unfortunately I can't find any sources for the formula.

For your simpler case with xz-plane, a simpler matrix is enough. The following matrix mirrors in y-direction with y given as the plane height.

1,  0, 0, 0,
0, -1, 0, 0,
0,  0, 1, 0,
0,-2y, 0, 1

Again you might need to transpose the matrix or switch -2y to 2y.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.