包含此页的版本:
不含此页的版本:
这是 Surface 的完整工作示例着色器在 GPU 上运行的程序。更多信息
请参阅术语表用粒子系统通过在场景中生成大量小型 2D 图像并为其设置动画来模拟流体实体(如液体、云和火焰)的组件。更多信息
请参阅术语表GPU实例化:
Shader "Instanced/ParticleMeshesSurface" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
// And generate the shadow pass with instancing support
#pragma surface surf Standard nolightmap nometa noforwardadd keepalpha fullforwardshadows addshadow vertex:vert
// Enable instancing for this shader
#pragma multi_compile_instancing
#pragma instancing_options procedural:vertInstancingSetup
#pragma exclude_renderers gles
#include "UnityStandardParticleInstancing.cginc"
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
fixed4 vertexColor;
};
fixed4 _Color;
half _Glossiness;
half _Metallic;
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
vertInstancingColor(o.vertexColor);
vertInstancingUVs(v.texcoord, o.uv_MainTex);
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * IN.vertexColor * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
与常规有许多细微的区别表面着色器:为内置渲染管线编写着色器的简化方法。更多信息
请参阅术语表在上面的示例中,这使其与粒子实例化一起使用。
首先,您需要添加以下两行来启用程序化实例化,并指定内置的顶点设置函数。此函数位于 UnityStandardParticleInstancing.cginc 中,并加载每个实例(每个粒子)位置数据:
#pragma instancing_options procedural:vertInstancingSetup
#include "UnityStandardParticleInstancing.cginc"
示例中的另一个修改是对 顶点(Vertex) 函数的修改,该函数有两行额外的行,用于应用每个实例的属性,特别是粒子颜色和纹理表动画纹理坐标:
vertInstancingColor(o.vertexColor);
vertInstancingUVs(v.texcoord, o.uv_MainTex);