Sdf return *Material change, 2x perf boost
This commit is contained in:
parent
264a759ac5
commit
71c86e3570
4 changed files with 72 additions and 53 deletions
|
|
@ -31,8 +31,11 @@ func (grid GridColor) GetColor(p Vector3) Vector3 {
|
|||
return grid.color2.GetColor(p)
|
||||
}
|
||||
|
||||
// Ambre je te copie
|
||||
type Material struct {
|
||||
type Material interface {
|
||||
GetMaterialBrut() MaterialBrut
|
||||
}
|
||||
|
||||
type MaterialBrut struct {
|
||||
ambiantColor Color
|
||||
diffuseColor Color
|
||||
diffuseFac float64
|
||||
|
|
@ -45,23 +48,12 @@ type Material struct {
|
|||
refractIndice float64
|
||||
}
|
||||
|
||||
func DefaultMaterial(diffuseColor Color) Material {
|
||||
return Material{
|
||||
ambiantColor: ScaledColor{diffuseColor, 0.2},
|
||||
diffuseColor: diffuseColor,
|
||||
diffuseFac: 1,
|
||||
specularColor: Vector3{255, 255, 255},
|
||||
specularFac: 1,
|
||||
specularExp: 35.0,
|
||||
reflectanceFac: 0.0,
|
||||
reflectanceTint: Vector3{255, 255, 255},
|
||||
refractFac: 0.0,
|
||||
refractIndice: 1.0,
|
||||
}
|
||||
func (mat MaterialBrut) GetMaterialBrut() MaterialBrut {
|
||||
return mat
|
||||
}
|
||||
|
||||
func MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
||||
return Material{
|
||||
func MixMat(mat1 MaterialBrut, mat2 MaterialBrut, t float64, p Vector3) MaterialBrut {
|
||||
return MaterialBrut{
|
||||
(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.diffuseFac*(1-t) + mat2.diffuseFac*t,
|
||||
|
|
@ -75,6 +67,32 @@ func MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
|||
}
|
||||
}
|
||||
|
||||
type MixedMaterial struct {
|
||||
mat1 *Material
|
||||
mat2 *Material
|
||||
t float64
|
||||
p Vector3
|
||||
}
|
||||
|
||||
func (mixedMat MixedMaterial) GetMaterialBrut() MaterialBrut {
|
||||
return MixMat((*mixedMat.mat1).GetMaterialBrut(), (*mixedMat.mat2).GetMaterialBrut(), mixedMat.t, mixedMat.p)
|
||||
}
|
||||
|
||||
func DefaultMaterial(diffuseColor Color) MaterialBrut {
|
||||
return MaterialBrut{
|
||||
ambiantColor: ScaledColor{diffuseColor, 0.2},
|
||||
diffuseColor: diffuseColor,
|
||||
diffuseFac: 1,
|
||||
specularColor: Vector3{255, 255, 255},
|
||||
specularFac: 1,
|
||||
specularExp: 35.0,
|
||||
reflectanceFac: 0.0,
|
||||
reflectanceTint: Vector3{255, 255, 255},
|
||||
refractFac: 0.0,
|
||||
refractIndice: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
// Colors
|
||||
|
||||
var RED = Vector3{255, 0, 0}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue