Materials
This commit is contained in:
parent
c0c129db88
commit
f5d4a5cb7e
5 changed files with 113 additions and 106 deletions
62
material.go
Normal file
62
material.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
type Color interface {
|
||||
GetColor(Vector3) Vector3
|
||||
}
|
||||
|
||||
// Ambre je te copie
|
||||
type Material struct {
|
||||
diffuseColor Color
|
||||
diffuseFac float64
|
||||
specularColor Color
|
||||
specularFac float64
|
||||
specularExp float64
|
||||
reflectanceFac float64
|
||||
reflectanceTint Color
|
||||
refractFac float64
|
||||
refractIndice float64
|
||||
}
|
||||
|
||||
func DefaultMaterial(diffuseColor Color) Material {
|
||||
return Material{
|
||||
diffuseColor: diffuseColor,
|
||||
diffuseFac: 1.0,
|
||||
specularColor: Vector3{1.0, 1.0, 1.0},
|
||||
specularFac: 0.5,
|
||||
specularExp: 32.0,
|
||||
reflectanceFac: 0.0,
|
||||
reflectanceTint: Vector3{1.0, 1.0, 1.0},
|
||||
refractFac: 0.0,
|
||||
refractIndice: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
||||
return Material{
|
||||
mat1.diffuseColor.GetColor(p).Scale(1 - t).Add((mat2.diffuseColor.GetColor(p)).Scale(t)),
|
||||
(mat1.diffuseFac*(1-t) + mat2.diffuseFac) * t,
|
||||
mat1.specularColor.GetColor(p).Scale(1 - t).Add((mat2.specularColor.GetColor(p)).Scale(t)),
|
||||
(mat1.specularFac*(1-t) + mat2.specularFac) * t,
|
||||
(mat1.specularExp*(1-t) + mat2.specularExp) * t,
|
||||
(mat1.reflectanceFac*(1-t) + mat2.reflectanceFac) * t,
|
||||
mat1.reflectanceTint.GetColor(p).Scale(1 - t).Add((mat2.reflectanceTint.GetColor(p)).Scale(t)),
|
||||
(mat1.refractFac*(1-t) + mat2.refractFac) * t,
|
||||
(mat1.refractIndice*(1-t) + mat2.refractIndice) * t,
|
||||
}
|
||||
}
|
||||
|
||||
// Colors
|
||||
|
||||
var RED = Vector3{255, 0, 0}
|
||||
var GREEN = Vector3{0, 255, 0}
|
||||
var BLUE = Vector3{0, 0, 255}
|
||||
var WHITE = Vector3{255, 255, 255}
|
||||
var GREY = Vector3{127, 127, 127}
|
||||
|
||||
// Materials
|
||||
|
||||
var RED_MAT = DefaultMaterial(RED)
|
||||
var GREEN_MAT = DefaultMaterial(GREEN)
|
||||
var BLUE_MAT = DefaultMaterial(BLUE)
|
||||
var WHITE_MAT = DefaultMaterial(WHITE)
|
||||
var GREY_MAT = DefaultMaterial(GREY)
|
||||
Loading…
Add table
Add a link
Reference in a new issue