Hello all,
I’ve been browsing the forums for a while and I’ve found some useful stuff, so I thought I’d ask a few questions of my own.
My first question pertains to how I would go about moving a light source. I want the camera position to stay constant, but I’d like to be able to use the keyboard to move where the light is shining from and update my shading accordingly. Here’s how I’m currently doing it, to no avail:
I have a handler in my main source file which takes three vertices where the light should be positioned.
//from main
//declaring the handler
GLint h_aLight;
//globals for light position
float lightX = 5;
float lightY = 5;
float lightZ = 5;
//inside my function to install the shaders
h_aLight = safe_glGetAttribLocation(ShadeProg, "aLight");
//inside my draw function, after I've done the appropriate model transforms
//set the light position in the shader
glUniform3f(h_aLight, lightX, lightY, lightZ);
I’m not worrying about applying the transforms yet, I know I need to multiply the model matrix by the normals, but that’s a problem for later. Those values are passed off to a variable in my vertex shader, which is used to calculate the direction of the light by created by subtracting the position of the object from the points passed to my light handler to create a vector.
//vertex shader
//declaring the variable
varying vec3 lightPos;
void main(){
//...
//creating the vector
lightPos = vec3(aLight.x - vPosition.x, aLight.y - vPosition.y, aLight.z - vPosition.z);
//shading calculations based on the light vector
}
Because my light direction is updated here and all the shading calculations are done AFTER this point, I would assume that updating the values passed to the light handler would result in a new light direction vector that my calculations would use for brand new calculations. However, I don’t see any difference in the picture at all. I make sure that the global variables are getting updated with a printf() right after glUniform3f(h_aLight, lightX, lightY, lightZ); that displays the values of lightX, lightY, and lightZ.
Any help would be appreciated