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

Grayscale shader, can I make modified textures appear brighter?

Discussion in 'Shaders' started by nTu4Ka, Apr 7, 2014.

  1. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Hi,

    I am completely unfamiliar with shaders.
    I am using this shader to make texture appear on GUI as grayscale.
    Code (csharp):
    1. Shader "Custom/Grayscale" {
    2.     Properties {
    3.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    4.     }
    5.  
    6.     SubShader {
    7.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    8.         LOD 200
    9.  
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert alpha
    12.  
    13.             sampler2D _MainTex;
    14.  
    15.             struct Input {
    16.                 float2 uv_MainTex;
    17.             };
    18.  
    19.             void surf (Input IN, inout SurfaceOutput o) {
    20.                 half4 c = tex2D(_MainTex, IN.uv_MainTex);
    21.                 o.Albedo = dot(c.rgb, float3(0.22, 0.707, 0.071));
    22.                 o.Alpha = c.a;
    23.             }
    24.  
    25.         ENDCG
    26.     }
    27.  
    28.     Fallback "Transparent/VertexLit"
    29. }
    The only problem is that textures appear very dark, almost black.
    Is there a way to make them brighter?


    Thank you.
     
  2. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    o.Albedo = dot(c.rgb, float3(0.22, 0.707, 0.071));

    the weights doesn't exactly add up 0.22+ 0.707+ 0.071 = 0.998 but is still should be good enough.
    You could test with a pure white texture with a white alpha ("opaque") to see if it comes out white (or very close, could be 254,254,254). If it doesn't something else is tinting your mesh, most likely vertex colors or a post effect.
     
  3. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Hi,

    I am new to it and didn't understand some things you said. The shader code above wasn't created by me.

    1. I created following texture and it appears pretty dark: #666666 to be exact.
    $TestTexture.png
    How can I find what causes this?

    2. What do you mean regarding weights doesn't add up? Should there be solid 1?


    Thank you.
     
    Last edited: Apr 13, 2014
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    change o.Albedo to o.Emission, or write a new fragment shader that is not effected by lights in scene.
     
  5. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Woooow! You are the greatest! It works perfectly! Thanks a lot!