I'm using a scene graph for my scene. It contains lights and meshes. Meshes have local transforms, and if a node is the child of a mesh node, its own local transform gets composed with the transform of its parent.
Now i am trying to implement lights. I send the coordinates of lights (world space coordinates) as a uniform to my shader.
Do I have to transform these light coordinates? It does not make sense to me to have to transform these light coordinates with the transform that is specific to a mesh.
Do I need to send another uniform matrix to the shader to transform the lights in a different way?
My code:
#version 330
const int numOfLights = 2;
// shader input
in vec2 vUV; // vertex uv coordinate
in vec3 vNormal; // untransformed vertex normal
in vec3 vPosition; // untransformed vertex position
uniform vec3 pointLights[numOfLights];
// shader output
out vec4 normal; // transformed vertex normal
out vec2 uv;
out vec4 position;
out vec3 lights[numOfLights];
uniform mat4 transform; //transform unique for this mesh containing the camera transformation
// vertex shader
void main()
{
position = transform * vec4(vPosition, 1.0);
// transform vertex using supplied matrix
gl_Position = position;
// forward normal and uv coordinate; will be interpolated over triangle
normal = transform * vec4( vNormal, 0.0f );
uv = vUV;
for (int i = 0; i < numOfLights; i++) {
//lights[i] = (transform * vec4(pointLights[i], 1.0)).xyz; //**Transform**?
lights[i] = pointLights[i];
}
}