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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity4, add Unlit texture on top of Shader?

Discussion in 'Shaders' started by Lizzard4000, Dec 15, 2015.

  1. Lizzard4000

    Lizzard4000

    Joined:
    Mar 3, 2010
    Posts:
    101
    Hello!

    I have this shader here, and it works well but i can't think of any way to make the "_EmissionTex" not affected by lighting.

    I need the Emission part to be added on top of everything independent of light, like a "Unlit Decal".
    Is this possible?

    Thanks!

    Code (CSharp):
    1. Shader "Lino_Edit" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _EmissionTex ("Emission (RGB)", 2D) = "white" {}
    6.         _EmissionIntensity ("Emission intensity", Range(0,5) ) = 1
    7.         _EmissionVisibility ("Emission visibility", Range(0,1) ) = 1
    8.         _EmissionColor ("Emission Color", Color) = (1,1,1,1)
    9.         _Saturation ("Saturation", Range(0,1) ) = 1
    10.         _Cubemap ("Cubemap", CUBE) = "" {}
    11.         _CubemapIntensity ("Cubemap Intensity", Range(0,1) ) = 1
    12.        // _Lightmap ("Lightmap (RGB)", 2D) = "grey" {}
    13.     }
    14.     SubShader {
    15.         Tags { "RenderType"="Opaque" }
    16.         LOD 200
    17.        
    18.        
    19.         CGPROGRAM
    20.         #pragma surface surf Lambert
    21.        
    22.  
    23.  
    24.  
    25.         sampler2D _MainTex;
    26.         sampler2D _Lightmap;
    27.         samplerCUBE _Cubemap;
    28.         fixed _CubemapIntensity;
    29.        
    30.         sampler2D _EmissionTex;
    31.         fixed _EmissionIntensity;
    32.         fixed _EmissionVisibility;
    33.         float4 _Color;
    34.         float4 _EmissionColor;
    35.  
    36.         struct Input {
    37.             float2 uv_MainTex;
    38.             float3 worldRefl;
    39.         };
    40.  
    41.         void surf (Input IN, inout SurfaceOutput o ) {
    42.        
    43.        
    44.        
    45.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    46.             fixed4 x = tex2D (_MainTex, IN.uv_MainTex) * _EmissionIntensity;
    47.            
    48.              c.rgb += texCUBE( _Cubemap, IN.worldRefl ) * _CubemapIntensity ;
    49.            
    50.              c.rgb =lerp(c.rgb,x, Luminance(tex2D (_EmissionTex, IN.uv_MainTex).rgb)* _EmissionVisibility );
    51.            
    52.  
    53.             o.Albedo = c.rgb * _Color;
    54.        
    55.         }
    56.        
    57.  
    58.         ENDCG
    59.        
    60.  
    61.        
    62.     }
    63.     FallBack "Diffuse"
    64. }
    65.  
     
  2. ilya_ca

    ilya_ca

    Joined:
    Nov 19, 2011
    Posts:
    274
    Albedo means the color of the surface. Albedo is always affected by the light.

    What you should do instead is write to the emission channel:
    Code (CSharp):
    1. fixed emissionMask = Luminance(tex2D (_EmissionTex, IN.uv_MainTex).rgb);
    2.  
    3. o.Albedo = tex2D (_MainTex, IN.uv_MainTex) * _Color * (1-emissionMask);
    4.  
    5. o.Emission = tex2D (_MainTex, IN.uv_MainTex) * _EmissionIntensity * emissionMask;
    6.  
    7. o.Emission += texCUBE( _Cubemap, IN.worldRefl ) * _CubemapIntensity;
     
    Last edited: Dec 15, 2015