I build a normal projection matrix with the following code:
/** * Create a right-handed perspective projection matrix based on a field of view. * * \param _fFov Field of view in the y direction, in radians. * \param _fAspect Aspect ratio, defined as view space width divided by height. * \param _fNear Z-value of the near view-plane. * \param _fFar Z-value of the far view-plane. */ LSMVOID LSM_CALL CMatrix4x4::PerspectiveFovRH( LSMREAL _fFov, LSMREAL _fAspect, LSMREAL _fNear, LSMREAL _fFar ) { // Zero out the ones that need to be zero. _12 = _13 = _14 = LSM_ZERO; _21 = _23 = _24 = LSM_ZERO; _31 = _32 = LSM_ZERO; _41 = _42 = _44 = LSM_ZERO; LSMREAL fDist = LSM_ONE / (_fNear - _fFar); // Set the remaining ones. _22 = LSM_ONE / CMath::Tan( LSM_HALF * _fFov ); _11 = _22 / _fAspect; _33 = (_fFar + _fNear) * fDist; _34 = -LSM_ONE; _43 = (LSM_TWO * _fFar * _fNear) * fDist; }
This is row-major, as in DirectX®. _33 and _43 are the important values.
When I render my shadow volumes I basically do this:
_33 = LSM_FLT_EPSILON - LSM_ONE; // Standard machine epsilon here._43 = static_cast<LSMREAL>(0.2) * -LSM_TWO; // As an example, assume the near plane is at 0.2.
But no matter what values I set there I get clipping, and quite close to the camera. It actually clips at the near plane too, heavily noticeably.
I am extruding my shadow volume out at about 10,000 units. My regular far plane is at 2,000 units.
Any idea what I am doing wrong? The shadow volumes themselves are fine (as far as being correct geometry, but maybe I need to adjust how far I extrude them). If I use my normal projection, it works perfectly as long as I position my view so that none of the shadow volumes pass the far plane.
Thank you,
Yogurt Emperor