• Advertisement
Sign in to follow this  

how to make View Matrix and Projective Matrix for reflection by a plane.

This topic is 2147 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 want to render water surface

when i render the scene, use this matrix, it render the whole scene, include the object under the water.
so, when i use this render target as a shader resource view, it looks like this:

I find some materials in google, they said I must create a new projective matrix, which is used to make the plane to be the near clip plane.
I want to clip the primtive which is under the water( the reflection plane).
I want to know how to creat this skewed projection matrix form the reflection plane and the original projective matrix.

or other there are other measures..[img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

[size=5][color=#ff0000]I have resolved matrix problem.[/color][/size]

Share this post

Link to post
Share on other sites
I get it:

left hand:
void CCamera::SetClipPlane(const CPlane& WorldClipPlane)
CMatrix4x4 ClipProjectionMatrix(m_ViewProjectionMatrix);

CPlane Plane(WorldClipPlane);
CPlane ClipPlane(Plane);
ClipPlane *= ClipProjectionMatrix;
if(ClipPlane.w == 0)
if (ClipPlane.w > 0)
ClipPlane.x = - Plane.x;
ClipPlane.y = - Plane.y;
ClipPlane.z = - Plane.z;
ClipPlane.w = - Plane.w;
ClipPlane *= ClipProjectionMatrix;
ClipProjectionMatrix._13 = ClipPlane.x;
ClipProjectionMatrix._23 = ClipPlane.y;
ClipProjectionMatrix._33 = ClipPlane.z;
ClipProjectionMatrix._43 = ClipPlane.w;
m_ProjectionMatrix *= ClipProjectionMatrix;
m_bIsTransformDirty = true;

right hand:
inline float sgn(float a)
if (a > 0.0F) return (1.0F);
if (a < 0.0F) return (-1.0F);
return (0.0F);

void ModifyProjectionMatrix(const Vector4D& clipPlane)
float matrix[16];
Vector4D q;
// Grab the current projection matrix from OpenGL
glGetFloatv(GL_PROJECTION_MATRIX, matrix);

// Calculate the clip-space corner point opposite the clipping plane
// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
// transform it into camera space by multiplying it
// by the inverse of the projection matrix

q.x = (sgn(clipPlane.x) + matrix[8]) / matrix[0];
q.y = (sgn(clipPlane.y) + matrix[9]) / matrix[5];
q.z = -1.0F;
q.w = (1.0F + matrix[10]) / matrix[14];

// Calculate the scaled plane vector
Vector4D c = clipPlane * (2.0F / Dot(clipPlane, q));

// Replace the third row of the projection matrix
matrix[2] = c.x;
matrix[6] = c.y;
matrix[10] = c.z + 1.0F;
matrix[14] = c.w;
// Load it back into OpenGL

Share this post

Link to post
Share on other sites
[img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img] when i apply a wave on the water surface, the clip projection matrix is not working.
[img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] the inverted image is break up.

Share this post

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

  • Advertisement