Compute Shader

Compute Shader

1、Similar to regular shaders, compute shaders are Asset files in your project, with a .compute file extension. 

// test.compute

#pragma kernel FillWithRed

RWTexture2D<float4> res;

[numthreads(1,1,1)]
void FillWithRed (uint3 dtid : SV_DispatchThreadID)
{
    res[dtid.xy] = float4(1,0,0,1);
}

  1)通过 #pragma kernel 指定可执行的函数,一个compute中可以有多个#pragma kernel

  2)#pragma kernel 不能与 // 一起用。

  3)#pragma kernel 后面可以跟宏

#pragma kernel KernelOne SOME_DEFINE DEFINE_WITH_VALUE=1337
#pragma kernel KernelTwo OTHER_DEFINE
// ...

2、bool SystemInfo.supportsComputeShaders 可以检测当前环境是否支持computeShader。

3、numthreads:Defines the number of threads to be executed in a single thread group when a compute shader is dispatched 

   

4、numthreads总线程限制。

  

参考:

1、https://docs.unity3d.com/Manual/ComputeShaders.html

2、https://technet.microsoft.com/zh-cn/library/ff471442.aspx/

3、https://technet.microsoft.com/zh-cn/windowsserver/ff476331

原文地址:https://www.cnblogs.com/tekkaman/p/8866507.html