Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReflectionProbeMinMaxZJob.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Unity.Burst;
  2. using Unity.Collections;
  3. using Unity.Jobs;
  4. using Unity.Mathematics;
  5. namespace UnityEngine.Rendering.Universal
  6. {
  7. [BurstCompile]
  8. struct ReflectionProbeMinMaxZJob : IJobFor
  9. {
  10. public Fixed2<float4x4> worldToViews;
  11. [ReadOnly]
  12. public NativeArray<VisibleReflectionProbe> reflectionProbes;
  13. public NativeArray<float2> minMaxZs;
  14. public void Execute(int index)
  15. {
  16. var minMax = math.float2(float.MaxValue, float.MinValue);
  17. var reflectionProbeIndex = index % reflectionProbes.Length;
  18. var reflectionProbe = reflectionProbes[reflectionProbeIndex];
  19. var viewIndex = index / reflectionProbes.Length;
  20. var worldToView = worldToViews[viewIndex];
  21. var centerWS = (float3)reflectionProbe.bounds.center;
  22. var extentsWS = (float3)reflectionProbe.bounds.extents;
  23. for (var i = 0; i < 8; i++)
  24. {
  25. // Convert index to x, y, and z in [-1, 1]
  26. var x = ((i << 1) & 2) - 1;
  27. var y = (i & 2) - 1;
  28. var z = ((i >> 1) & 2) - 1;
  29. var cornerVS = math.mul(worldToView, math.float4(centerWS + extentsWS * math.float3(x, y, z), 1));
  30. cornerVS.z *= -1;
  31. minMax.x = math.min(minMax.x, cornerVS.z);
  32. minMax.y = math.max(minMax.y, cornerVS.z);
  33. }
  34. minMaxZs[index] = minMax;
  35. }
  36. }
  37. }