View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

#1db123  Members

Posted 02 March 2012 - 05:37 AM

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

I have resolved matrix problem.

#2db123  Members

Posted 02 March 2012 - 09:35 AM

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);
}


#3db123  Members

Posted 03 March 2012 - 02:08 AM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.