我可以在计算着色器中使用 unity unitycg.cginc 吗?

时间:2021-05-13 02:12:41

标签: unity3d shader compute-shader

是否可以使用计算着色器在#include "UnityCG.cginc"中使用UNITY_MATRIX_MVP等变量和函数 下面的代码会返回0并报错:

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]);
     }
...

错误:'NewComputeShader.compute' 中的着色器错误:所有内核必须使用相同的常量缓冲区布局;发现“unity_LightColor0”属性不同 我可以在计算着色器中使用 UnityCG.cginc 吗? 版本:Unity 2019.4.23f1c1

0 个答案:

没有答案