0
0
Unityframework~5 mins

Unlit vs lit shaders in Unity

Choose your learning style9 modes available
Introduction

Shaders control how objects look in a game. Unlit shaders show colors without light effects. Lit shaders change appearance based on light.

When you want a flat color or texture that doesn't change with light, like UI elements or cartoon styles.
When you want realistic surfaces that react to light, like shiny metals or rough walls.
When you need simple graphics that don't need lighting to save performance.
When you want shadows and highlights on objects to make them look 3D.
When creating special effects that ignore scene lighting, like glowing signs.
Syntax
Unity
Shader "Custom/UnlitShader" {
  SubShader {
    Pass {
      // Unlit shader code here
    }
  }
}

Shader "Custom/LitShader" {
  Properties {
    _Color ("Color", Color) = (1,1,1,1)
  }
  SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200
    Pass {
      // Lit shader code here
    }
  }
}

Unlit shaders do not use lighting calculations.

Lit shaders include lighting and shading calculations for realism.

Examples
This unlit shader colors everything red without any light effect.
Unity
Shader "Custom/UnlitColor" {
  SubShader {
    Pass {
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag

      struct appdata {
        float4 vertex : POSITION;
      };

      struct v2f {
        float4 pos : SV_POSITION;
      };

      v2f vert(appdata v) {
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);
        return o;
      }

      fixed4 frag(v2f i) : SV_Target {
        return fixed4(1, 0, 0, 1); // red color
      }
      ENDCG
    }
  }
}
This lit shader colors the object green and reacts to light for shading.
Unity
Shader "Custom/LitSimple" {
  Properties {
    _Color ("Color", Color) = (0,1,0,1)
  }
  SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200
    CGPROGRAM
    #pragma surface surf Standard

    fixed4 _Color;

    struct Input {
      float3 worldNormal;
      float3 worldPos;
    };

    void surf(Input IN, inout SurfaceOutputStandard o) {
      o.Albedo = _Color.rgb;
      o.Metallic = 0.0;
      o.Smoothness = 0.5;
    }
    ENDCG
  }
}
Sample Program

This program defines two shaders: one unlit that shows red color always, and one lit that shows green color reacting to lights in the scene.

Unity
// This example shows a simple unlit shader and a lit shader in Unity

// Unlit shader colors object red without lighting
Shader "Custom/UnlitRed" {
  SubShader {
    Pass {
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag

      struct appdata {
        float4 vertex : POSITION;
      };

      struct v2f {
        float4 pos : SV_POSITION;
      };

      v2f vert(appdata v) {
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);
        return o;
      }

      fixed4 frag(v2f i) : SV_Target {
        return fixed4(1, 0, 0, 1); // red color
      }
      ENDCG
    }
  }
}

// Lit shader colors object green and reacts to light
Shader "Custom/LitGreen" {
  Properties {
    _Color ("Color", Color) = (0,1,0,1)
  }
  SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200
    CGPROGRAM
    #pragma surface surf Standard

    fixed4 _Color;

    struct Input {
      float3 worldNormal;
      float3 worldPos;
    };

    void surf(Input IN, inout SurfaceOutputStandard o) {
      o.Albedo = _Color.rgb;
      o.Metallic = 0.0;
      o.Smoothness = 0.5;
    }
    ENDCG
  }
}
OutputSuccess
Important Notes

Unlit shaders are faster because they skip lighting calculations.

Lit shaders give more realistic visuals but use more processing power.

Use unlit for UI or stylized looks, lit for realistic 3D objects.

Summary

Unlit shaders show colors without light effects.

Lit shaders calculate light and shadows for realism.

Choose shader type based on your visual and performance needs.