Blend Multiply with Slider

Hello, I’m trying to make a particle multiply shader that can simply blend between two textures. I have looked into unity’s docs on shaders, but I was unable to find much regarding how I might incorporate a slider into controlling the opacity of a texture in a multiply shader. Does anyone know how I might go around creating such a shader? I really don’t have much experience in shaders and would be appreciative of any help I can get. I have included the code of the shader I would like to modify below. Thanks for any help!

Edit: I am sorry, I did not make myself clear enough. The trouble I’m running into comes from the fact that to my knowledge particle shaders (which I think are vertex shaders) – like multiply – cannot be coded as surface shaders.

Using a surface shader, its very possible to make a shader such that a slider can control the opacity of two textures. The idea is that a slider when at its min shows one texture, at its max shows a second texture and in-between shows both textures simultaneously at varying opacities.

I’m trying to mimic this effect in a vertex multiply shader such that I can use the shader to ultimately which can blend between two different texture maps in realtime. How can I create such a shader? Any pointers would be wonderful!

// Simplified Multiply Particle shader

Shader "Custom/MultiplyBlendTextures" {
    Properties {
        _Blending ("Blend Amount", Range(0,1)) = 0.5
        _MainTex ("Particle Texture", 2D) = "white" {}
        _BlendTex ("Blend Texture", 2D) = "white" {}
    }

    Category {
        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
        Blend Zero SrcColor
        Cull Off Lighting Off ZWrite Off Fog { Color (1,1,1,1) }
  
        BindChannels {
            Bind "Color", color
            Bind "Vertex", vertex
            Bind "TexCoord", texcoord
        }
  
        SubShader {
            Pass {
                SetTexture [_MainTex] {
                    combine texture * primary
                }
                SetTexture [_MainTex] {
                    constantColor (1,1,1,1)
                    combine previous lerp (previous) constant
                }
            }
        }
    }
}

And how are you going to control the blend between the two images using particles?

See the edit, I hope I have clarified my intentions!

See if this works for you, i simply copied the internal multiply particle shader and added a second texture that lerps from the alpha of the color (color of lifetime) the problem with this is that now you lose the ability to change the alpha of the particle (because it now controls the lerp), so my question still stands, how do you want to blend between the two?

Shader "Particles/Multiply Texture Blend" {
Properties {
    _MainTex ("Particle Texture", 2D) = "white" {}
    _FinalTex ("Final Texture", 2D) = "white" {}
    _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend Zero SrcColor
    Cull Off Lighting Off ZWrite Off Fog { Color (1,1,1,1) }
   
    SubShader {
        Pass {
       
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_particles

            #include "UnityCG.cginc"

            sampler2D _MainTex;
            sampler2D _FinalTex;
            fixed4 _TintColor;
           
            struct appdata_t {
                float4 vertex : POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
                #ifdef SOFTPARTICLES_ON
                float4 projPos : TEXCOORD1;
                #endif
            };
           
            float4 _MainTex_ST;
            float4 _FinalTex_ST;

            v2f vert (appdata_t v)
            {
                v2f o;
                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                #ifdef SOFTPARTICLES_ON
                o.projPos = ComputeScreenPos (o.vertex);
                COMPUTE_EYEDEPTH(o.projPos.z);
                #endif
                o.color = v.color;
                o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
                return o;
            }

            sampler2D_float _CameraDepthTexture;
            float _InvFade;
           
            fixed4 frag (v2f i) : SV_Target
            {
                #ifdef SOFTPARTICLES_ON
                float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
                float partZ = i.projPos.z;
                float fade = saturate (_InvFade * (sceneZ-partZ));
                i.color.a *= fade;
                #endif
               
                half4 prev = half4(i.color.rgb,1) * lerp(tex2D(_MainTex, i.texcoord), tex2D(_FinalTex, i.texcoord), i.color.a);
                return lerp(half4(1,1,1,1), prev, prev.a);
            }
            ENDCG
        }
    }
}
}

Thanks so much for taking the time to write that. However, it’s still not working quite the way I want. It looks like the lerp function is taking in the alpha of the main texture, would there be any way for it to instead take in the value on the slider? I suppose I’m not fully understanding your question. I’m looking for a shader to do a linear blend between the two textures so that you could slide the sider from 0 to 1 and see the material’s view texture change from the first texture to the second. What ways are there to blend between two textures? Thanks so much for your help.

Edit: Awesome! Literally just did what I said – changed the input on the lerp function to take in the slider’s value instead of the texture alpha and was able to achieve what I was aiming for! Thanks so much!

If its working for you i’m cool but what i gave you was already lerping using the slider alpha value of color over lifetime, it wasn’t lerping using the texture alpha at all

i.color.a is the vertex color and the lerp is doing a lerp between _MainTex and _FinalTex using i.color.a to do so, i then multiply it by the vertex color without alpha to tint the textures normally

half4 prev = half4(i.color.rgb,1) * lerp(tex2D(_MainTex, i.texcoord), tex2D(_FinalTex, i.texcoord), i.color.a);