Game/MMD
LisPSM (2)
newpolaris
2017. 11. 5. 02:01
우선, left hand 로 바꾸고 light matrix 만 구해서 orthographic 을 사용하는 버전을 테스트 해보자
그냥 임의의 min/max box
DirectX::XMMatrixOrthographicOffCenterLH
float2 TransTexCoord = ShadowPos.xy;
if (!any( saturate( TransTexCoord ) != TransTexCoord ))
{
ShadowPos = saturate( ShadowPos );
float3 shadowPosDX = ddx_fine( ShadowPos );
float3 shadowPosDY = ddy_fine( ShadowPos );
saturate 없으면 ground 에서 깊이가 1.0 초과하는 값이 나와서 항상 실패하는 부분이 나온다.
UnitCubeClip 적용
Nvidia sample에는 BuildOrthoShadowProjectionMatrix 라 되어있다
Matrix4 lightView = Matrix4(XMMatrixLookAtLH( lightPt, frustumCenter, axis ));
frustumAABB = lightView * frustumAABB;
casterAABB = lightView * casterAABB;
// use a small fudge factor for the near plane, to avoid some minor clipping artifacts
Matrix4 lightProj = Matrix4( DirectX::XMMatrixOrthographicOffCenterLH(
frustumAABB.m_Min.GetX(), frustumAABB.m_Max.GetX(),
frustumAABB.m_Min.GetY(), frustumAABB.m_Max.GetY(),
casterAABB.m_Min.GetZ(), frustumAABB.m_Max.GetZ() ) );
lightView = lightView * view;
m_SunShadow.SetViewProjectMatrix( lightView, lightProj );
View space에서 AABB 박스의 중심에서 광원으로의 방향으로의 교차점을 구해서
light view를 구하고 AABB의 min/max 를 offcenter로 꽉차게 만든거다.
뒤의 꽉차게 projection matrix 만드는걸 unit cube clip 이라 하는 듯