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

Help with shader

Discussion in 'Shaders' started by kilian277, Apr 12, 2014.

  1. kilian277

    kilian277

    Joined:
    Jul 13, 2012
    Posts:
    54
    Hi,

    i'm trying to make a shader i added a few stuff but it is doing things that make my eyes go bazurk.

    Here's the shader:

    Code (csharp):
    1.  
    2. Shader "Exile/Skydome/Animated Clouds" {
    3.     Properties {
    4.         _CloudColor ("Cloud Color", Color) = (0,0,0,1)
    5.         _MainTex ("Cloud pattern", 2D) = "black" {}
    6.         _NormalMap ("Depth Map", 2D) = "white" {}
    7.         _MarbleTex ("Marble Texture", 2D) = "white" {}
    8.         _SunDir ("SunDir", Vector) = (0,0,1,0)
    9.         _RimMultiplier("Rim multiplier", Range (0.0, 1.0)) = 0.3
    10.     }
    11.     SubShader {
    12.         Tags { "RenderType"="Transparent" "Queue"="Transparent"}
    13.         LOD 200
    14.        
    15.         CGPROGRAM
    16.         #pragma surface surf Lambert alpha
    17.  
    18.         sampler2D _MainTex;
    19.         sampler2D _NormalMap;
    20.         sampler2D _MarbleTex;
    21.         float4 _CloudColor;
    22.         float4 _SunDir;
    23.         float _RimMultiplier;
    24.  
    25.         struct Input {
    26.             float2 uv_MainTex;
    27.             float2 uv_NormalMap;
    28.             float2 uv_MarbleTex;
    29.         };
    30.  
    31.         void surf (Input IN, inout SurfaceOutput o) {
    32.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    33.             half3 m = tex2D (_MarbleTex, IN.uv_MarbleTex);
    34.             half3 n = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
    35.            
    36.             float alpha = c.a * _CloudColor.a;
    37.            
    38.             o.Albedo = c;
    39.             o.Alpha = alpha;
    40.            
    41.             if((alpha >= _RimMultiplier))
    42.                 o.Normal = n;
    43.                
    44.             else
    45.                 o.Normal = 2 * _SunDir;
    46.                 //o.Alpha = alpha * m.r;
    47.         }
    48.         ENDCG
    49.     }
    50.     FallBack "Diffuse"
    51. }
    52.  
    Herer's an image

    $12.png

    The model in question is about that ring with the white pathes on it.

    Basically i want to check if a alpha value of a pixel is greater than a certain value and just apply the normal map to it.
    If the alpha value of the pixel is less than the given constant then give that pixel a normal of 2.

    The normal map also reacts to directional lights so at the place where the normal map is not applied (the place where the directional light shining away from it the pixel with alpha less than given value should de 2.0 en multiply that with the sun direction vector.

    Now that is working fine.

    But adding a color to the albedo adds the color to the normal map and not the diffuse texture underneath it.

    Any thoughts on that ?

    And also as yo ucan see in the picture the border between the lesser and greater pixel is like alpha testing foliage , is there a way to smoothen that ?

    Thanks!
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You're not using _CloudColor.rgb anywhere. What do you want it to do? My guess is you want to multiply c by _CloudColor across all channels.

    To smooth out the transition between rim/regular, you should use an interpolation rather than a conditional. Start with lerp().
     
  3. kilian277

    kilian277

    Joined:
    Jul 13, 2012
    Posts:
    54
    I will give it a try , thanks
     
  4. kilian277

    kilian277

    Joined:
    Jul 13, 2012
    Posts:
    54
    How would i do the lerping then , without the if condition ?

    Also the coloring works now , forgot to add it (facepalm)

    EDIT:

    basically i want to achieve this the outline lighting where the clouds are infront of the sun it works , but it's radical
    it's need to be more smoothed:

    $OutlineSlope0.jpg
     
    Last edited: Apr 14, 2014