Jump to content
  • Advertisement
Sign in to follow this  
db123

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.

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:
[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.
rolleyes.gif
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..sad.png sad.png sad.png
\

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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
mellow.png mellow.png when i apply a wave on the water surface, the clip projection matrix is not working.
sad.png the inverted image is break up.

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!