关于ShaderForge的shader变体variant过多,但是又并没有用宏或者分支,why?

举例:


Shader "Mihayou/SmokeDissolve" {
    Properties {
        _Maintex ("Maintex", 2D) = "white" {}
        _DisolveMap01 ("DisolveMap01", 2D) = "white" {}
        _Min ("Min", Range(0, 1)) = 0.2564103
        _Max ("Max", Range(0, 1)) = 0.3760684
        _Edgethick ("Edgethick", Float ) = 1.05
        _SecondTex ("SecondTex", 2D) = "white" {}
        _Edgethick02 ("Edgethick02", Float ) = 1.05
        _Tex02Min ("Tex02Min", Range(0, 1)) = 0.2
        _Tex02Max ("Tex02Max", Range(0, 1)) = 0.3
        [HDR]_SecondTexCor ("SecondTexCor", Color) = (1,1,1,1)
        _DissolveMap02 ("DissolveMap02", 2D) = "white" {}
        [HDR]_HighLightCor ("HighLightCor", Color) = (1,1,1,1)
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform sampler2D _Maintex; uniform float4 _Maintex_ST;
            uniform sampler2D _DisolveMap01; uniform float4 _DisolveMap01_ST;
            uniform float _Min;
            uniform float _Max;
            uniform float _Edgethick;
            uniform sampler2D _SecondTex; uniform float4 _SecondTex_ST;
            uniform float _Edgethick02;
            uniform float _Tex02Min;
            uniform float _Tex02Max;
            uniform float4 _SecondTexCor;
            uniform sampler2D _DissolveMap02; uniform float4 _DissolveMap02_ST;
            uniform float4 _HighLightCor;
            struct VertexInput {
                float4 vertex : POSITION;
                float4 texcoord0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float4 uv0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.vertexColor = v.vertexColor;
                o.pos = UnityObjectToClipPos( v.vertex );
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
// Lighting:
// Emissive:
                float4 _Maintex_var = tex2D(_Maintex,TRANSFORM_TEX(i.uv0, _Maintex));
                float4 _DisolveMap01_var = tex2D(_DisolveMap01,TRANSFORM_TEX(i.uv0, _DisolveMap01));
                float4 _SecondTex_var = tex2D(_SecondTex,TRANSFORM_TEX(i.uv0, _SecondTex));
                float3 emissive = (i.vertexColor.rgb*(((_Maintex_var.rgb.r*(_HighLightCor.rgb*_HighLightCor.a))*(_Maintex_var.a*smoothstep( _Min, _Max, saturate((_DisolveMap01_var.r+_Edgethick+(i.uv0.b*(-2.0)))) )))+((_SecondTexCor.rgb*_SecondTexCor.a)*_SecondTex_var.rgb)));
                float3 finalColor = emissive;
                float4 _DissolveMap02_var = tex2D(_DissolveMap02,TRANSFORM_TEX(i.uv0, _DissolveMap02));
                return fixed4(finalColor,(i.vertexColor.a*(_SecondTex_var.a*smoothstep( _Tex02Min, _Tex02Max, saturate((_DissolveMap02_var.r+_Edgethick02+(i.uv0.a*(-2.0)))) ).r)));
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"
}

这个是用SF连出来的效果,结果variant居然会有37个,首先我们先把影响到变体多的因素去掉,把#pragma multi_compile_fwdbase注掉,再看一下变体数量是30个,这是为啥?
原因是最后的FallBack是diffuse,直接注销掉,可以发现变体为1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值