Quiz: 3D Cameras, Lighting Models, Materials & Shaders¶
Test your understanding of Lighting (ambient, point, directional), materials, orbitControl(), and GLSL shaders with these review questions.
1. Which built-in p5.js function enables interactive 3D camera panning, orbiting, and zooming using mouse drag and scroll wheel?¶
- orbitControl()
- cameraControl()
- mouse3D()
- enableOrbit()
Show Answer
The correct answer is A. orbitControl() placed inside draw() enables automatic 3D camera navigation: left-click drag orbits, right-click drag pans, and scrolling zooms. Options B, C, and D are not p5.js functions.
Concept Tested: Orbit Control Camera
2. What type of light source illuminates all objects uniformly from all directions without casting specific directional shadows?¶
- ambientLight(v1, v2, v3)
- directionalLight(v1, v2, v3, x, y, z)
- pointLight(v1, v2, v3, x, y, z)
- spotLight(...)
Show Answer
The correct answer is A. ambientLight() casts omnidirectional ambient illumination that lights all surfaces equally, preventing completely black unlit shadows. Options B, C, and D are directional/positioned lights.
Concept Tested: Ambient Light Source
3. What type of light source emits light rays in parallel from an infinitely distant source (like the Sun)?¶
- pointLight(color, positionVector)
- directionalLight(color, directionVector)
- ambientLight(color)
- spotLight(color, position, direction)
Show Answer
The correct answer is B. directionalLight() simulates light rays traveling in parallel from a given direction vector, like sunlight. pointLight() emits outward radially from a specific 3D location. Options C and D differ.
Concept Tested: Directional Light Source
4. Which material shader displays surface normal vectors mapped directly to RGB colors without requiring external lights?¶
- basicMaterial()
- normalMaterial()
- specularMaterial()
- ambientMaterial()
Show Answer
The correct answer is B. normalMaterial() colors each face based on its normal vector (X=Red, Y=Green, Z=Blue), useful for debugging 3D geometry. Options B, C, and D require lights or show flat colors.
Concept Tested: Normal Material Shading
5. What material type reflects shiny specular highlights from point, directional, or spot lights?¶
- basicMaterial(color)
- specularMaterial(color)
- normalMaterial()
- emissiveMaterial(color)
Show Answer
The correct answer is B. specularMaterial() models shiny surfaces (like polished metal or plastic) with sharp specular reflection highlights calculated from light angles. basicMaterial() is unlit. normalMaterial() is unlit normal colors.
Concept Tested: Specular Material Highlights
6. What is the primary function of a Vertex Shader in the WebGL graphics pipeline?¶
- To compress 3D model files into ZIP archives
- To calculate the final RGBA color of individual screen pixels (fragments)
- To calculate the 3D screen space positions and transformations of geometry vertices
- To simulate audio frequencies on the sound card
Show Answer
The correct answer is C. The Vertex Shader executes once per vertex to transform 3D model coordinates through model, view, and projection matrices into clip space. Option B describes the Fragment Shader. Options C and D are unrelated.
Concept Tested: Vertex Shader Role
7. What is the primary function of a Fragment (Pixel) Shader in the WebGL graphics pipeline?¶
- To move the mouse cursor across the canvas
- To calculate the physical mass of 3D objects
- To compute the final color, lighting, texture mapping, and transparency for every rasterized pixel fragment
- To load 3D OBJ files from disk
Show Answer
The correct answer is C. The Fragment (or Pixel) Shader runs on the GPU for every single pixel covered by a polygon, computing lighting formulas, procedural patterns, and texture colors. Options B, C, and D are false.
Concept Tested: Fragment Shader Role
8. Which p5.js function loads external GLSL vertex and fragment shader files in preload()?¶
- compileShader(vertFile, fragFile)
- createShader(vertCode, fragCode)
- loadShader('vertPath.vert', 'fragPath.frag')
- importShader(shaderName)
Show Answer
The correct answer is C. loadShader(vertFilename, fragFilename) loads external GLSL shader source files during preload(). createShader() compiles raw string code. Options C and D are not p5.js functions.
Concept Tested: Load Shader Function
9. How do you pass a variable (such as time or resolution) from JavaScript into a custom GLSL shader program?¶
- myShader.setGlobal('time', millis());
- myShader.passVariable('time', millis());
- myShader.bindAttribute('time', millis());
- myShader.setUniform('u_time', millis() / 1000.0);
Show Answer
The correct answer is D. Shader uniforms are read-only constants passed from CPU JavaScript to GPU shaders using shader.setUniform('uniformName', value). Options B, C, and D are invalid method names.
Concept Tested: Shader Uniform Passing
10. Why are GPU shaders capable of rendering complex mathematical patterns (like fractals or raymarching) thousands of times faster than CPU JavaScript loops?¶
- GPUs do not use floating-point math
- GPUs have more RAM than CPUs
- Shaders run without electricity
- The GPU features thousands of parallel arithmetic cores designed to evaluate shader math on every pixel simultaneously
Show Answer
The correct answer is D. GPUs achieve extreme rendering speed through massive SIMD (Single Instruction, Multiple Data) parallelism, running fragment shader calculations across millions of pixels concurrently. Options B, C, and D are incorrect.
Concept Tested: GPU Massive Parallelism