5x performance, sdf.Distance return only Distance now. Creation of sdf.GetMaterial

This commit is contained in:
Crizomb 2025-09-28 18:44:59 +02:00
parent b5c9eaf692
commit b3dcda11e6
4 changed files with 105 additions and 61 deletions

View file

@ -30,7 +30,7 @@ func shadow(point Vector3) float64 {
res := 1.0
dist_total := 0.0
for range MAX_STEP {
dist, _ := scene.Distance(p)
dist := scene.Distance(p)
if dist < EPS {
return 0
}
@ -62,8 +62,9 @@ func reflect(point Vector3, direction Vector3, normal Vector3, mat Material, ref
func rayMarch(origin Vector3, direction Vector3, reflectNumber int) (bool, Vector3) {
p := origin
for range MAX_STEP {
dist, mat := scene.Distance(p)
dist := scene.Distance(p)
if dist < EPS {
mat := scene.GetMaterial(p)
normal := Gradient(scene, p, EPS).Normalized()
phongShade := phongShading(p, normal, mat)
shadowCoeff := max(shadow(p), 0.3)