0
0
Unityframework~10 mins

Custom shader fundamentals in Unity - Interactive Code Practice

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

Complete the code to declare a simple shader with a name.

Unity
Shader "[1]" {
    SubShader {
        Pass {
        }
    }
}
Drag options to blanks, or click blank then click option'
AMyShader
BStandard
CCustom/Basic
DSimple/Color
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name without quotes
Using an invalid format for the shader name
2fill in blank
medium

Complete the code to define a color property in the Properties block.

Unity
Properties {
    _Color ("Main Color", [1]) = (1,1,1,1)
}
Drag options to blanks, or click blank then click option'
ARange(0,1)
BColor
CVector
DFloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Float' or 'Range' for colors
Forgetting the parentheses around the default value
3fill in blank
hard

Fix the error in the fragment shader function declaration.

Unity
fixed4 [1](v2f i) : SV_Target {
    return _Color;
}
Drag options to blanks, or click blank then click option'
Afrag
Bvert
Cvertex
Dfragment
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'vert' which is for vertex shader
Using 'vertex' or 'fragment' which are not standard function names here
4fill in blank
hard

Fill both blanks to sample the main texture color in the fragment shader.

Unity
sampler2D _MainTex;

fixed4 frag(v2f i) : SV_Target {
    fixed4 col = tex2D([1], [2]);
    return col * _Color;
}
Drag options to blanks, or click blank then click option'
A_MainTex
Bi.uv
Ci.vertex
D_Color
Attempts:
3 left
💡 Hint
Common Mistakes
Using _Color instead of the texture sampler
Using i.vertex instead of i.uv for texture coordinates
5fill in blank
hard

Fill all three blanks to declare a vertex input struct with position and UV, and pass UV to fragment shader.

Unity
struct appdata {
    float4 [1] : POSITION;
    float2 [2] : TEXCOORD0;
};

struct v2f {
    float2 [3] : TEXCOORD0;
    float4 vertex : SV_POSITION;
};
Drag options to blanks, or click blank then click option'
Avertex
Buv
Dpos
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pos' instead of 'vertex' for position
Using different names for UV in appdata and v2f structs