Aentro Personal Blog

Back

2025spring 【Catlike Coding】Compute Shader2025spring 【Catlike Coding】Compute Shader

【Catlike Coding】Compute Shader#

学了Catlike Coding的basic部分, compute shader部分有点收获,写个总结.

alt text

GPUGraph.cs#

通过Shader.propertyToID把数据从C#脚本中传递到shader中(CPU To GPU).

GraphComputeShader.compute#

compute shader 计算好坐标,并返回给缓冲区

Catlike shader 是surface shader,在我2022 URP Unity中不能使用. 所以我让AI改为了 URP shader.
通过

#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
// Get the position for this instance
float3 position = _Positions[unity_InstanceID];
plaintext

来获取缓冲区内的坐标,然后改变unity object to world 矩阵, 来改变坐标. 挺巧妙的.

ProcedureDraw.shader#

总结#

这一套方案让CPU运算量大大降低. 戴森球的优化应该也采用类似的方法, 把各种CPU的计算转移到GPU中进行. 大概效率提升了一个数量级.

戴森球作者发的专栏 https://www.zhihu.com/question/442555442/answer/1711890146?utm_psn=1883875216381432992

2025spring 【Catlike Coding】Compute Shader
https://entropy622.github.io/blog/2025spring-catlike-codingcompute-shader
Author Aentro
Published at 2025年3月11日