📖 Scenario: You are creating a simple Unity scene where you want to understand the difference between unlit and lit shaders. Unlit shaders do not react to light and show colors as they are, while lit shaders respond to lighting and shadows in the scene.This project will help you create two materials: one using an unlit shader and one using a lit shader, and apply them to two cubes to see the difference.
🎯 Goal: Build a Unity scene with two cubes: one with an unlit shader material and one with a lit shader material. You will create the materials in code and apply them to the cubes to observe how lighting affects each.
📋 What You'll Learn
Create two cubes in the scene using code.
Create a material with an unlit shader and assign a color.
Create a material with a lit shader and assign a color.
Apply the materials to the respective cubes.
Print the names of the shaders used to the console.
💡 Why This Matters
🌍 Real World
Understanding unlit vs lit shaders helps game developers control how objects appear under different lighting conditions, which is essential for creating realistic or stylized visuals.
💼 Career
Shader knowledge is important for roles like game developer, technical artist, and graphics programmer, where controlling object appearance and performance is key.
Progress0 / 4 steps
1
Create two cubes in the scene
Write code to create two cubes named unlitCube and litCube in the Unity scene using GameObject.CreatePrimitive(PrimitiveType.Cube).
Unity
Hint
Use GameObject.CreatePrimitive(PrimitiveType.Cube) twice and assign the results to unlitCube and litCube.
2
Create materials with unlit and lit shaders
Create two materials called unlitMaterial and litMaterial. Assign the shader Shader.Find("Unlit/Color") to unlitMaterial and Shader.Find("Standard") to litMaterial. Set unlitMaterial.color to red and litMaterial.color to blue.
Unity
Hint
Use new Material(Shader.Find("Unlit/Color")) for the unlit material and new Material(Shader.Find("Standard")) for the lit material. Then set their colors.
3
Apply materials to the cubes
Assign unlitMaterial to the Renderer.material of unlitCube and litMaterial to the Renderer.material of litCube.
Unity
Hint
Use GetComponent<Renderer>().material = to assign the materials to each cube.
4
Print the shader names to the console
Write two Debug.Log statements to print the shader names of unlitMaterial and litMaterial using unlitMaterial.shader.name and litMaterial.shader.name.
Unity
Hint
Use Debug.Log("Unlit shader used: " + unlitMaterial.shader.name) and similarly for litMaterial.
Practice
(1/5)
1. What is the main difference between Unlit and Lit shaders in Unity?
easy
A. Unlit shaders do not react to lighting, Lit shaders do
B. Unlit shaders are slower than Lit shaders
C. Lit shaders ignore shadows, Unlit shaders show shadows
D. Lit shaders only work on 2D objects
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 A
Quick 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
A. Shaders > Unlit > Color
B. Shaders > Legacy Shaders > Transparent
C. Shaders > Standard
D. Shaders > Lit > PBR
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 A
Quick 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?