その先にあるもの…

NVidia NearClipPlane 본문

프로그래밍/3D

NVidia NearClipPlane

specialJ 2014. 3. 25. 17:50

예전에 물을 구현할 때 물 표면에 반사되는 씬을 clipping할때 사용

void NearClipPlane::ClipProjectionMatrix(D3DXMATRIXA16 & matView, D3DXMATRIXA16 & matProj,
                                             D3DXPLANE & clip_plane, LPDIRECT3DDEVICE9 pd3dDevice)
{
  D3DXMATRIXA16 matClipProj;
  D3DXMATRIXA16 WorldToProjection;


  WorldToProjection = matView * matProj;

  // m_clip_plane is plane definition (world space)
  D3DXPlaneNormalize(&clip_plane, &clip_plane);

  D3DXMatrixInverse(&WorldToProjection, NULL, &WorldToProjection);
  D3DXMatrixTranspose(&WorldToProjection, &WorldToProjection);


  D3DXVECTOR4 clipPlane(clip_plane.a, clip_plane.b, clip_plane.c, clip_plane.d);
  D3DXVECTOR4 projClipPlane;

  // transform clip plane into projection space
  D3DXVec4Transform(&projClipPlane, &clipPlane, &WorldToProjection);
  D3DXMatrixIdentity(&matClipProj);


  if (projClipPlane.w == 0)  // or less than a really small value
  {
    // plane is perpendicular to the near plane
    pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj);
    return;
  }
  D3DXVec4Normalize(&projClipPlane, &projClipPlane);  //  bug fix by David Whatley

  if (projClipPlane.w > 0)
  {
      projClipPlane = -projClipPlane;
      projClipPlane.w += 1;
  } 


  // put projection space clip plane in Z column
  matClipProj(0, 2) = projClipPlane.x;
  matClipProj(1, 2) = projClipPlane.y;
  matClipProj(2, 2) = projClipPlane.z;
  matClipProj(3, 2) = projClipPlane.w;

  

  // multiply into projection matrix
  D3DXMATRIXA16 projClipMatrix = matProj * matClipProj;


  pd3dDevice->SetTransform( D3DTS_PROJECTION, &projClipMatrix);

}

http://download.nvidia.com/developer/SDK/Individual_Samples/DEMOS/Direct3D9/NearClipPlane.zip

http://gpgstudy.com/forum/viewtopic.php?t=3677

'프로그래밍 > 3D' 카테고리의 다른 글

Frustum 그리기  (0) 2015.03.19
Z Buffer State  (0) 2015.03.04
Dissolve Shader  (0) 2015.02.11
normal에 역행렬 전치행렬하는 이유  (0) 2014.03.25
동차좌표(homogeneous coordinate)  (0) 2014.02.06
Comments