little opti ?

This commit is contained in:
Crizomb 2025-09-28 04:09:58 +02:00
parent 0ded879dce
commit 40c0846029

View file

@ -8,8 +8,7 @@ import (
"math" "math"
) )
func phongShading(point Vector3, normal Vector3, mat Material) Vector3 { func phongShading(point Vector3, normal Vector3, lightVec Vector3, mat Material) Vector3 {
lightVec := (lightPos.Sub(point)).Normalized()
reflectLight := Reflect(lightVec, normal) reflectLight := Reflect(lightVec, normal)
eyeVec := (cameraPos.Sub(point)).Normalized() eyeVec := (cameraPos.Sub(point)).Normalized()
brutMat := mat.GetMaterialBrut() brutMat := mat.GetMaterialBrut()
@ -24,8 +23,7 @@ func phongShading(point Vector3, normal Vector3, mat Material) Vector3 {
return ambiant.Add(diffuse).Add(specular) return ambiant.Add(diffuse).Add(specular)
} }
func shadow(point Vector3) float64 { func shadow(point Vector3, direction Vector3) float64 {
direction := (lightPos.Sub(point)).Normalized()
p := point.Add(direction.Scale(5 * EPS)) p := point.Add(direction.Scale(5 * EPS))
res := 1.0 res := 1.0
dist_total := 0.0 dist_total := 0.0
@ -50,7 +48,8 @@ func rayMarch(origin Vector3, direction Vector3) (bool, Vector3) {
dist, mat := scene.Distance(p) dist, mat := scene.Distance(p)
if dist < EPS { if dist < EPS {
normal := Gradient(scene, p, EPS).Normalized() 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) // return true, phongShading(p, normal, *mat)
} }
if dist > MAX_DIST { if dist > MAX_DIST {