Shaders control how objects look in a game. Unlit shaders show colors without light effects. Lit shaders change appearance based on light.
Unlit vs lit shaders in Unity
Introduction
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
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 } } }
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 } }
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.
Practice
1. What is the main difference between
Unlit and Lit shaders in Unity?easy
Solution
Step 1: Understand Unlit shader behavior
Unlit shaders display colors without any lighting or shadow effects.Step 2: Understand Lit shader behavior
Lit shaders calculate lighting and shadows to create realistic visuals.Final Answer:
Unlit shaders do not react to lighting, Lit shaders do -> Option AQuick Check:
Lighting reaction = Unlit no, Lit yes [OK]
Hint: Unlit means no light effects, Lit means light and shadows [OK]
Common Mistakes:
- Thinking Unlit shaders are slower
- Believing Lit shaders ignore shadows
- Assuming Lit shaders only work on 2D
2. Which of the following is the correct way to assign an Unlit shader to a material in Unity's Shader dropdown?
easy
Solution
Step 1: Locate Unlit shaders in Unity
Unlit shaders are found under the menu path: Shaders > Unlit > Color.Step 2: Confirm correct shader assignment
Assigning 'Unlit > Color' applies an unlit shader that ignores lighting.Final Answer:
Shaders > Unlit > Color -> Option AQuick Check:
Unlit shader path = Shaders > Unlit > Color [OK]
Hint: Unlit shaders are under Shaders > Unlit in dropdown [OK]
Common Mistakes:
- Choosing Standard shader which is lit
- Selecting Legacy shaders unrelated to unlit
- Picking Lit shaders for unlit materials
3. Given this Unity shader code snippet, what will be the visual result on a 3D object?
Shader "Custom/Example" {
SubShader {
Tags { "RenderType"="Opaque" }
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); }
ENDCG
}
}
}medium
Solution
Step 1: Analyze the fragment shader output
The fragment shader returns fixed4(1,0,0,1), which is solid red color.Step 2: Check for lighting calculations
No lighting or normal calculations exist, so color is unlit and constant.Final Answer:
The object will appear bright red without lighting effects -> Option DQuick Check:
Fragment color fixed red, no lighting = unlit red [OK]
Hint: No lighting code means solid color output [OK]
Common Mistakes:
- Assuming lighting affects color here
- Thinking object is invisible without lighting
- Expecting color changes or flickering
4. You wrote a Lit shader but the object appears completely black in your scene. What is the most likely cause?
medium
Solution
Step 1: Understand Lit shader requirements
Lit shaders need normal vectors to calculate lighting properly.Step 2: Identify missing normal vector effect
If normals are missing or incorrect, lighting calculations fail, causing black appearance.Final Answer:
The shader is missing normal vector calculations -> Option BQuick Check:
Missing normals = no lighting = black object [OK]
Hint: Lit shaders need normals for lighting; missing normals cause black [OK]
Common Mistakes:
- Blaming mesh or camera instead of shader code
- Confusing Unlit shader with Lit shader issues
- Ignoring normal vector importance
5. You want to optimize a mobile game by reducing lighting calculations but still want some color variation. Which shader approach is best?
hard
Solution
Step 1: Consider performance needs
Reducing lighting calculations improves performance on mobile devices.Step 2: Choose shader with color variation but no lighting
Unlit shaders with vertex colors provide color changes without expensive lighting.Final Answer:
Use Unlit shaders with vertex colors for variation -> Option CQuick Check:
Unlit + vertex colors = color variation without lighting cost [OK]
Hint: Unlit + vertex colors = color without lighting cost [OK]
Common Mistakes:
- Using full Lit shaders which are costly
- Choosing Unlit with no color variation loses visual interest
- Disabling shadows alone doesn't reduce lighting cost fully
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
