0
0
Unityframework~30 mins

Unlit vs lit shaders in Unity - Hands-On Comparison

Choose your learning style9 modes available
Unlit vs Lit Shaders in Unity
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use Debug.Log("Unlit shader used: " + unlitMaterial.shader.name) and similarly for litMaterial.