This page was last updated: December 1, 2019
Project #1 asked you to create your own object in a Vulkan program. Project #2 is asking you to add lighting to it.
In the sample.cpp code, you already have a start on this with the
lightBuf struct having the uLightPos vec4 in it.
You need to add:
'l' (ell) | Toggle lighting on and off |
'm' | Toggle display mode (textures vs. colors) |
'r' | Toggle rotation-animation and using the mouse |
Esc, 'q' | Exit the program |
Feel free to add more keyboard inputs to control more aspects of the lighting if you want.
In your video, somehow demonstrate that this all works. This could be by:
I recommend you copy the Sample2019 folder and edit the sample.cpp file.
The file LightingForClass.zip cointains lighting shaders for use with OpenGL. Remember that you need to Vulkan-ize them.
Use the Teach system to turn in your:
http://cs.oregonstate.edu/~mjb/cs557/Handouts/lighting.1pp.pdf
// uniform variable block: struct matBuf { glm::mat4 uModelMatrix; glm::mat4 uViewMatrix; glm::mat4 uProjectionMatrix; glm::mat4 uNormalMatrix; }; // uniform variable block: struct lightBuf { float uKa; float uKd; float uKs; glm::vec4 uLightPos; glm::vec3 uLightSpecularColor; float uShininess; glm::vec4 uEyePos; };
glm::vec3 eye(0., 0., EYEDIST); glm::vec3 look(0., 0., 0.); glm::vec3 up(0., 1., 0.); Matrices.uViewMatrix = glm::lookAt( eye, look, up ); Matrices.uProjectionMatrix = glm::perspective( FOV, (double)Width/(double)Height, 0.1, 1000. ); Matrices.uProjectionMatrix[1][1] *= -1.; Matrices.uNormalMatrix = glm::mat4( glm::inverseTranspose( glm::mat3( Matrices.uModelMatrix ) ) ); // initialize the light position: Light.uKa = 0.1f; Light.uKd = 0.6f; Light.uKs = 0.3f; Light.uEyePos = glm::vec4( eye, 1. ); Light.uLightPos = glm::vec4( 0., 0., 10., 1. ); Light.uLightSpecularColor = glm::vec3( 1., 1., 1. ); Light.uShininess = 20.f;
// change the viewing matrix: glm::vec3 eye(0., 0., EYEDIST); //glm::vec3 look(0., 0., 0.); //glm::vec3 up(0., 1., 0.); //Matrices.uViewMatrix = glm::lookAt(eye, look, up); // change the normal matrix: Matrices.uNormalMatrix = glm::mat4(glm::inverseTranspose(glm::mat3(Matrices.uModelMatrix)));
// non-opaque must be in a uniform block: layout( std140, set = 0, binding = 0 ) uniform matBuf { mat4 uModelMatrix; mat4 uViewMatrix; mat4 uProjectionMatrix; mat4 uNormalMatrix; } Matrices; layout( std140, set = 1, binding = 0 ) uniform lightBuf { float uKa; float uKd; float uKs; vec4 uLightPos; vec3 uLightSpecularColor; float uShininess; vec4 uEyePos; } Light;
Feature | Points |
---|---|
Ka, Kd, Ks | 25 |
Light Position | 25 |
Light Specular Color | 25 |
Shininess | 25 |
Potential Total | 100 |