Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Completly invisible shader, but only shows lights reflection on it

Discussion in 'Shaders' started by Fujisama, Dec 27, 2014.

  1. Fujisama

    Fujisama

    Joined:
    Dec 27, 2014
    Posts:
    4
    Hi everyone,

    Is it possible to write a shader that is completly invisible, but only shows lights reflection on it as the example below ?

    Before applying shader
    light1.png

    The plane is fully transparent, but it reflects the white light part, as a white diffuse
    light2.png

    Real time result
    light3.png


    Anyone know if something like that already exists ?

    Thanks!
     
  2. Fujisama

    Fujisama

    Joined:
    Dec 27, 2014
    Posts:
    4
    I found this shader here to show lighting only:

    Code (CSharp):
    1.     Shader "Lighting Only" {
    2.         Properties {
    3.             _Color ("Main Color", Color) = (1,1,1,1)
    4.             _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         }
    6.      
    7.         SubShader {
    8.             Blend SrcAlpha One
    9.             ZWrite Off
    10.             Tags {Queue = Transparent}
    11.             ColorMask RGB
    12.             // Vertex lights
    13.             Pass {
    14.                 Tags {"LightMode" = "Vertex"}
    15.                 Lighting On
    16.                 Material {
    17.                     Diffuse [_Color]
    18.                 }
    19.                 SetTexture [_MainTex] {
    20.                     constantColor [_Color]
    21.                     Combine texture * primary DOUBLE, texture * constant
    22.                 }
    23.             }
    24.         }
    25.      
    26.         Fallback "VertexLit", 2
    27.      
    28.     }
    29.  
    Here is the result with "Lighting Only" shader:
    Light Only.png


    I still have 2 problems with it, the light result is not clean (low definition?), and this shader does not accept shadows (unlike "Diffuse" shader) :
    diffuse.png

    Thanks in advance
     
  3. Fujisama

    Fujisama

    Joined:
    Dec 27, 2014
    Posts:
    4
    After multiples tests I finally found this, witch seems to be perfect:



    Matte.png

    Good result, but it still not recieves the projected shadow from the cube, any ideas ?




    Code (CSharp):
    1.      Shader "FX/Matte Shadow3" {
    2.     Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    5.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.01
    6.     _ShadowStrength ("Shadow strength", Range(0,5)) = 1
    7.     }
    8.     SubShader {
    9.     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    10.     LOD 200
    11.     Blend Zero SrcColor
    12.     CGPROGRAM
    13.     #pragma surface surf ShadowOnly alphatest:_Cutoff
    14.     fixed4 _Color;
    15.     float _ShadowStrength;
    16.    
    17.     struct Input {
    18.     float2 uv_MainTex;
    19.     };
    20.    
    21.     inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten){
    22.     fixed4 c;
    23.     c.rgb = s.Albedo*atten;
    24. //    c.rgb = lerp(_ShadowStrength *.75, 1, atten).rrr;
    25.     c.a = s.Alpha;
    26.     return c;
    27.     }
    28.    
    29.     void surf (Input IN, inout SurfaceOutput o) {
    30.      //fixed4 c = _LightColor0 + _Color;
    31.      fixed4 c = _LightColor0 + 0.3*_Color;
    32.      //fixed4 c = _Color;
    33.     o.Albedo = c.rgb * _ShadowStrength;
    34.     o.Alpha = 0;
    35.     }
    36.     ENDCG
    37.     }
    38.     Fallback "Transparent/Cutout/VertexLit"
    39.     }
     

    Attached Files:

  4. Shootingdutchtman

    Shootingdutchtman

    Joined:
    Aug 28, 2017
    Posts:
    2
    For anyone still struggeling with this and want a shader that is 2 sided transparent but still show the light glow, I changed the above shader a bit to make it work:

    Code (CSharp):
    1.  Shader "FX/Matte Shadow3" {
    2.     Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    5.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.01
    6.     _ShadowStrength ("Shadow strength", Range(0,5)) = 1
    7.     }
    8.     SubShader {
    9.         Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
    10.         LOD 100
    11.         Blend srcAlpha oneMinusSrcAlpha
    12.         ZWrite Off
    13.  
    14.         CGPROGRAM
    15.         #pragma surface surf ShadowOnly alphatest:_Cutoff
    16.        
    17.         fixed4 _Color;
    18.         float _ShadowStrength;
    19.  
    20.         struct Input {
    21.             float2 uv_MainTex;
    22.         };
    23.  
    24.         inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten){
    25.             fixed4 c;
    26.             c.rgb = s.Albedo*atten;
    27.         //    c.rgb = lerp(_ShadowStrength *.75, 1, atten).rrr;
    28.             c.a = s.Alpha;
    29.             return c;
    30.         }
    31.  
    32.         void surf (Input IN, inout SurfaceOutput o) {
    33.             //fixed4 c = _LightColor0 + _Color;
    34.             fixed4 c = _LightColor0 + 0.1*_Color;
    35.             //fixed4 c = _Color;
    36.             o.Albedo = c.rgb * _ShadowStrength;
    37.             o.Alpha = 0;
    38.         }
    39.  
    40.     ENDCG
    41.     }
    42.     Fallback "Transparent/Cutout/VertexLit"
    43. }
    It can be better but I'm just starting to learn :p

    Make sure you set alpha cutoff to 0 (zero) for it to work properly.