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