Can I use unity unitycg.cginc in compute shader?

Viewed 290

Is it possible to use compute shader to use variable and function such as UNITY_MATRIX_MVP in #include "UnityCG.cginc" The following code will return 0 And report an error:

CG:

// Each #kernel tells which function to compile; you can have many kernels
 #pragma kernel CSMain
 #include "UnityCG.cginc"
     
 RWStructuredBuffer<float> Result;
     
 [numthreads(1,1,1)]
  void CSMain (uint3 id : SV_DispatchThreadID)
 {
     Result[id.x] = UNITY_MATRIX_MVP[0][0];
 }

C#

...
     public ComputeShader _ComputeShader;
 
     void Start()
     {
         kernelIndex = _ComputeShader.FindKernel("CSMain");
         _Result = new ComputeBuffer(1, 4);
         _ComputeShader.SetBuffer(kernelIndex, "Result", _Result);
         _ComputeShader.Dispatch(kernelIndex, 1, 1, 1);
         float[] total = new float[1];
         _Result.GetData(total);
         Debug.Log(total[0]);
     }
...

Error: Shader error in 'NewComputeShader.compute': All kernels must use same constant buffer layouts; 'unity_LightColor0' property found to be different Can I use UnityCG.cginc in compute shader? Version: Unity 2019.4.23f1c1

0 Answers
Related