BatchShaderBind.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Unity.Collections;
  2. using Unity.Mathematics;
  3. using UnityEngine;
  4. namespace Core.BRG
  5. {
  6. public class BatchShaderBind
  7. {
  8. public BRGShaderValue shaderValue;
  9. public int offset;
  10. private NativeArray<float4x4> _f4x4Buffer;
  11. private NativeArray<float3x4> _f3x4Buffer;
  12. private NativeArray<float4> _f4Buffer;
  13. private NativeArray<float> _f1Buffer;
  14. private int _count;
  15. private int _size;
  16. public int updateMinIndex;
  17. public int updateMaxIndex;
  18. public void InitBuffer(int count)
  19. {
  20. this._count = count;
  21. _size = shaderValue.GetSize();
  22. switch (shaderValue.ValueType)
  23. {
  24. case BRGShaderValueType.F4X4:
  25. _f4x4Buffer = new NativeArray<float4x4>(count, Allocator.Persistent);
  26. break;
  27. case BRGShaderValueType.F3X4:
  28. _f3x4Buffer = new NativeArray<float3x4>(count, Allocator.Persistent);
  29. break;
  30. case BRGShaderValueType.F4:
  31. _f4Buffer = new NativeArray<float4>(count, Allocator.Persistent);
  32. break;
  33. case BRGShaderValueType.F1:
  34. _f1Buffer = new NativeArray<float>(count, Allocator.Persistent);
  35. break;
  36. }
  37. }
  38. public void SetData(int index, float4 data)
  39. {
  40. _f4Buffer[index] = data;
  41. }
  42. public void SetData(int index, float4x4 data)
  43. {
  44. _f4x4Buffer[index] = data;
  45. }
  46. public void SetData(int index, float3x4 data)
  47. {
  48. _f3x4Buffer[index] = data;
  49. }
  50. public void SetData(int index, float data)
  51. {
  52. _f1Buffer[index] = data;
  53. }
  54. public void SetData(GraphicsBuffer graphicsBuffer,int maxCount)
  55. {
  56. // IitBuffer(graphicsBuffer.count);
  57. switch (shaderValue.ValueType)
  58. {
  59. case BRGShaderValueType.F4X4:
  60. graphicsBuffer.SetData(_f4x4Buffer, 0, offset / _size, maxCount);
  61. break;
  62. case BRGShaderValueType.F3X4:
  63. graphicsBuffer.SetData(_f3x4Buffer, 0, offset / _size, maxCount);
  64. break;
  65. case BRGShaderValueType.F4:
  66. graphicsBuffer.SetData(_f4Buffer, 0, offset / _size, maxCount);
  67. break;
  68. case BRGShaderValueType.F1:
  69. graphicsBuffer.SetData(_f1Buffer, 0, offset / _size, maxCount);
  70. break;
  71. }
  72. }
  73. }
  74. }