LuxURP_LayerBasedCulling.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace LuxURPEssentials
  5. {
  6. public class LuxURP_LayerBasedCulling : MonoBehaviour
  7. {
  8. [LuxURP_HelpBtn("h.2uxuzzrgrwpo", order = 0)]
  9. [Space(5, order = 1)]
  10. public LayerMask SmallDetailsLayer;
  11. public float SmallDetailsDistance = 30.0f;
  12. public LayerMask MediumDetailsLayer;
  13. public float MediumDetailsDistance = 50.0f;
  14. int GetLayerNumber(int LayerValue) {
  15. int layerNumber = 0;
  16. int layer = LayerValue;
  17. while(layer > 0)
  18. {
  19. layer = layer >> 1;
  20. layerNumber++;
  21. }
  22. return (layerNumber - 1);
  23. }
  24. void OnEnable()
  25. {
  26. // Get layer numbers
  27. int smallLayerNumber = GetLayerNumber(SmallDetailsLayer.value);
  28. int mediumLayerNumber = GetLayerNumber(MediumDetailsLayer.value);
  29. for (int i = 0; i < Camera.allCameras.Length; i++) {
  30. float[] distances = new float[32];
  31. distances = Camera.allCameras[i].layerCullDistances;
  32. if (smallLayerNumber > 0)
  33. distances[smallLayerNumber] = SmallDetailsDistance; // small things like DetailDistance of the terrain engine
  34. if (mediumLayerNumber > 0)
  35. distances[mediumLayerNumber] = MediumDetailsDistance;
  36. Camera.allCameras[i].layerCullDistances = distances;
  37. distances = null;
  38. }
  39. }
  40. }
  41. }