|
|
|
|
|
|
|
|
|
|
float3 GetCurrentCameraPosition() |
|
|
|
{ |
|
|
|
#if SHADERPASS != SHADERPASS_DEPTH_ONLY |
|
|
|
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_DEPTH_ONLY) |
|
|
|
return _WorldSpaceCameraPos; |
|
|
|
#else |
|
|
|
// TEMP: this is rather expensive. Then again, we need '_WorldSpaceCameraPos' |
|
|
|
|
|
|
return -viewMat[2].xyz; |
|
|
|
} |
|
|
|
|
|
|
|
// Computes the world space view direction (pointing towards the camera). |
|
|
|
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS) |
|
|
|
// Returns 'true' if the current camera performs a perspective projection. |
|
|
|
bool IsPerspectiveCamera() |
|
|
|
#if SHADERPASS != SHADERPASS_DEPTH_ONLY |
|
|
|
if (unity_OrthoParams.w == 0) |
|
|
|
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_DEPTH_ONLY) |
|
|
|
return (unity_OrthoParams.w == 0); |
|
|
|
if (GetWorldToHClipMatrix()[3].x != 0 && |
|
|
|
GetWorldToHClipMatrix()[3].y != 0 && |
|
|
|
GetWorldToHClipMatrix()[3].z != 0 && |
|
|
|
GetWorldToHClipMatrix()[3].w != 1) |
|
|
|
return (GetWorldToHClipMatrix()[3].x != 0 || |
|
|
|
GetWorldToHClipMatrix()[3].y != 0 || |
|
|
|
GetWorldToHClipMatrix()[3].z != 0 || |
|
|
|
GetWorldToHClipMatrix()[3].w != 1); |
|
|
|
} |
|
|
|
|
|
|
|
// Computes the world space view direction (pointing towards the camera). |
|
|
|
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS) |
|
|
|
{ |
|
|
|
if (IsPerspectiveCamera()) |
|
|
|
{ |
|
|
|
// Perspective |
|
|
|
float3 V = GetCurrentCameraPosition() - positionWS; |
|
|
|