0

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

}
The Coding Wombat
  • 805
  • 1
  • 10
  • 29
  • Why do you want to transform the lights to a different space? It is totally unclear what exactly you want do do here. `transform` seems to include the projection matrix, and you usually would _never_ want the lighting caluculaions done in clip space. If your lights are specified in world space, you probably want to do the lighting calculation there, and for that, you need to separate the model to world transfrom from your overall `transform` matrix _for the vertices_. – derhass Jun 20 '19 at 17:49
  • @derhass My lights are in world space. My different meshes have different local transforms. "transform" contains the projection, view and local transformation matrices. I want to know how I have to transform the vPosition of the meshes, how to transform the vNormals of the meshes, which are in model space. And how to transform the lights, which are already in world space. – The Coding Wombat Jun 20 '19 at 22:11

0 Answers0