Search Unity

Self Illumination in my shader

Discussion in 'Shaders' started by terraKote, Apr 3, 2014.

  1. terraKote

    terraKote

    Joined:
    Apr 3, 2014
    Posts:
    9
    Hello everyone. I'm new here, and always try to make everything by my own, but shaders is my problem. Searching in internet, dont make any results. I make a custom shader, from few others. I make a 2D game without any light sources in scene, and my shader using diffuse, but I need effect like in self illum shaders. This is my code:
    Code (csharp):
    1.  Shader "Example/Slices" {
    2.     Properties {
    3.       _Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
    4.     }
    5.    
    6.     SubShader {
    7.       Tags { "RenderType" = "Opaque" }
    8.       Cull Off
    9.       CGPROGRAM
    10.       #pragma surface surf Lambert
    11.       struct Input {
    12.           float2 uv_MainTex;
    13.           float3 worldPos;
    14.       };
    15.      
    16.      fixed4 _Color;
    17.      
    18.       void surf (Input IN, inout SurfaceOutput o) {
    19.           clip (frac((IN.worldPos.y+IN.worldPos.z*0.1) * 5) - 0.5);
    20.           o.Albedo = _Color.rgb;
    21.       }
    22.       ENDCG
    23.     }
    24.     Fallback "Diffuse"
    25.   }
    P.S. sorry for my English. I'm from Ukraine.
     
  2. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    You can download the shader source here: https://unity3d.com/unity/download/archive

    In there you can check out how they did their illumination shader and apply it yourself. They're all surface shaders I think, so that shouldn't be a problem. Do note that surface shaders generally always apply a lighting function, but considering you have no lights in your scene, this shouldn't really matter.
     
  3. terraKote

    terraKote

    Joined:
    Apr 3, 2014
    Posts:
    9
    Thank you. If you interested in result, check this out:
    Code (csharp):
    1.  Shader "Custom/Slices" {
    2.     Properties {
    3.       _Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
    4.       _Fade ("Alpha cutoff", Range(0,1)) = 1
    5.     }
    6.    
    7.     SubShader {
    8.       Tags { "RenderType" = "Opaque" }
    9.       Cull Off
    10.       CGPROGRAM
    11.       #pragma surface surf Lambert
    12.       struct Input {
    13.           float2 uv_MainTex;
    14.           float3 worldPos;
    15.           float2 uv_Illum;
    16.       };
    17.      
    18.      fixed4 _Color;
    19.      half _Fade;
    20.      
    21.       void surf (Input IN, inout SurfaceOutput o) {
    22.           clip (frac((IN.worldPos.y*+IN.worldPos.z*0.1) * 5) - 0.5);
    23.           o.Albedo = _Color.rgb * (_Color.a - _Fade);
    24.           o.Emission = _Color.rgb * 1;
    25.       }
    26.       ENDCG
    27.     }
    28.     Fallback "Self-Illumin/VertexLit"
    29.   }
     
    Last edited: Apr 12, 2014