Search Unity

Help with basic texture-related shader property.

Discussion in 'Shaders' started by Neetesh3D, Aug 24, 2019.

  1. Neetesh3D

    Neetesh3D

    Joined:
    Dec 24, 2014
    Posts:
    9
    hello everyone, i'm trying to do something basic in a custom shader script, but am unable to do so. Basically, when i apply a texture, the black colored part of the texture is transparent or not rendered by the shader ( standard behavior ). Now, I want another color to show/render on the black/unseen part.

    Capture.PNG

    In this I want the " Color 2 " which is dark red to show up on the texture blacks.

    I've tried searching it up, but there's nothing proper or some thread from years ago, any help will be appreciated.
    Thank you.
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    finalColor = lerp(texColor, _TintColor, 1-texColor.r)
     
  3. Neetesh3D

    Neetesh3D

    Joined:
    Dec 24, 2014
    Posts:
    9
    Hi @mouusrusai, Thanks for the reply but i am unable to implement it in my code.
    Right now, this is what applies the "blue" color to the white part of the texture in the above image.
    How would i go about to add your line to this?

    void surf (Input IN, inout SurfaceOutputStandard o)
    {
    fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
    }
     
  4. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    void surf (Input IN, inout SurfaceOutputStandard o)
    {
    fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    c.rgb=lerp(c.rgb, fixed3(1,0,0), 1-Luminance(c.rgb));
    o.Albedo = c.rgb;
    o.Alpha = c.a;
    }
    Also you may use "if" or "step"
    if(c.r<0.1) c.rgb = fixed3(1,0,0);
    or
    c.rgb=lerp(c.rgb, fixed3(1,0,0), step(1-Luminance(c.rgb), 0.1));
    or
    c.rgb+=fixed3(1,0,0)*step(1-Luminance(c.rgb), 0.1);
     
    Last edited: Aug 25, 2019
    Rs likes this.
  5. Neetesh3D

    Neetesh3D

    Joined:
    Dec 24, 2014
    Posts:
    9
    Wasn't working with the texture I was testing this with, used the actual texture that i'll be working upon and it works perfectly! Thank you for you time & knowledge. :)