0
0
Unityframework~20 mins

Why shaders control visual rendering in Unity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shader Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
    }
  }
}
AThe surface will appear black.
BThe surface will appear bright green.
CThe surface will appear white.
DThe surface will appear bright red.
Attempts:
2 left
💡 Hint
Look at the color returned in the fragment shader.
🧠 Conceptual
intermediate
1:30remaining
Why do shaders control visual rendering?
Why are shaders essential for controlling how objects appear visually in Unity?
ABecause shaders control the physics simulation of objects.
BBecause shaders store the 3D models of objects.
CBecause shaders define how light interacts with surfaces and how pixels are colored.
DBecause shaders manage the audio effects in the scene.
Attempts:
2 left
💡 Hint
Think about what changes the color and brightness of pixels on screen.
🔧 Debug
advanced
2: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
    }
  }
}
AThe fragment shader return color is missing the alpha value, causing black output.
BThe vertex shader does not transform the vertex position correctly.
CThe shader is missing a texture sample, so it cannot color the surface.
DThe shader is missing a lighting calculation, so it defaults to black.
Attempts:
2 left
💡 Hint
Check the return value of the fragment shader carefully.
📝 Syntax
advanced
1:30remaining
Which shader code snippet has correct syntax?
Which of the following shader fragment functions is syntactically correct in Unity's CG shader language?
Afixed4 frag(v2f i) : SV_Target { return fixed4(1, 1, 1); }
Bfixed4 frag(v2f i) : SV_Target { return fixed4(1, 1, 1, 1); }
Cfixed4 frag(v2f i) : SV_Target return fixed4(1, 1, 1, 1);
Dfixed4 frag(v2f i) SV_Target { return fixed4(1, 1, 1, 1); }
Attempts:
2 left
💡 Hint
Look for correct function declaration and return statement syntax.
🚀 Application
expert
3: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?
AChange the fragment shader return to fixed4(1, 0, 0, 0.5) and enable blending in the shader settings.
BChange the fragment shader return to fixed4(1, 0, 0, 1) and disable depth testing.
CChange the vertex shader to output alpha 0.5 and keep fragment shader unchanged.
DAdd a texture sample with alpha 0.5 but keep fragment shader return fixed4(1, 0, 0, 1).
Attempts:
2 left
💡 Hint
Transparency requires alpha less than 1 and blending enabled.