#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
// This function always return the absolute position in WS either the CameraRelative mode is enabled or not
float3 GetAbsolutePositionWS(float3 positionWS)
{
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
positionWS += _WorldSpaceCameraPos;
#endif
return positionWS;
}
// This function always return the camera relative position in WS either the CameraRelative mode is enabled or not
float3 GetCameraRelativePositionWS(float3 positionWS)
{
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
positionWS -= _WorldSpaceCameraPos;
#endif
return positionWS;
}
// Return world position of current object
float3 GetObjectPositionWS()
// Return absolute world position of current object
float3 GetObjectAbsolutePositionWS()
return modelMatrix._m03_m13_m23; // Translation object to world
return GetAbsolutePositionWS(modelMatrix._m03_m13_m23); // Translation object to world
float4x4 modelMatrix = UNITY_MATRIX_M;
// To handle camera relative rendering we substract the camera position in the model matrix
// User must not use UNITY_MATRIX_M directly, unless they understand what they do
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
modelMatrix._m03_m13_m23 -= _WorldSpaceCameraPos;
#endif
return modelMatrix;
return UNITY_MATRIX_M;
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
// To handle camera relative rendering we need to apply translation before converting to object space
float4x4 modelMatrix = { {1.0, 0.0, 0.0, _WorldSpaceCameraPos.x}, { 0.0, 1.0, 0.0, _WorldSpaceCameraPos.y }, { 0.0, 0.0, 1.0, _WorldSpaceCameraPos.z }, { 0.0, 0.0, 0.0, 1.0 } };
return mul(UNITY_MATRIX_I_M, modelMatrix);
#else
#endif
}
// Transform to homogenous clip space
float3 TransformViewToHClipDir(float3 directionVS)
{
return mul((float3x3)GetViewToHClipMatrix(), directionVS);
}
// This function always return the absolute position in WS either the CameraRelative mode is enabled or not
float3 GetAbsolutePositionWS(float3 positionWS)
{
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
positionWS += _WorldSpaceCameraPos;
#endif
return positionWS;
}
// This function always return the camera relative position in WS either the CameraRelative mode is enabled or not
float3 GetCameraRelativePositionWS(float3 positionWS)
{
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
positionWS -= _WorldSpaceCameraPos;
#endif
return positionWS;
}
float3 GetPrimaryCameraPosition()