GxrShaderUtils.cginc 969 B

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