OpenGL OpenGL Shaders 2 — Questions and Answers
Question 1: What GLSL built-in function returns the dot product of two vectors?
- cross()
- reflect()
- dot() (Correct answer)
- normalize()
Correct answer: dot()
The GLSL dot(genType x, genType y) function computes the scalar dot product of two vectors.
Question 2: Which GLSL type represents a 4×4 floating-point matrix?
- mat3
- mat4 (Correct answer)
- vec4
- dmat4
Correct answer: mat4
mat4 is a 4×4 matrix of float components, commonly used for model-view-projection transforms.
Question 3: What does the GLSL built-in texture() function do?
- Creates a new texture object
- Samples a texture at given coordinates (Correct answer)
- Binds a texture unit
- Deletes a texture
Correct answer: Samples a texture at given coordinates
texture(sampler, coord) fetches a texel from the texture bound to the sampler at the specified coordinates.
Question 4: Which GLSL qualifier marks a fragment shader output variable that writes to a color attachment?
- in
- uniform
- out (Correct answer)
- varying
Correct answer: out
Fragment shader output variables declared with 'out' are written to the corresponding framebuffer color attachment.
Question 5: What is the purpose of the GLSL normalize() function?
- Scales a vector to unit length (Correct answer)
- Rounds float components to integers
- Clamps values between 0 and 1
- Computes vector cross product
Correct answer: Scales a vector to unit length
normalize(v) divides a vector by its magnitude, returning a direction vector of length 1.
Question 6: Which GLSL version directive is required to use the core profile layout qualifiers?
- #version 110
- #version 120
- #version 330 core (Correct answer)
- #version 210
Correct answer: #version 330 core
Layout qualifiers such as 'layout(location = 0)' require at least #version 330 core in GLSL.
What GLSL built-in function returns the dot product of two vectors?