To begin, I utilized five different surface shapes such as spheres, ellipsoids, rectangles, cones (cylinders), and torus (donut shapes). I wrote my own code for creating the surface mesh and defining the vertex buffer and index buffer. I then implemented various rendering techniques, including basic rendering, diffuse reflection, specular reflection, ambient lighting, texture mapping, and normal mapping. I also distinguished between point lighting, directional lighting, and spotlight effects. Ultimately, I produced several stunning scenes.
The following are the four scenarios of this program:
-
First, please install version 3.8 of Python or install Anaconda/Miniconda.
- If you choose conda, please use
conda create -n GRAPHICS
after installation to create an environment named GRAPHICS. Then useconda activate GRAPHICS
to enter that environment.
- If you choose conda, please use
-
Use
pip install -r requirements.txt
to install the required packages: PyOpenGL, WxPython, and Numpy. -
Run the program by executing the command
pythonw Sketch.py
On Mac, please use
python.app
.
If you encounter any problems during the run, please submit an Issue.
GLSLPreview.mp4
Keys | Functions |
---|---|
Numeric keys (1 to 9 ) |
Toggle the light switches in the scene (if the corresponding number exists) |
A |
Turn on/off the ambient rendering mode. Turning off Ambient mode will cause the image to appear washed out because all objects will be displayed in their original colors without any dimming ambient light. |
S |
Turn on/off the specular rendering mode. Turning off Specular mode will remove the highlight effect from the surfaces of objects. Please rotate the object to observe the difference in the specular effect on different material surfaces. |
D |
Turn on/off the diffuse rendering mode. |
← / → |
Switch scenes. |
-
Scene 1: This scene is a testing scene, primarily used to ensure that the VBO/EBO implementation of this program is functioning correctly. It includes an 🌏 earth (sphere shape), a ring ashtray (torus shape), and a half cone, all with metallic surface applied. There are also three point lights present in the scene, colored blue, red, and yellow, that are flying around.
Scene1.mp4
-
Scene 2: The second scene is similar to the high school map in the game Phasmophobia. It features a wooden floor of a basketball court, on which there is a 🏀basketball (sphere model), an 🏈 American football (ellipsoid model), several rings (randomly colored red or blue, torus model for the ring, cylinder model for the stick). In order to create a horror-like atmosphere, I intentionally made the environment dark and added several 🔦 flashlights, to create a atmosphere of dimness.
Scene2.mp4
-
Scene 3: The third scene is a beautifully set dining table with a plethora of donuts 🥯 (All come in Glazed flavor, which is my favorite flavor. You might gain 10lbs if you ate them all 😂lol), several nicely decorated 🎁 Christmas gift boxes, chocolate cakes and elegant candles. The surface of the Christmas gift box has a reflective mirror-like effect (resembling tin foil). The donuts are textured using a special normal map that makes them look incredibly realistic! (The specific texture file can be found in the /assets folder). The only downside is that I didn't implement a shadow effect, so the candle light will shine through the cakes and it will give the impression of a very bright light beneath the cakes.
Scene3.mp4
-
Scene 4: This is a finely crafted scene featuring a 🎱 pool table with a smooth, comfortable texture and an orderly pattern of stripes. A series of pool balls and a rack are placed on the table. Four flashlight beams illuminate the center of the table and two fluorescent lamps are used for lighting. In this scene, I used a normal map to achieve the feel of the fabric on the pool table. The fluorescent lamps use an infinite light and the flashlight beams use a spotlight effect.
Scene4.mp4
The following models are used in this program:
-
Sphere/Ellipsoid Model
Sphere surface parameter equation, where
$r$ represents the radius of the sphere.Normal equation:
Texture mapping position: Each point [j/stacks, i/slices]
. Where j/stacks
represents the iteration of i/slices
represents the iteration of
The parameters of the ellipsoid model are very similar to those of the sphere model, with the only difference being that
-
Cube Model
The cube model has a total of 8 points, and different faces have different normals, all of which need to be defined manually. Please refer to DisplayableCube.py for specific VBO/EBO definitions, as they will not be explained here.
-
Cylinder/Cone Model
Surface parameter equation:
where
$r_{\mathrm{lower}}$ represents the lower radius of the cone,$r_{\mathrm{upper}}$ represents the upper radius of the cone. If the two radii are the same, it represents a cylinder.$h$ is the height.Normal equation:
-
On the top surface is:
$\vec{n}=[0, 0, 1]$ -
On the bottom surface is:
$\vec{n}=[0, 0, -1]$ -
On the edges is:
where,
$\mathbf{cSin} = (r_{\mathrm{lower}} - r_{\mathrm{upper}}) / h$ .
See DisplayableCylinder.py for specific definitions.
-
-
Torus Model
Torus surface parameter equation:
where
a = (outer + inner) / 2
,b = (outer - inner) / 2
.Torus surface normal equation:
After normalization it is:
Texture mapping position: Each point
[i/nsides, j / rings]
. Wherei/nsides
represents the iteration of$\theta$ andj / rings
represents the iteration of$\phi$ . See DisplayableTorus.py for specific definitions.
Requirements | Done |
---|---|
Generate Triangle Meshes: Ellipsoid, Torus, and Cylinder with end caps | ✅ |
Implement EBO for defining your meshes | ✅ |
Generate normals for your meshes, and implement normal visualization | ✅ |
Illuminate your meshes with diffuse, specular, and ambient components | ✅ |
Support 3 different light types (point, infinite, spotlight) | ✅ |
Create 3 different scenes | ✅ |
Texture mapping | ✅ |
Normal mapping | ✅ |
Artist Rendering |