From 6b4fef6a2bbfc32a178cbd258f1fbeaa07bf9533 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 12 Nov 2021 17:00:07 +0100 Subject: [PATCH] Fix missing normalization of the first plane vector after cross product --- src/lightmap/cpuraytracer.cpp | 4 ++-- src/lightmap/glsl_rgen_light.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lightmap/cpuraytracer.cpp b/src/lightmap/cpuraytracer.cpp index ef10da1..05b3147 100644 --- a/src/lightmap/cpuraytracer.cpp +++ b/src/lightmap/cpuraytracer.cpp @@ -251,7 +251,7 @@ void CPURaytracer::RunLightTrace(CPUTraceState& state) float attenuation = 0.0f; if (state.PassType == 0 && surface) { - Vec3 e0 = Vec3::Cross(normal, std::abs(normal.x) < std::abs(normal.y) ? Vec3(1.0f, 0.0f, 0.0f) : Vec3(0.0f, 1.0f, 0.0f)); + Vec3 e0 = Vec3::Normalize(Vec3::Cross(normal, std::abs(normal.x) < std::abs(normal.y) ? Vec3(1.0f, 0.0f, 0.0f) : Vec3(0.0f, 1.0f, 0.0f))); Vec3 e1 = Vec3::Cross(normal, e0); e0 = Vec3::Cross(normal, e1); @@ -308,7 +308,7 @@ void CPURaytracer::RunLightTrace(CPUTraceState& state) if (state.PassType == 0 && surface) { - Vec3 e0 = Vec3::Cross(normal, std::abs(normal.x) < std::abs(normal.y) ? Vec3(1.0f, 0.0f, 0.0f) : Vec3(0.0f, 1.0f, 0.0f)); + Vec3 e0 = Vec3::Normalize(Vec3::Cross(normal, std::abs(normal.x) < std::abs(normal.y) ? Vec3(1.0f, 0.0f, 0.0f) : Vec3(0.0f, 1.0f, 0.0f))); Vec3 e1 = Vec3::Cross(normal, e0); e0 = Vec3::Cross(normal, e1); for (uint32_t i = 0; i < state.SampleCount; i++) diff --git a/src/lightmap/glsl_rgen_light.h b/src/lightmap/glsl_rgen_light.h index 7b30a28..19cfd51 100644 --- a/src/lightmap/glsl_rgen_light.h +++ b/src/lightmap/glsl_rgen_light.h @@ -87,7 +87,7 @@ void main() float attenuation = 0.0; if (PassType == 0 && surfaceIndex >= 0) { - vec3 e0 = cross(normal, abs(normal.x) < abs(normal.y) ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0)); + vec3 e0 = normalize(cross(normal, abs(normal.x) < abs(normal.y) ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0))); vec3 e1 = cross(normal, e0); e0 = cross(normal, e1); @@ -139,7 +139,7 @@ void main() if (PassType == 0 && surfaceIndex >= 0) { - vec3 e0 = cross(normal, abs(normal.x) < abs(normal.y) ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0)); + vec3 e0 = normalize(cross(normal, abs(normal.x) < abs(normal.y) ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0))); vec3 e1 = cross(normal, e0); e0 = cross(normal, e1); for (uint i = 0; i < SampleCount; i++)