Fixed spot light transformation

This commit is contained in:
Antoine Pilote
2024-08-29 12:54:31 -04:00
parent cf7d236540
commit 05096355be
3 changed files with 6 additions and 19 deletions

View File

@@ -366,7 +366,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
Matrix4 gizmoPosition = Matrix4(1.0f);
gizmoPosition = glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3]));
gizmoPosition = gizmoPosition * rotationMatrix;
gizmoPosition = glm::translate(gizmoPosition, { 0, cylinderLength / 2.0, 0 });
gizmoPosition = glm::translate(gizmoPosition, { 0, -cylinderLength / 2.0, 0 });
m_LineShader->Bind();
m_LineShader->SetUniform1f("u_Opacity", 1.0f);

View File

@@ -318,6 +318,7 @@ namespace Nuake
if (light.Type == Spot)
{
direction = transform.GetGlobalRotation() * Vector3(0, 0, -1);
deferredShader->SetUniform3f(uniformAccessor + "Direction", direction.x, direction.y, direction.z);
deferredShader->SetUniform1f(uniformAccessor + "OuterAngle", glm::cos(Rad(light.OuterCutoff)));
deferredShader->SetUniform1f(uniformAccessor + "InnerAngle", glm::cos(Rad(light.Cutoff)));
@@ -326,23 +327,7 @@ namespace Nuake
{
int shadowMapTextureSlot = 22 + spotShadowMapCount;
deferredShader->SetUniform1f(uniformAccessor + "ShadowMapID", spotShadowMapCount);
Matrix4 spotLightTransform = Matrix4(1.0f);
Vector3 pos = transform.GetGlobalPosition();
pos.y *= -1.0f;
pos.x *= -1.0f;
pos.z *= -1.0f;
spotLightTransform = glm::translate(spotLightTransform, pos);
Vector3 direction = transform.GetGlobalRotation() * Vector3(0, 0, 1);
auto lookatAt = lookAt(Vector3(), direction, Vector3(0, 1, 0));
Quat offset = QuatFromEuler(0, -90.0f, 0);
Quat offset2 = QuatFromEuler(180.0f, 0.0f, 0);
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
deferredShader->SetUniformMat4f(uniformAccessor + "Transform", light.GetProjection() * lookatAt * spotLightTransform);
deferredShader->SetUniformMat4f(uniformAccessor + "Transform", light.GetProjection() * glm::inverse(transform.GetGlobalTransform()));
if (ImGui::Begin(("DebugShadowMap" + std::to_string(idx)).c_str()))
{

View File

@@ -594,6 +594,8 @@ namespace Nuake
light.m_Framebuffers[0]->Clear();
{
Matrix4 spotLightTransform = Matrix4(1.0f);
Vector3 pos = lightTransform.GetGlobalPosition();
pos.y *= -1.0f;
pos.x *= -1.0f;
@@ -608,7 +610,7 @@ namespace Nuake
const Quat& globalRotation = glm::normalize(lightTransform.GetGlobalRotation());
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
shader->SetUniformMat4f("u_LightTransform", light.GetProjection() * lookatAt * spotLightTransform);
shader->SetUniformMat4f("u_LightTransform", light.GetProjection() * glm::inverse(lightTransform.GetGlobalTransform()));
for (auto e : meshView)
{
auto [transform, mesh, visibility] = meshView.get<TransformComponent, ModelComponent, VisibilityComponent>(e);