From 6fc7d7a4c3d53c647d88e981b83957e7f00c8bfc Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sun, 28 Sep 2025 04:15:28 +0200 Subject: [PATCH] Revert "little opti ?" This reverts commit 40c0846029ee7d3dc4bb20f91fb9c2620002f133. --- src/ray_marching.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ray_marching.go b/src/ray_marching.go index 2a1ccd9..6af7946 100644 --- a/src/ray_marching.go +++ b/src/ray_marching.go @@ -8,7 +8,8 @@ import ( "math" ) -func phongShading(point Vector3, normal Vector3, lightVec Vector3, mat Material) Vector3 { +func phongShading(point Vector3, normal Vector3, mat Material) Vector3 { + lightVec := (lightPos.Sub(point)).Normalized() reflectLight := Reflect(lightVec, normal) eyeVec := (cameraPos.Sub(point)).Normalized() brutMat := mat.GetMaterialBrut() @@ -23,7 +24,8 @@ func phongShading(point Vector3, normal Vector3, lightVec Vector3, mat Material) return ambiant.Add(diffuse).Add(specular) } -func shadow(point Vector3, direction Vector3) float64 { +func shadow(point Vector3) float64 { + direction := (lightPos.Sub(point)).Normalized() p := point.Add(direction.Scale(5 * EPS)) res := 1.0 dist_total := 0.0 @@ -48,8 +50,7 @@ func rayMarch(origin Vector3, direction Vector3) (bool, Vector3) { dist, mat := scene.Distance(p) if dist < EPS { normal := Gradient(scene, p, EPS).Normalized() - lightVec := (lightPos.Sub(p)).Normalized() - return true, phongShading(p, normal, lightVec, mat).Scale(max(shadow(p, lightVec), 0.3)) + return true, phongShading(p, normal, mat).Scale(max(shadow(p), 0.3)) // return true, phongShading(p, normal, *mat) } if dist > MAX_DIST {