Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

(SOLVED) What standard shader will do what I want ...

Discussion in 'Shaders' started by imgodot, Feb 12, 2020.

  1. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    First off, I am pretty confused when it comes to textures, materials and shaders.
    And, I need a shader that will allow the following features:
    1) The texture will have a solid color area and a transparent area.
    2) Programmatically, the solid color portion of the texture must be able to have its color changed.
    3) Programmatically, the transparency of the solid color portion of the texture must be adjustable.

    Is there a standard shader that allows all of this?

    Thanks.
    -- Paul
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    993
    You'd have to make a custom Surface shader for that, which will allow you to essentially easily make a copy of the Standard shader, but only using the inputs/outputs you want to assign to.

    https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

    You'll define a
    _Tint
    color like they show in some of the examples there.
    When you sample the color of your
    _MainTex
    in the
    surf()
    program, you'll store it in a variable such as:

    fixed4 col = tex2D (_MainTex, IN.uv_MainTex);


    Then you can simply do:
    if(col.a == 1) { col *= _Tint; }

    This will only tint the existing color though, which is fine if you expect your solid color to be white, then it will always be the color you set in your
    _Tint
    .
    Otherwise, you'll have to split that into 2 lines.
    col.a *= _Tint.a;
    and
    col.rgb = _Tint.rgb;
    to completely replace the color instead of tint it.

    And then finally, like in the examples, assign the values to the right outputs:
    o.Albedo = col.rgb;

    o.Alpha = col.a;


    There are other outputs, like o.Normal, Smoothness, Roughness, Occlusion... etc that you can output to if you plan to use those kinds of textures too, as defined on this page.
     
  3. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    Invertex,
    Thanks for that detailed and illuminating response.
    I did actually find what I needed by using the Text/GUI (?) shader.
    However, I am going to copy/paste your response into my "keep" file.
    I may actually try what you suggest, just as an exercise, since I am such a noob with shaders, etc.

    Thanks again.
    -- Paul
     
unityunity