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

This topic is 2473 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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:
[attachment=7544:???.jpg]

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..
\

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

##### Share on other sites
I get it:

left hand:
 void CCamera::SetClipPlane(const CPlane& WorldClipPlane) { CMatrix4x4 ClipProjectionMatrix(m_ViewProjectionMatrix); CPlane Plane(WorldClipPlane); Plane.Normalize(); ClipProjectionMatrix.Invert4x4(); ClipProjectionMatrix.Transpose(); CPlane ClipPlane(Plane); ClipPlane *= ClipProjectionMatrix; if(ClipPlane.w == 0) return; if (ClipPlane.w > 0) { ClipPlane.x = - Plane.x; ClipPlane.y = - Plane.y; ClipPlane.z = - Plane.z; ClipPlane.w = - Plane.w; ClipPlane *= ClipProjectionMatrix; } ClipProjectionMatrix.Identity(); 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 glMatrixMode(GL_PROJECTION); glLoadMatrix(matrix); } 

##### Share on other sites
when i apply a wave on the water surface, the clip projection matrix is not working.
the inverted image is break up.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013187
×