Version: 6000.3
语言: 中文
内置渲染管线中的粒子系统标准着色器自定义顶点流示例
为内置渲染管线中的粒子定义自定义数据格式

内置渲染管线中的粒子系统表面着色器自定义顶点流示例

可以使用 Surface着色器GPU 上运行的程序。更多信息
请参阅术语表
使用自定义顶点流,但还有一些额外的事项需要注意:

  • 曲面函数的输入结构与顶点着色器 渲染模型时在 3D 模型的每个顶点上运行的程序。更多信息
    请参阅术语表
    .您需要提供自己的顶点着色器输入结构。请参阅下面的示例,其中它被称为appdata_particles.
  • 什么时候表面着色器内置渲染管线编写着色器的简化方法。更多信息
    请参阅术语表
    构建时,会自动处理名称以某些标记开头的变量。最引人注目的是uv.为了防止自动处理在此处导致问题,请务必为您的UV输入指定不同的名称(例如,“texcoord”)。

下面是与标准着色器相同的功能,但在表面着色器中:

Shader "Particles/Anim Alpha Blend Surface" {
    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 {"Queue"="Transparent" "RenderType"="Transparent"}
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite off
        LOD 200
        
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard alpha vertex:vert

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

         struct appdata_particles {
            float4 vertex : POSITION;
            float3 normal : NORMAL;
            float4 color : COLOR;
            float4 texcoords : TEXCOORD0;
            float texcoordBlend : TEXCOORD1;
            };


        struct Input {
            float2 uv_MainTex;
            float2 texcoord1;
            float blend;
            float4 color;
        };


        void vert(inout appdata_particles v, out Input o) {
            UNITY_INITIALIZE_OUTPUT(Input,o);
            o.uv_MainTex = v.texcoords.xy;
            o.texcoord1 = v.texcoords.zw;
            o.blend = v.texcoordBlend;
            o.color = v.color;
          }


        half _Glossiness;
        half _Metallic;
        fixed4 _Color;


        void surf (Input IN, inout SurfaceOutputStandard o) {
            fixed4 colA = tex2D(_MainTex, IN.uv_MainTex);
            fixed4 colB = tex2D(_MainTex, IN.texcoord1);
            fixed4 c = 2.0f * IN.color * lerp(colA, colB, IN.blend) * _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"
}

内置渲染管线中的粒子系统标准着色器自定义顶点流示例
为内置渲染管线中的粒子定义自定义数据格式