Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a shader property for color.
Unity
Shader "Custom/SimpleColor" { Properties { _Color ("Color", Color) = [1] } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names as strings instead of numeric vectors.
Using incorrect syntax like float4 without proper context.
✗ Incorrect
Shader color properties use a vector with four float values representing RGBA, like (1,1,1,1) for white.
2fill in blank
mediumComplete the code to sample the main texture in the fragment shader.
Unity
fixed4 frag(v2f i) : SV_Target {
fixed4 col = tex2D([1], i.uv);
return col;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the type name instead of the sampler variable.
Passing UV coordinates incorrectly.
✗ Incorrect
The tex2D function samples a texture using its sampler variable, usually named _MainTex.
3fill in blank
hardFix the error in the shader code to correctly multiply color by light intensity.
Unity
fixed4 frag(v2f i) : SV_Target {
fixed4 col = tex2D(_MainTex, i.uv);
fixed light = [1].r;
return col * light;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that don't exist or hold different data.
Multiplying by a vector instead of a scalar.
✗ Incorrect
The light color variable holds intensity information; multiplying color by lightColor.r applies lighting.
4fill in blank
hardFill both blanks to declare and use a float property controlling brightness.
Unity
Properties {
_Brightness ("Brightness", Float) = [1]
}
fixed4 frag(v2f i) : SV_Target {
fixed4 col = tex2D(_MainTex, i.uv);
col.rgb *= [2];
return col;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property name in the shader code.
Setting default value as a string instead of a number.
✗ Incorrect
The brightness property is declared with a default value 1.0 and used in the shader as _Brightness to scale color.
5fill in blank
hardFill all three blanks to create a simple vertex shader that moves vertices up by a float amount.
Unity
Shader "Custom/MoveUp" { Properties { _MoveAmount ("Move Amount", Float) = [1] } SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag float [2]; struct appdata { float4 vertex : POSITION; }; struct v2f { float4 pos : SV_POSITION; }; v2f vert(appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.pos.y += [3]; return o; } fixed4 frag(v2f i) : SV_Target { return fixed4(1,1,1,1); } ENDCG } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the property name.
Trying to add vertex.y directly instead of the property.
✗ Incorrect
The float property _MoveAmount is declared with default 0.5, then used as variable _MoveAmount to add to vertex y position.