reflection added
This commit is contained in:
parent
6fc7d7a4c3
commit
a6770d7fac
3 changed files with 24 additions and 6 deletions
|
|
@ -44,13 +44,31 @@ func shadow(point Vector3) float64 {
|
|||
return res
|
||||
}
|
||||
|
||||
func rayMarch(origin Vector3, direction Vector3) (bool, Vector3) {
|
||||
func reflect(point Vector3, direction Vector3, normal Vector3, mat Material, reflectNumber int) Vector3 {
|
||||
brutMat := mat.GetMaterialBrut()
|
||||
if reflectNumber <= 0 || brutMat.reflectanceFac < EPS {
|
||||
return Vector3{0, 0, 0}
|
||||
}
|
||||
reflected := Reflect(direction, normal).Scale(-1)
|
||||
reflectRayOrigin := point.Add(reflected.Scale(5 * EPS))
|
||||
hit, color := rayMarch(reflectRayOrigin, reflected, reflectNumber-1)
|
||||
if !hit {
|
||||
color = Vector3{0, 0, 0}
|
||||
}
|
||||
// fmt.Println("Reflect")
|
||||
return color.Scale(brutMat.reflectanceFac)
|
||||
}
|
||||
|
||||
func rayMarch(origin Vector3, direction Vector3, reflectNumber int) (bool, Vector3) {
|
||||
p := origin
|
||||
for range MAX_STEP {
|
||||
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))
|
||||
phongShade := phongShading(p, normal, mat)
|
||||
shadowCoeff := max(shadow(p), 0.3)
|
||||
reflectColor := reflect(p, direction, normal, mat, reflectNumber)
|
||||
return true, phongShade.Add(reflectColor).Scale(shadowCoeff)
|
||||
// return true, phongShading(p, normal, *mat)
|
||||
}
|
||||
if dist > MAX_DIST {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue