smooth + mixmat bug fix
This commit is contained in:
parent
60730edb7b
commit
e35cca1830
3 changed files with 20 additions and 16 deletions
18
material.go
18
material.go
|
|
@ -41,8 +41,8 @@ func DefaultMaterial(ambiantColor Color) Material {
|
||||||
return Material{
|
return Material{
|
||||||
ambiantColor: ambiantColor,
|
ambiantColor: ambiantColor,
|
||||||
diffuseColor: Vector3{255, 255, 255},
|
diffuseColor: Vector3{255, 255, 255},
|
||||||
diffuseFac: 1.0,
|
diffuseFac: 0.5,
|
||||||
specularColor: Vector3{0, 255, 0},
|
specularColor: Vector3{255, 255, 255},
|
||||||
specularFac: 1.0,
|
specularFac: 1.0,
|
||||||
specularExp: 32.0,
|
specularExp: 32.0,
|
||||||
reflectanceFac: 0.0,
|
reflectanceFac: 0.0,
|
||||||
|
|
@ -54,16 +54,16 @@ func DefaultMaterial(ambiantColor Color) Material {
|
||||||
|
|
||||||
func MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
func MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
||||||
return Material{
|
return Material{
|
||||||
mat1.ambiantColor.GetColor(p).Scale(1 - t).Add((mat2.ambiantColor.GetColor(p)).Scale(t)),
|
(mat1.ambiantColor.GetColor(p).Scale(1 - t)).Add((mat2.ambiantColor.GetColor(p)).Scale(t)),
|
||||||
mat1.diffuseColor.GetColor(p).Scale(1 - t).Add((mat2.diffuseColor.GetColor(p)).Scale(t)),
|
(mat1.diffuseColor.GetColor(p).Scale(1 - t)).Add((mat2.diffuseColor.GetColor(p)).Scale(t)),
|
||||||
(mat1.diffuseFac*(1-t) + mat2.diffuseFac) * t,
|
mat1.diffuseFac*(1-t) + mat2.diffuseFac*t,
|
||||||
mat1.specularColor.GetColor(p).Scale(1 - t).Add((mat2.specularColor.GetColor(p)).Scale(t)),
|
mat1.specularColor.GetColor(p).Scale(1 - t).Add((mat2.specularColor.GetColor(p)).Scale(t)),
|
||||||
(mat1.specularFac*(1-t) + mat2.specularFac) * t,
|
mat1.specularFac*(1-t) + mat2.specularFac*t,
|
||||||
(mat1.specularExp*(1-t) + mat2.specularExp) * t,
|
mat1.specularExp*(1-t) + mat2.specularExp*t,
|
||||||
(mat1.reflectanceFac*(1-t) + mat2.reflectanceFac) * t,
|
(mat1.reflectanceFac*(1-t) + mat2.reflectanceFac) * t,
|
||||||
mat1.reflectanceTint.GetColor(p).Scale(1 - t).Add((mat2.reflectanceTint.GetColor(p)).Scale(t)),
|
mat1.reflectanceTint.GetColor(p).Scale(1 - t).Add((mat2.reflectanceTint.GetColor(p)).Scale(t)),
|
||||||
(mat1.refractFac*(1-t) + mat2.refractFac) * t,
|
mat1.refractFac*(1-t) + mat2.refractFac*t,
|
||||||
(mat1.refractIndice*(1-t) + mat2.refractIndice) * t,
|
mat1.refractIndice*(1-t) + mat2.refractIndice*t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,17 @@ import (
|
||||||
const MAX_DIST = 1000.0
|
const MAX_DIST = 1000.0
|
||||||
const MAX_STEP = 1000
|
const MAX_STEP = 1000
|
||||||
const EPS = 0.01
|
const EPS = 0.01
|
||||||
const WIDTH = 500
|
const WIDTH = 250
|
||||||
const HEIGHT = 500
|
const HEIGHT = 250
|
||||||
const PI = math.Pi
|
const PI = math.Pi
|
||||||
|
|
||||||
var lightPos Vector3 = Vector3{0, -200, 600}
|
var lightPos Vector3 = Vector3{0, -200, 600}
|
||||||
var sphere Sphere = Sphere{Vector3{0, 100, 10}, 10, RED_MAT}
|
var sphere Sphere = Sphere{Vector3{0, 100, 5}, 10, RED_MAT}
|
||||||
var plane Plane = Plane{Vector3{0, 0, 1}, -10, GRID_OF_GRID_MAT}
|
var plane Plane = Plane{Vector3{0, 0, 1}, 0, WHITE_GREY_GRID_MAT}
|
||||||
var scene UnionSDF = UnionSDF{sphere, plane}
|
|
||||||
|
|
||||||
|
var scene SmoothUnionSDF = SmoothUnionSDF{sphere, plane, 3.5}
|
||||||
|
|
||||||
|
// var scene UnionSDF = UnionSDF{sphere, plane}
|
||||||
var cameraPos Vector3 = Vector3{0, -10, 30}
|
var cameraPos Vector3 = Vector3{0, -10, 30}
|
||||||
|
|
||||||
// radius, theta, phi
|
// radius, theta, phi
|
||||||
|
|
|
||||||
6
sdf.go
6
sdf.go
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "math"
|
import (
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
type SDF interface {
|
type SDF interface {
|
||||||
Distance(Vector3) (float64, Material)
|
Distance(Vector3) (float64, Material)
|
||||||
|
|
@ -121,7 +123,7 @@ func (s SmoothUnionSDF) Distance(p Vector3) (float64, Material) {
|
||||||
h := math.Max(k-math.Abs(d1-d2), 0.0)
|
h := math.Max(k-math.Abs(d1-d2), 0.0)
|
||||||
d := math.Min(d1, d2) - h*h*0.25/k
|
d := math.Min(d1, d2) - h*h*0.25/k
|
||||||
t := SmoothStep(d2-d1, -k, k)
|
t := SmoothStep(d2-d1, -k, k)
|
||||||
mat := MixMat(mat1, mat2, t, p)
|
mat := MixMat(mat2, mat1, t, p)
|
||||||
return d, mat
|
return d, mat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue