Hi! I tried figuring this out without asking for help but I just can’t do it :mad: The problem is that my spotlight rotates with the camera. It’s in the correct position but when the camera rotates so does the light. What I’m doing is I have a LightMatrix translated to the light’s position - the camera’s position. Then I rotate it by the camera’s Y angle and the opposite of the camera’s X angle. Then I send the LightMatrix to the shader, and I send the light’s rotation:
float LightMatrix[16] = IDENTITY_MATRIX4;
//The false argument is just to check if it's relative or not
TranslateMatrix(LightMatrix, Position.m_x - CameraPosition.m_x, Position.m_y - CameraPosition.m_y, Position.m_z - CameraPosition.m_z, false);
RotateMatrix(LightMatrix, CameraRotation.m_y, Y_AXIS);
RotateMatrix(LightMatrix, -CameraRotation.m_x, X_AXIS);
glUniformMatrix4fv(glGetUniformLocation(MainShader, "LightMatrix"), 1, false, LightMatrix);
float LightRot[] = {RotationCounter.m_x, RotationCounter.m_y, RotationCounter.m_z};
SendUniform3f("SpotDirection", LightRot, MainShader);
Then in the shader I use this line:
float spotEffect = dot(normalize(SpotDirection * mat3(LightMatrix)), normalize(-lightDir));
I read in glLight specification that GL_SPOT_DIRECTION is transformed by the upper 3x3 of the modelview matrix. However no matter what try the light rotates with the camera. Any help is greatly appreciated!!!