Phong, Blinn Phong 제작시
viewDir를 쉐이더에서 값을 받아와야 하는데
이를 받는 두가지 방법을 둘다 사용해 보면서 문제상황이 생겼다.


veretx shader 부분 구조 정의할때 Varyings 안에
o.viewDir = normalize(_WorldSpaceCameraPos - vertex.positionWS);
fragment shader에서
viewDirWS = IN.viewDir;


fragment shader에서
float3 viewDirWS = GetWorldSpaceNormalizeViewDir(IN.posWS);
둘이 값 차이가 발생하는데(특정 조건에서) 어느 부분에서 문제가 생긴건지 전혀 모르겠다.

현재 좌표축은 카메라가 +z 방향쪽에 있으므로 첫번째와 같이 푸른색이 나와야 하는게 정상임.
반면 두번째의 경우 카메라가 보는 방향에 대해서 수직인 위치에 존재하고 있다고 디버깅 됨
아래와 같은 경우는 GetWorldSpaceNormalizeViewDir의 내부 함수 구조가
Core.hlsl안에 inlcude 되어 있는 다른 hlsl의 함수를 참조하는데
구현은
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS)
{
if (IsPerspectiveProjection())
{
// Perspective
float3 V = GetCurrentViewPosition() - positionWS;
return normalize(V);
}
else
{
// Orthographic
return -GetViewForwardDir();
}
}
float3 GetCurrentViewPosition()
{
return GetCameraPositionWS();
}
float3 GetCameraPositionWS()
{
return _WorldSpaceCameraPos;
}
따라서, 표면상으로 보면 둘이 큰 차이가 없어 보인다.
뭐가 문제인지는 좀더 알아봐야 할 것 같다...
'Unity Study' 카테고리의 다른 글
| 2026-01-08_Gamma Correction & GPU Texture Compression (0) | 2026.01.08 |
|---|---|
| 2026-01-03_Normal, Normal Mapping, Tangent Space, TBN(1) (0) | 2026.01.03 |
| 2025-01-02_Unity Blender Coordinate Difference (0) | 2026.01.03 |
| 2025-12-17_SmoothDamp, Critical Damped Oscillation (1) | 2025.12.17 |
| 2025-12-08_TPS System Basic (0) | 2025.12.08 |