Labs /

TP-4


Class Organization

Labs

* TP-5?

Gallery of Past Projects

Lab Sessions * Lab Sessions Overview * Assignments * Raytracing project * OpenGL project * Polytech Extension * Gallery

percent right percent edit SideBar

TP-4

Illumination and Illumination

The objectives of this TP are:

  • Understand the phong lighting model and it's implementation
  • Understand how to map textures

Illumination

Illumination is an essential element in 3D world, and it plays a crucial role in how we perceive objects around us. Understanding how light works is essential in creating realistic graphics in computer graphics. However, accurately calculating how light interacts with objects is a complex task, and it involves calculating light intensity, color, and direction at every point on an object's surface. This problem becomes even more challenging when you consider how light interacts with different surfaces and materials.

Thus, several simplified models for lighting have been proposed. One of them is the Phong model. A Phong lighting model simplifies the complex process of calculating lighting by breaking it down into three main components: ambient, diffuse, and specular lighting. The ambient component approximates the light that bounces off other objects in the environment and illuminates the object from all directions. The diffuse component simulates the light that scatters in different directions when it hits a rough surface, creating a matte appearance. The specular component models the reflection of light from a shiny surface, creating a highlight.

By using these three components, the Phong lighting model can create a more realistic representation of how light interacts with objects in a scene. It has become a popular model used in computer graphics because it can create stunning visuals with relatively simple calculations.


Components of the Phong Lighting Model

Overview: Light Reflection

We are going to implement the Phong model using the LightingSphere class. To do this, complete the phong.frag shader. You should get a final output like this.


Phong Output

Textures

Texture mapping is a technique used to apply a 2D image, known as a texture, onto a 3D object. This allows for more realistic and detailed rendering of objects in computer graphics. Textures can be images of any kind, such as photographs, patterns, or even generated images.

In OpenGL, textures are loaded and stored on the GPU as texture objects and are accessed through a special type of variable called a sampler. A sampler is an object that specifies how the texture should be accessed, such as the filtering mode, the wrapping mode, and the texture coordinates.

The sampler2D data type in OpenGL is specifically used to sample 2D textures. The sampler2D variable is used in conjunction with texture coordinates to specify the portion of the texture that should be mapped onto the 3D object. The texture coordinates are typically provided by the application and specify the position of each vertex on the texture.

During rendering, the sampler2D variable is used to access the texture object stored on the GPU and retrieve the colour values for each texel (texture pixel) that corresponds to the texture coordinates of each vertex. These colour values are then used to determine the final colour of each pixel in the rendered image, giving the 3D object the appearance of being covered with texture.

For this part of the exercise, we will use the TexturedSphere class. Note that the shaders texture.frag and texture.vert are already complete along with the Texture class. All you have to do is complete the draw call for TexturedSphere. This is done using the following GL calls:

In the end, you should get an output like this.


Texture Output

Bonus: Skybox

A skybox is the quickest hack to make a bad-looking 3D environment feel more immersive. It is essentially a cube with textures mapped on each face, creating a seamless environment for the viewer. It is a popular technique used in 3D graphics and game development to simulate a realistic and immersive environment. LearnOpenGL has an excellent tutorial on skybox.

Bonus: Combining them together

Combine the two different types of shaders studied today to get a textured model with illumination. What sort of changes did you make in your shaders?

Bonus: Other Lighting models

Try out other simple lighting models, such as the Cel-shaded lighting model (used a lot by Nintendo to give a toonish look to it's games) or Lambertian model. What differences did you observe?

Recent Changes (All) | Edit SideBar Page last modified on April 03, 2025, at 12:26 AM Edit Page | Page History
Powered by PmWiki