暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Common.hlsl 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. #ifndef _UNIFIEDRAYTRACING_COMMON_HLSL_
  2. #define _UNIFIEDRAYTRACING_COMMON_HLSL_
  3. #include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/Bindings.hlsl"
  4. #include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/FetchGeometry.hlsl"
  5. #define K_T_MAX 400000
  6. #ifndef FLT_EPSILON
  7. #define FLT_EPSILON 1.192092896e-07F
  8. #endif
  9. #ifndef FLT_MAX
  10. #define FLT_MAX 3.402823e+38
  11. #endif
  12. float Max3(float3 val)
  13. {
  14. return max(max(val.x, val.y), val.z);
  15. }
  16. // Adapted from RayTracing Gems, A Fast and Robust Method for Avoiding Self-Intersection
  17. // - Dropped the exact +N ulp computation, instead use, N * epsilon
  18. // - Use max of distance components instead of per component offset
  19. // - Use less conservative factors for error estimation
  20. float3 OffsetRayOrigin(float3 p, float3 n, float customOffset = 0.0f)
  21. {
  22. float distanceToOrigin = Max3(abs(p));
  23. float offset = (distanceToOrigin < 1 / 32.0f) ? FLT_EPSILON * 64.0f : FLT_EPSILON * 64.0f * distanceToOrigin;
  24. return p + (offset + customOffset) * n;
  25. }
  26. #endif