Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can I modify this grayscale shader to work for Transparent Cut Out?

Discussion in 'Shaders' started by From-Soy-Sauce, Nov 12, 2014.

  1. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Hi I was looking for a shader that could make gray scale, and I found one, but when it only does so as a diffuse type, I wanted to know how I could make it instead be in a transparent cut out diffuse.

    Here is what the shader I'm currently using looks like:
    Code (CSharp):
    1. Shader "Custom/gray" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         }
    5.     SubShader {
    6.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    7.         LOD 200
    8.        
    9.              CGPROGRAM
    10.     #pragma surface surf Lambert
    11.    
    12.     sampler2D _MainTex;
    13.    
    14.     struct Input {
    15.     float2 uv_MainTex;
    16.     };
    17.    
    18.     void surf (Input IN, inout SurfaceOutput o) {
    19.     half4 c = tex2D (_MainTex, IN.uv_MainTex);
    20.     o.Albedo = (c.r + c.g + c.b)/3;
    21.     o.Alpha = c.a;
    22.     }
    23.     ENDCG
    24.     }
    25.     FallBack "Transparent/Cutout/Diffuse"
    26. }
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Code (csharp):
    1.  
    2. Shader "Custom/gray cutout" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _AlphaReject ("Alpha reject", Range(0.0, 1.0)) = 0.5
    6.         }
    7.     SubShader {
    8.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    9.         LOD 200
    10.        
    11.              CGPROGRAM
    12.     #pragma surface surf Lambert
    13.    
    14.     sampler2D _MainTex;
    15.     half _AlphaReject;
    16.    
    17.     struct Input {
    18.     float2 uv_MainTex;
    19.     };
    20.    
    21.     void surf (Input IN, inout SurfaceOutput o) {
    22.     half4 c = tex2D (_MainTex, IN.uv_MainTex);
    23.     clip(c.a - _AlphaReject);
    24.     o.Albedo = dot(c.rgb, half3(0.3333, 0.3333, 0.3333));
    25.     o.Alpha = c.a;
    26.     }
    27.     ENDCG
    28.     }
    29.     FallBack "Transparent/Cutout/Diffuse"
    30. }
    31.  
     
  3. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Ahh this works great thanks! One more question, if I may: what is the way to do a gray scale of a transparent bump diffuse?
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Well, you could make the diffuse texture grayscale, but else you can also just take the existing shader and add this line:
    Code (csharp):
    1.  
    2. o.Albedo = dot(c.rgb, half3(0.3333, 0.3333, 0.3333));
    3.