In this assignment we are going to be adding a more accurate model for the ambient lighting contribution. We will apply this improved lighting model to a complex shape in an effort to improve the realism of the object.
Click the appropriate button above to download the starter files for this project.
Running this project produces a scene with a checkered ground plane, a blue world box, and a model of a piece of furniture, a night stand.
In this assignment we are going to replace the ambient part of the lighting model with a more accurate ambient lighting computation.
The original lighting model operates on the assumption that every point in the scene will receive some ambient light, regardless of where that point is located. In this version of the program we are going to replace that simplistic assumption with a more realistic model of ambient light, called global illumination.
In this new model each point in the scene receives an ambient lighting contribution based on how much of the "sky" the point can see. To estimate what fraction of the sky that point is exposed to we will shoot 32 randomly chosen rays from that point and count what fraction of the rays can get to the world box without first running into some other object in the scene.
To implement this improved lighting model we will need to start with an algorithm that can generate random directions for rays. Here is some code you can use for this purpose.
//------------------------------------------------------------------------------ // Random number generator // From: https://www.reedbeta.com/blog/hash-functions-for-gpu-rendering/ //------------------------------------------------------------------------------ uint rng_state = gl_GlobalInvocationID.x*521+gl_GlobalInvocationID.y; float rand_pcg() { uint state = rng_state; rng_state = rng_state * 747796405u + 2891336453u; uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; return (((word >> 22u) ^ word)%65536u)/65536.0; } // Construct a random vector in the half-sphere centered on the // normal vector n vec3 rand_vec3(vec3 n) { vec3 rnd = vec3(rand_pcg(),rand_pcg(),rand_pcg()); if(dot(rnd,n) < 0) rnd = -rnd; return normalize(rnd); }
You will use this code to compute your ambient lighting contribution in the function that computes the lighting for the night stand. Do the following:
c.p + c.n * 0.01
.Finally, to get a better balance between ambient and point light sources, you will need to adjust the material properties used for the night stand.