0
0
Unityframework~10 mins

Why shaders control visual rendering in Unity - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A(1,1,1,1)
Bred
Cfloat4(1,0,0,1)
D"blue"
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names as strings instead of numeric vectors.
Using incorrect syntax like float4 without proper context.
2fill in blank
medium

Complete 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'
Auv
Bsampler2D
Cfloat4
D_MainTex
Attempts:
3 left
💡 Hint
Common Mistakes
Using the type name instead of the sampler variable.
Passing UV coordinates incorrectly.
3fill in blank
hard

Fix 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'
AlightIntensity
BlightDir
ClightColor
DlightPos
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.
4fill in blank
hard

Fill 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'
A1.0
B0.5
C_Brightness
D_Color
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.
5fill in blank
hard

Fill 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'
A0.5
B_MoveAmount
Cv.vertex.y
DmoveAmount
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.