ShadowShaderUtils.cginc 852 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. #ifndef MRTK_SHADER_UTILS
  4. #define MRTK_SHADER_UTILS
  5. #if defined(_CLIPPING_PLANE)
  6. inline float PointVsPlane(float3 worldPosition, float4 plane)
  7. {
  8. float3 planePosition = plane.xyz * plane.w;
  9. return dot(worldPosition - planePosition, plane.xyz);
  10. }
  11. #endif
  12. #if defined(_CLIPPING_SPHERE)
  13. inline float PointVsSphere(float3 worldPosition, float4 sphere)
  14. {
  15. return distance(worldPosition, sphere.xyz) - sphere.w;
  16. }
  17. #endif
  18. #if defined(_CLIPPING_BOX)
  19. inline float PointVsBox(float3 worldPosition, float3 boxSize, float4x4 boxInverseTransform)
  20. {
  21. float3 distance = abs(mul(boxInverseTransform, float4(worldPosition, 1.0))) - boxSize;
  22. return length(max(distance, 0.0)) + min(max(distance.x, max(distance.y, distance.z)), 0.0);
  23. }
  24. #endif
  25. #endif