Search Unity

Relective alpha-cutout

Discussion in 'Shaders' started by ViCoX, Jan 6, 2015.

  1. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Hi Unity folk,

    Does anyone know if there is reflective alpha-cutout shader somewhere available?
    I need to do growing puddles with reflective cube maps. I was thinking using the alpha cutout for this effect.
    Sadly I personally have little experience with shaders.

    Thanks,
    - J
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Not tested, but here's a combination of Cutout/Diffuse and Reflect/Diffuse:
    Code (csharp):
    1.  
    2. Shader "Transparent/Cutout/Reflective" {
    3. Properties {
    4.    _Color ("Main Color", Color) = (1,1,1,1)
    5.    _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    6.    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    7.    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    8.    _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    9. }
    10.  
    11. SubShader {
    12.    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    13.    LOD 200
    14.    
    15. CGPROGRAM
    16. #pragma surface surf Lambert alphatest:_Cutoff
    17.  
    18. sampler2D _MainTex;
    19. samplerCUBE _Cube;
    20.  
    21. fixed4 _Color;
    22. fixed4 _ReflectColor;
    23.  
    24. struct Input {
    25.    float2 uv_MainTex;
    26.    float3 worldRefl;
    27. };
    28.  
    29. void surf (Input IN, inout SurfaceOutput o) {
    30.    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    31.    fixed4 c = tex * _Color;
    32.    o.Albedo = c.rgb;
    33.    o.Alpha = c.a;
    34.    fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
    35.    reflcol *= tex.a;
    36.    o.Emission = reflcol.rgb * _ReflectColor.rgb;
    37. }
    38. ENDCG
    39. }
    40.  
    41. Fallback "Transparent/Cutout/VertexLit"
    42. }
    43.  
     
  3. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Wow! Thank you so much jvo3dc!

    It works and it looks gorgeous when I animate the alpha cutout with my baked enviroment map.
    This community is a ultimate win! : )