CS 419v/519v -- Winter Quarter 2018

Project #2

100 Points

Due: Fenruary 9

Add Lighting to Your Own Vulkan Program


This page was last updated: January 31, 2018


Requirements

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:

Keep the 'm' and 'i' keys doing what they used to do. But, add a 'l' (ell) key to turn lighting off and on.

Feel free to add more keyboard inputs to control more aspects of the lighting if you want.

Hints

In your video, somehow demonstrate that this all works. This could be by:

  1. Demonstrating the features by toggling them off and on with keyboard keys.
  2. Animating the features by using the uTime uniform variable.

I recommend you copy the Sample2017 folder and edit the sample.cpp file.

You can define your object with either direct drawing with a vertex data buffer, or with an indexed draw with a vertex data buffer and index buffer.

The file LightingForClass.zip cointains lighting shaders for use with OpenGL. Remember that you need to Vulkan-ize them.

Turn-in:

Use the Teach system to turn in your:

  1. A one-page PDF with a title, your name, your email address, nice screen shots from your program, and the link to the Kaltura video demonstrating that your project does what the requirements ask for. I'd like you to narrate your video so that you can tell me what you did.

Here's a Link to a video showing the Vulkan Lighting

Proj02.mp4

Here's a Link to the OpenGL Shader-Lighting Notes

http://cs.oregonstate.edu/~mjb/cs557/Handouts/lighting.1pp.pdf

Here's a Vertex Shader and a Skeleton Fragment Shader to Start With

light-vert.vert

light-frag.frag

Here's What You Need to Change in sample.cpp's struct Definitions


// 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;
};

Here's What You Need to Change in sample.cpp's Reset( ) Function


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;

Here's What You Need to Change in sample.cpp's UpdateScene( ) Function


// 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)));

Here's What You Need to Change in the Vertex Shader


// 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;

Grading:

FeaturePoints
Ka, Kd, Ks25
Light Position25
Light Specular Color25
Shininess25
Potential Total100