Get position of light from lightcomp

Hi!

Im doing the learnopengl.com tutorials for lights and have some problems figuring out how to get the position of the light from the lightcomp into my code.

Im passing the normals in worldspace from the vertex shader to the fragment shader for making the calculation in the fragment shader:

[code] // Normals
vec3 worldSpaceNorm = normalize(TDDeformNorm(N));
oVert.worldSpaceNorm.xyz = worldSpaceNorm;

// fragment position
oVert.worldSpacePos.xyz = worldSpacePos.xyz;[/code]

I then passing the lightposition as an uniform into the shader but how can I pass in the position of the light from the light comp?

I have been reading this:
docs.derivative.ca/Write_a_GLSL … c_Uniforms

but cannot get it right

thanks
light.toe (6.22 KB)

edit: see malcolm’s better answer below

Check out the docs here:
docs.derivative.ca/Write_a_GLSL_Material
specifically, the uTDLights uniform. That has the position already for you

So easy. It was all there. Sorry, didnt read properly …

uTDLights[0].position.xyz

As well as camera position for calculating specular light. For pulling the xyz position for the camera from the TDMatrix struct. Is it correct to write:

uTDMats[0].cam[0].xyz

At least it doesnt give me any error and behaves more or less as expected.

Thanks

I was wrong.

uTDMats[0].cam[0].xyz

doesnt provide me of the position of the camera from the cam comp and I cannot find it in the documentation.

My calculation for ambient diffuse and specular behaves as expected as long i hardcode the camera position i worldspace but I guess I can pull the position from the camera comp the same way as I can get the light position?

In the example below I have hardcoded the position.

vec3 viewDir = normalize(uCamPos - iVert.worldSpacePos);

Is it possible to get it from the camcomp without creating my own uniform?

The position of the camera can be obtained from

uTDMats[TDCameraIndex()].camInverse[3].xyz

This is pulling out the translation values from the inverse camera matrix, which is the position of the camera.