Search Unity

Shader Alpha/Transparency from LightReflection/Specular

Discussion in 'Shaders' started by equal, Jul 26, 2015.

  1. equal

    equal

    Joined:
    Dec 14, 2012
    Posts:
    77
    Hi dear Devs,

    Im trying to modify Shaders that works like the surface of water, but inverse in the case of lightReflections. But all my tries end up in a mess of Code without any results, with errors or 100% invisible materials.


    If we take this ball for example, the shader should make it transparent where the light hits , based on the strength.
    Where the light reflection is total white, the ball should be absolute invisible and only partly invisible around it.

    It seemed easy, i take the o.Alpha = Specular and im done, but this didnt work out. The whole object was invisible.

    Any Help is very welcome.
     
  2. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    357
  3. equal

    equal

    Joined:
    Dec 14, 2012
    Posts:
    77
    Hi, thanks for the reply,I just need this for confirmation;

    It is not possible to make somthing like an inverted "specular only"-Shader ?
     
  4. equal

    equal

    Joined:
    Dec 14, 2012
    Posts:
    77
    Code (CSharp):
    1. Shader "Lighting Only"
    2. {
    3.      Properties
    4.      {
    5.          _Color ("Main Color", Color) = (1,1,1,1)
    6.          _MainTex ("Base (RGB)", 2D) = "white" {}
    7.      }
    8.      SubShader
    9.      {
    10.          Blend SrcAlpha One
    11.          ZWrite Off
    12.          Tags
    13.          {
    14.              Queue = Transparent
    15.          }
    16.          ColorMask RGB
    17.          CGPROGRAM
    18.          #pragma surface surf MyLight alpha finalcolor:mycolor
    19.          sampler2D _MainTex;
    20.          fixed4 _Color;
    21.          struct Input
    22.          {
    23.              float2 uv_MainTex;
    24.          };
    25.          void surf(Input IN, inout SurfaceOutput o)
    26.          {
    27.              fixed4 tex = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    28.              o.Albedo = tex.rgb;
    29.              o.Alpha = tex.a;
    30.          }
    31.          float lightPower;
    32.          fixed4 LightingMyLight(SurfaceOutput s, half3 lightDir, fixed atten)
    33.          {
    34.              lightPower = 1 - saturate(dot(normalize(s.Normal), lightDir));
    35.              return fixed4((s.Albedo * _LightColor0.rgb) * (lightPower * atten * 2), 1);
    36.          }
    37.  
    38.          void mycolor(Input IN, SurfaceOutput o, inout fixed4 color)
    39.          {
    40.              color.a = o.Alpha * lightPower;
    41.          }
    42.          ENDCG
    43.      }
    44.      Fallback "VertexLit", 2
    45. }
    I took This one from
    http://answers.unity3d.com/questions/283985/a-shader-with-transparent-lit-area.html

    It does not give me the same Result as in the picture for 3d objects but ok, i only use 2d planes anyway.
    The bigger Problem is that i need black and not like in the link red. But when i change the color or a Texture map it turns alpha.


    In the end is all i want some kind of Shader that behave like fog of war to any close light (becomes transparent)