https://blog.csdn.net/wodownload2/article/details/103705433
https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html
In the above blog, I mainly copied the example of the official, experiment a bit, but there are still many questions.
This section focuses on two issues:
1, the transmission data of
the transmission 2, the parameter data
When using DrawMeshInstancedIndirect function, do not understand the meaning of each parameter:
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
);
Now I will be practical examples to answer this question.
1, ready to draw grass data
2, setup parameters Videos grass
3, prepared grass shader
. 4, C # pass data to shader
code None property pages:
https://stackoverflow.com/questions/24512841/unity3d-unsafe-code- --unsafe-at The The requires the Command-Line-the 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的使用,不详