Challenge - 5 Problems
Shader Mastery: Unlit vs Lit
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple unlit shader
What will be the visible color output of this unlit shader applied to a white mesh?
Unity
Shader "Custom/SimpleUnlit" { Properties { _Color ("Color", Color) = (1,0,0,1) } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" fixed4 _Color; 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 _Color; } ENDCG } } }
Attempts:
2 left
💡 Hint
Unlit shaders do not calculate lighting, so the color is constant.
✗ Incorrect
Unlit shaders output a fixed color regardless of scene lighting. Here, _Color is set to red, so the mesh appears solid red.
❓ Predict Output
intermediate2:00remaining
Output difference between lit and unlit shaders
Given a lit shader and an unlit shader applied to the same mesh under a directional white light, what is the main visible difference?
Attempts:
2 left
💡 Hint
Lit shaders calculate lighting, unlit shaders do not.
✗ Incorrect
Lit shaders respond to lights and show shading and highlights. Unlit shaders ignore lights and show a flat color.
🔧 Debug
advanced2:00remaining
Identify the error in this lit shader snippet
What error will this lit shader code cause when compiled?
Unity
Shader "Custom/BrokenLit" { Properties { _Color ("Color", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" fixed4 _Color; struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; float3 normalDir : TEXCOORD0; }; v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.normalDir = normalize(v.normal); return o; } fixed4 frag (v2f i) : SV_Target { float3 lightDir = normalize(float3(0,1,0)); float diff = max(dot(i.normalDir, lightDir), 0); return fixed4(_Color.rgb * diff, _Color.a); } ENDCG } } }
Attempts:
2 left
💡 Hint
Normals must be transformed to world space for correct lighting.
✗ Incorrect
The normal is used directly from object space without transforming to world space, so lighting calculation is incorrect and results in black output.
📝 Syntax
advanced2:00remaining
Which shader code snippet correctly implements a simple unlit shader?
Select the code snippet that correctly compiles and outputs a fixed color ignoring lighting.
Attempts:
2 left
💡 Hint
Fragment shaders must return fixed4 with SV_Target semantic.
✗ Incorrect
Option C correctly returns fixed4 with four components and the SV_Target semantic required for fragment shaders.
🚀 Application
expert2:00remaining
Choosing shader type for a performance-critical UI element
You need to render a large number of 2D UI elements with solid colors and no lighting effects in a mobile game. Which shader type is best and why?
Attempts:
2 left
💡 Hint
Consider performance and visual needs for UI elements.
✗ Incorrect
Unlit shaders are simpler and faster because they skip lighting calculations, making them ideal for many UI elements that do not need lighting.