Challenge - 5 Problems
Shader Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What does this simple shader output?
Consider this Unity shader code snippet that colors a surface red. What color will the surface appear when rendered?
Unity
Shader "Custom/SimpleRed" { 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 } } }
Attempts:
2 left
💡 Hint
Look at the color returned in the fragment shader.
✗ Incorrect
The fragment shader returns fixed4(1, 0, 0, 1), which means full red, no green or blue, and full opacity. This colors the surface bright red.
🧠 Conceptual
intermediate1:30remaining
Why do shaders control visual rendering?
Why are shaders essential for controlling how objects appear visually in Unity?
Attempts:
2 left
💡 Hint
Think about what changes the color and brightness of pixels on screen.
✗ Incorrect
Shaders run on the GPU and calculate how light and color affect each pixel, controlling the final look of objects.
🔧 Debug
advanced2:30remaining
Identify the error in this shader code
This shader is supposed to color a surface blue, but it renders black instead. What is the error?
Unity
Shader "Custom/BlueShader" { 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(0, 0, 1, 1); // added alpha value } ENDCG } } }
Attempts:
2 left
💡 Hint
Check the return value of the fragment shader carefully.
✗ Incorrect
The fixed4 constructor requires four values (RGBA). Returning fixed4(0,0,1) only provides three, so the alpha defaults to 0, making the surface fully transparent (black).
📝 Syntax
advanced1:30remaining
Which shader code snippet has correct syntax?
Which of the following shader fragment functions is syntactically correct in Unity's CG shader language?
Attempts:
2 left
💡 Hint
Look for correct function declaration and return statement syntax.
✗ Incorrect
Option B correctly declares the function with return type, semantic, and braces. Option B misses colon before semantic. Option B misses braces. Option B misses alpha value in fixed4.
🚀 Application
expert3:00remaining
How to modify a shader to add transparency?
You have a shader that colors objects solid red. How would you modify the fragment shader to make the surface 50% transparent?
Attempts:
2 left
💡 Hint
Transparency requires alpha less than 1 and blending enabled.
✗ Incorrect
To make a surface transparent, the fragment shader must output an alpha less than 1, and the shader must have blending enabled to mix with background.