little opti ?
This commit is contained in:
parent
0ded879dce
commit
40c0846029
1 changed files with 4 additions and 5 deletions
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue