https://blog.csdn.net/wodownload2/article/details/103705433
https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html
在上面的博客中,我主要是照搬了官方的例子,实验了一下,但是还是有很多的疑问。
本节主要着重阐述两个问题:
1、数据的传输
2、参数数据的传输
在使用DrawMeshInstancedIndirect函数的时候,不明白各个参数的意思:
public static void DrawMeshInstancedIndirect(
Mesh mesh, int submeshIndex, Material material, Bounds bounds, ComputeBuffer bufferWithArgs,
[Internal.DefaultValue("0")] int argsOffset,
[Internal.DefaultValue("null")] MaterialPropertyBlock properties,
[Internal.DefaultValue("ShadowCastingMode.On")] ShadowCastingMode castShadows,
[Internal.DefaultValue("true")] bool receiveShadows,
[Internal.DefaultValue("0")] int layer,
[Internal.DefaultValue("null")] Camera camera,
[Internal.DefaultValue("LightProbeUsage.BlendProbes")] LightProbeUsage lightProbeUsage,
[Internal.DefaultValue("null")] LightProbeProxyVolume lightProbeProxyVolume
);
下面我将以实际的例子来解答这个疑问。
1、准备画草的数据
2、准备画草的参数
3、准备草的shader
4、C#传递数据给shader
代码无属性页:
https://stackoverflow.com/questions/24512841/unity3d-unsafe-code-requires-the-unsafe-command-line-option-to-be-specified
https://answers.unity.com/questions/804103/how-to-enable-unsafe-and-use-pointers.html
Graphics.DrawMeshInstancedIndirect(
info.mesh, //要画的mesh
0, //要画的mesh的,submesh索引
info.mat, //要使用什么材质求画
info.mesh.bounds, //画的东西的包围盒
info.argBuffer, //要画的东西的参数buffer,这个后面会详细说怎么设置
info.argOffset, //这个是参数buffer的偏移
info.mpb, //画的材质的参数
ShadowCastingMode.Off, //释放阴影,也可以释放
false, //不接受阴影,也可以接受
0, //所属的层,是哪个层级
null, //为null,则画所有的相机
LightProbeUsage.BlendProbes, //probe的使用,不详
null); //volume probe的使用,不详