LightExtractionJob.cs 990 B

1234567891011121314151617181920212223242526272829303132333435
  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 LightExtractionJob : IJobFor
  9. {
  10. [ReadOnly]
  11. public NativeArray<VisibleLight> lights;
  12. public NativeArray<LightType> lightTypes;
  13. public NativeArray<float> radiuses;
  14. public NativeArray<float3> directions;
  15. public NativeArray<float3> positions;
  16. public NativeArray<float> coneRadiuses;
  17. public void Execute(int index)
  18. {
  19. var light = lights[index];
  20. var localToWorldMatrix = (float4x4)light.localToWorldMatrix;
  21. lightTypes[index] = light.lightType;
  22. radiuses[index] = light.range;
  23. directions[index] = localToWorldMatrix.c2.xyz;
  24. positions[index] = localToWorldMatrix.c3.xyz;
  25. coneRadiuses[index] = math.tan(math.radians(light.spotAngle * 0.5f)) * light.range;
  26. }
  27. }
  28. }