1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
- #define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
- #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
- float3 GetPrimaryCameraPosition()
- {
- #if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
- return float3(0, 0, 0);
- #else
- return _WorldSpaceCameraPos;
- #endif
- }
- float3 GetCurrentViewPosition()
- {
- #if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS)
- return GetPrimaryCameraPosition();
- #else
-
-
-
- return UNITY_MATRIX_I_V._14_24_34;
- #endif
- }
- float3 GetViewForwardDir()
- {
- float4x4 viewMat = GetWorldToViewMatrix();
- return -viewMat[2].xyz;
- }
- bool IsPerspectiveProjection()
- {
- #if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS)
- return (unity_OrthoParams.w == 0);
- #else
-
- return UNITY_MATRIX_P[3][3] == 0;
- #endif
- }
- float3 GetWorldSpaceNormalizeViewDir(float3 positionWS)
- {
- if (IsPerspectiveProjection())
- {
-
- float3 V = GetCurrentViewPosition() - positionWS;
- return normalize(V);
- }
- else
- {
-
- return -GetViewForwardDir();
- }
- }
- void GetLeftHandedViewSpaceMatrices(out float4x4 viewMatrix, out float4x4 projMatrix)
- {
- viewMatrix = UNITY_MATRIX_V;
- viewMatrix._31_32_33_34 = -viewMatrix._31_32_33_34;
- projMatrix = UNITY_MATRIX_P;
- projMatrix._13_23_33_43 = -projMatrix._13_23_33_43;
- }
- #if UNITY_REVERSED_Z
- #if SHADER_API_OPENGL || SHADER_API_GLES || SHADER_API_GLES3
-
- #define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) max(-(coord), 0)
- #else
-
-
- #define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) max(((1.0-(coord)/_ProjectionParams.y)*_ProjectionParams.z),0)
- #endif
- #elif UNITY_UV_STARTS_AT_TOP
-
- #define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) (coord)
- #else
-
- #define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) (coord)
- #endif
- #endif
|