A shader in Unity is a small program that tells the computer how to draw something on the screen, controlling the color, lighting, and texture of objects.
Click to reveal answer
beginner
What are the two main types of shaders in Unity?
The two main types are Vertex Shaders, which handle the position of vertices, and Fragment (or Pixel) Shaders, which handle the color of each pixel.
Click to reveal answer
beginner
What is the purpose of the 'Properties' block in a Unity shader?
The 'Properties' block defines variables like colors or textures that you can change in the Unity Editor without editing the shader code.
Click to reveal answer
intermediate
Explain the role of the 'SubShader' in a Unity shader.
A 'SubShader' contains the actual shader code that runs on the GPU. Unity can have multiple SubShaders to support different hardware or rendering paths.
Click to reveal answer
intermediate
What is the difference between a Surface Shader and a Vertex/Fragment Shader in Unity?
Surface Shaders are easier to write and handle lighting automatically, while Vertex/Fragment Shaders give you full control but require more code to manage lighting and effects.
Click to reveal answer
Which part of a Unity shader controls the color of each pixel?
ASubShader
BVertex Shader
CFragment Shader
DProperties Block
✗ Incorrect
The Fragment Shader (also called Pixel Shader) controls the color and appearance of each pixel on the object.
What does the 'Properties' block in a Unity shader allow you to do?
AControl vertex positions
BWrite GPU code
CDefine lighting models
DChange shader variables in the Unity Editor
✗ Incorrect
The 'Properties' block lets you expose variables like colors or textures so you can change them easily in the Unity Editor.
Why might you use multiple SubShaders in a Unity shader?
ATo support different hardware or rendering paths
BTo add more colors
CTo increase texture size
DTo speed up the CPU
✗ Incorrect
Multiple SubShaders allow Unity to pick the best shader code for the user's hardware or rendering method.
Which shader type in Unity automatically handles lighting for you?
ASurface Shader
BVertex/Fragment Shader
CCompute Shader
DGeometry Shader
✗ Incorrect
Surface Shaders simplify writing shaders by automatically managing lighting calculations.
What is the main role of a Vertex Shader?
ATo set pixel colors
BTo calculate the position of vertices
CTo define textures
DTo manage lighting
✗ Incorrect
Vertex Shaders process each vertex's position and can modify it before drawing.
Describe the basic structure of a custom shader in Unity and the role of each part.
Think about how you set variables, write GPU code, and control drawing.
You got /5 concepts.
Explain the difference between Surface Shaders and Vertex/Fragment Shaders and when you might choose each.
Consider how much control you want versus how much work you want to do.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a custom shader in Unity?
easy
A. To control exactly how objects look by writing small programs
B. To create 3D models from scratch
C. To write game logic and rules
D. To manage user input events
Solution
Step 1: Understand the role of shaders
Shaders define how surfaces appear by controlling colors, lighting, and textures.
Step 2: Identify what custom shaders do
Custom shaders let you write small programs to control object appearance beyond built-in options.
Final Answer:
To control exactly how objects look by writing small programs -> Option A
Quick Check:
Custom shader = control object look [OK]
Hint: Shaders control object appearance with code [OK]
Common Mistakes:
Confusing shaders with 3D modeling
Thinking shaders handle game logic
Assuming shaders manage input
2. Which of the following is the correct way to start a simple Unity shader code block?
easy
A. ShaderBegin
B. StartShader
C. CGPROGRAM
D. ProgramCG
Solution
Step 1: Recall Unity shader syntax
Unity shaders use CGPROGRAM to start the programmable shader code block.
Step 2: Check options for correct keyword
Only CGPROGRAM is the valid keyword to begin the shader code section.
Final Answer:
CGPROGRAM -> Option C
Quick Check:
Shader code block starts with CGPROGRAM [OK]
Hint: Look for CGPROGRAM to start shader code [OK]
Common Mistakes:
Using made-up keywords like StartShader
Confusing CGPROGRAM with other terms
Misspelling the keyword
3. What will be the output color of this simple shader fragment code?
A. Missing semicolon after _Color property declaration
B. _Color cannot be used directly in fragment shader
C. frag function missing input parameters
D. Incorrect use of ENDCG keyword
Solution
Step 1: Check Properties block syntax
The property declaration is correct: no semicolon needed, parentheses balanced.
Step 2: Verify shader code block
Properties like _Color must be declared inside CGPROGRAM as 'uniform fixed4 _Color;' to be used; direct use causes undeclared identifier error.
Final Answer:
_Color cannot be used directly in fragment shader -> Option B
Quick Check:
Properties need uniform declaration [OK]
Hint: Declare Properties as uniforms in CGPROGRAM [OK]
Common Mistakes:
Assuming semicolons are needed in Properties
Not declaring uniform for _Color
Thinking ENDCG is incorrect
5. You want to write a custom shader that colors an object red only if its x-coordinate is positive, otherwise blue. Which fragment shader code correctly implements this?
hard
A. fixed4 frag() : SV_Target {
if (POSITION.x > 0) return fixed4(1,0,0,1);
else return fixed4(0,0,1,1);
}
B. fixed4 frag(float3 pos) : SV_Target {
if (pos.x > 0) return fixed4(1,0,0,1);
else return fixed4(0,0,1,1);
}