ShaderSpecificURP.cginc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
  2. // UNITY_SHADER_NO_UPGRADE
  3. #ifndef _VLB_SHADER_SPECIFIC_INCLUDED_
  4. #define _VLB_SHADER_SPECIFIC_INCLUDED_
  5. // POSITION TRANSFORM
  6. #if VLB_CUSTOM_INSTANCED_OBJECT_MATRICES
  7. #define __VLBMatrixWorldToObject UNITY_ACCESS_INSTANCED_PROP(Props, _WorldToLocalMatrix)
  8. #define __VLBMatrixObjectToWorld UNITY_ACCESS_INSTANCED_PROP(Props, _LocalToWorldMatrix)
  9. #define __VLBMatrixV unity_MatrixV
  10. inline float4 VLBObjectToClipPos(in float3 pos) { return mul(mul(unity_MatrixVP, __VLBMatrixObjectToWorld), float4(pos, 1.0)); }
  11. #else
  12. #define __VLBMatrixWorldToObject unity_WorldToObject
  13. #define __VLBMatrixObjectToWorld unity_ObjectToWorld
  14. #define __VLBMatrixV UNITY_MATRIX_V
  15. inline float4 VLBObjectToClipPos(in float3 pos) { return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos.xyz, 1.0))); }
  16. #endif
  17. inline float4 VLBObjectToWorldPos(in float4 pos) { return mul(__VLBMatrixObjectToWorld, pos); }
  18. #define VLBWorldToViewPos(pos) (mul(__VLBMatrixV, float4(pos.xyz, 1.0)).xyz)
  19. // FRUSTUM PLANES
  20. #define VLBFrustumPlanes unity_CameraWorldClipPlanes
  21. // CAMERA
  22. inline float3 __VLBWorldToObjectPos(in float3 pos) { return mul(__VLBMatrixWorldToObject, float4(pos, 1.0)).xyz; }
  23. inline float3 VLBGetCameraPositionObjectSpace(float3 scaleObjectSpace)
  24. {
  25. return __VLBWorldToObjectPos(_WorldSpaceCameraPos).xyz * scaleObjectSpace;
  26. }
  27. // DEPTH
  28. #define VLBSampleDepthTexture(/*float4*/uv) (SampleSceneDepth((uv.xy) / (uv.w)))
  29. #define VLBLinearEyeDepth(depth) LinearEyeDepth((depth), _ZBufferParams)
  30. // FOG
  31. #if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
  32. #define VLB_FOG_MIX(color, fogColor, posClipSpace) color.rgb = MixFogColor(color.rgb, fogColor.rgb, ComputeFogFactor(posClipSpace.z * posClipSpace.w))
  33. #if VLB_ALPHA_AS_BLACK
  34. #define VLB_FOG_APPLY(color) \
  35. float4 fogColor = unity_FogColor; \
  36. fogColor.rgb *= color.a; \
  37. VLB_FOG_MIX(color, fogColor, i.posClipSpace);
  38. #else
  39. #define VLB_FOG_APPLY(color) VLB_FOG_MIX(color, unity_FogColor, i.posClipSpace);
  40. #endif
  41. #endif
  42. #endif // _VLB_SHADER_SPECIFIC_INCLUDED_