Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you add an additive texture?

Discussion in 'Shaders' started by astracat111, Sep 18, 2019.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    I've got a main texture named _MainTex and I've got a texture _AdditiveTex, and I can't seem to find how to chnage the blending mode of the additive texture...

    If someone could point me in the right direction, thanks a bunch ahead of time.
     
  2. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    The blending mode of a shader is what determines how the whole shader blends with the scene.
    An additive shader has a blend mode
    Blend One One

    But blending between two textures within the the shader is different. Thats just a maths operation.
    So, when you've done your texture reads you'll have something like
    Code (CSharp):
    1.          
    2. fixed4 tex = tex2D(_MainTex, i.uv);
    3. fixed4 AddTex= tex2D(_AdditiveTex, i.uv);
    4.  
    Then you just add the results of the reads together for "additive". Or multiply them for multiplicative. Or you can lerp them.
    Code (CSharp):
    1. tex+=addTex;
    2. tex*=addTex;
    3. tex = lerp(tex,addTex,addTex.a);
     
    astracat111 likes this.
  3. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    Hey thanks so much @tmcthee , sorry for not providing more info in the original post.