然后像前面一样使用UNITY_SETUP_INSTANCE_ID使索引可用。material属性现在必须通过UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseColor)来访问。 float4 UnlitPassFragment (Varyings input) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(input); return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseColor);...
UNITY_SETUP_INSTANCE_ID(input); float4 baseColor = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseColor); return baseColor ; } Graphics.DrawMeshInstanced Unity提供了Graphics.DrawMeshInstanced来使用GPU Instancing合批。 public class MeshBall : MonoBehaviour { [SerializeField] private Mesh mesh; [...
第二步:在顶点数据结构的最后,增加UNITY_VERTEX_INPUT_INSTANCE_ID定义 第三步:在顶点程序的最前面增加UNITY_SETUP_INSTANCE_ID ()的宏方法 UNITY_SETUP_INSTANCE_ID(v); 第四步:在材质球的Inspector中把EnableGpuInstance的选项给勾选上. 勾选 验证:有instanced字段,即表示已经成功 ...
Object.GetInstanceID public int GetInstanceID(); Description Returns the instance id of the object. The instance id of an object is always guaranteed to be unique. using UnityEngine; using System.Collections;public class ExampleClass : MonoBehaviour { void Example() { print(GetInstanceID())...
开启gpu instance。#pragma multi_compile_instancing 在结构体中添加 id 声明。UNITY_VERTEX_INPUT_INSTANCE_ID 定义数据。 setup,在 vert/frag 中使用需要先UNITY_SETUP_INSTANCE_ID。在 frag 中使用还要在 vert 中使用UNITY_TRANSFER_INSTANCE_ID 获取数据。UNITY_ACCESS_INSTANCED_PROP ...
// 4. setup UNITY_SETUP_INSTANCE_ID(v); // 在 fragment 中使用,需要在此进行设置 UNITY_TRANSFER_INSTANCE_ID(v, o); o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); UNITY_TRANSFER_FOG(o,o.vertex); ...
UNITY_SETUP_INSTANCE_ID(v); o.color=v.color; o.texcoord=v.texcoord; vertInstancingColor(o.color); vertInstancingUVs(v.texcoord, o.texcoord); #ifdefined(UNITY_PARTICLE_INSTANCING_ENABLED) UNITY_PARTICLE_INSTANCE_DATA data=unity_ParticleInstanceData[unity_InstanceID]; ...
#define DEFAULT_UNITY_SETUP_INSTANCE_ID(input) { UnitySetupInstanceID(UNITY_GET_INSTANCE_ID(input)); UnitySetupCompoundMatrices(); } 1. 2. 3. 4. 5. 6. 这个宏主要做了两件事,第一是设置全局的unity_InstanceID变量,该变量用于索引shader用到的各类内置矩阵(例如object to world)的数组: ...
private int colorID; private void Start () { GPUInstanceByBlock(); //GPUInstanceByDrawMesh(); } private void Update() { if (insMesh != null) DrawMeshes(); } // 方法1:通过Shader + PropertyBlock 实现GPU Instance private void GPUInstanceByBlock() { ...
UNITY_SETUP_INSTANCE_ID(IN); fixed4col; col.rgb=DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap,IN.uv1.xy)); returncol; } 以上代码修改完毕,我们就可以开始烘焙场景了,如下图所示,右侧我们能看到现在还游戏对象模式。 接着我们要使用Graphics.DrawMeshInstanced来进行绘制,按照上面我们修改的shader其实...