Tuesday, November 25, 2014

Engineering II - Assignment 10 - Directional and Ambient Lighting

Assignment 10- Directional and Ambient Lighting


ZIP LINK

Assignment10.zip

Write-Up


The basics of this assignment were to focus on getting correct lighting, both ambient and directional working in our game engine. This required our meshes to be using their normals, which required our Maya Exporters to include those as well.

With the normals being read by the Maya Exporter, this also required our shader programs (vertex and fragment) to use them as well.

Finally, we needed to include the ambient and directional lighting, with movement of the directional light, and then using PIX to capture some debug pixel information.


Technical Write-Up

Maya Exporter Update

The mesh type was already implemented in our last assignment, so I needed to have the exporter include the normal from the mesh as well. This was a simple addition into the exporter file requesting the newly included normal values.

The normal values are included in each vertex of the shape being imported. This is different than I initially viewed, as I expected the normal of the object to be with respect to its “side” or “face”. Maya includes additional vertices in the models to help make the rendering of the image correct with the additional vertices’ normals being included.

After this was done, I re-exported all of my initial mesh files and confirmed the normals were being included.

Ambient and Directional Lighting 

The inclusion of ambient and directional lighting was slightly more difficult. This required the alteration of the fragment shader to recognize the color of the ambient light, the color of the directional light, and the direction of the directional light.

The vertex and fragment shaders also required the normals to be input and output correctly. This allowed for the addition of the directional light and ambient light together, using the normal, and calculating the color correctly via the fragment shader.
The vertex shader required the normals to be calculated with the mesh, and the world rotation.

Here is an image of my scene with ambient and directional lighting:




The light for the image is coming from below and to the right (your right) of the character, and has a red-ish tint. The ambient light is white, and is fairly dark, while the directional light has the heavier value of red.

I implemented movement controls for the directional light, which allow you to change the direction of it. I also allow the user to alter the color of the ambient light, and the directional light as well.

If you were to access the code and alter the lighting manually, it would be inside of my Graphics.cpp file,and you would change the variable's values which are D3DXVECTOR3 values. For color the x would be red, the y would be green, and the z would be blue. While for the direction, x, y, and z would be as normal.

The control schemes for altering these values at runtime are as follows:

I - Move the directional light to face the negative z direction
K - Move the directional light to face the positive z direction
J - Move the directional light to face the negative x direction
L - Move the directional light to face the positive x direction


R - Adds to the red value of the directional light color
G - Adds to the green value of the directional light color
B - Adds to the blue value of the directional light color


T - Adds to the red value of the ambient light color
Y - Adds to the green value of the ambient light color
H - Adds to the blue value of the ambient light color
***These color controls add to the color value, and if they exceed 1.0f, they loop back to 0.0f.


PIX Debug Pixel 

The last thing to confirm was the pixel color information, and we used PIX to do this. Below is the captured PIX image:




The image shows that during the draw call, you can click on a pixel in render (right side of the image) and request its history of color information. It will also allow you to step through your code for the shader and see what the code is doing.

This allows you to more simply see, step by step, what your fragment shader code is doing.

This is similar to a previous PIX step where we were able to debug the vertex shader by selecting a vertex on the mesh and stepping through its code.

All of this code is done purely in Debug mode, as you cannot step through the code in Release mode.

Realized Learning Moments
This assignment allowed me to see the key reason for Maya including multiple vertices in a mesh. It was confusing to create your own mesh by hand, and understand that a cube has eight vertices, but when Maya generates a cube it has 24 vertices. These additional vertices are for UVs and normals. If these weren’t created, then the rendering method would take the eight vertices of a cube, create a cube surface, and render it almost as a slightly flat faced sphere.

I had a great learning moment of double checking the variable names being used in your shader, and how you access them. A simple mistake I made, and then an additional pair of eyes helped out with.

Time Used

Reading: 2 hours

Write-Up: 1.5 hours
Technical Write-Up: 1.5 hours
Coding: 4 hours

No comments:

Post a Comment