clean up
This commit is contained in:
parent
f5c912c489
commit
a7f8b46910
8 changed files with 28 additions and 52 deletions
92
src/material.go
Normal file
92
src/material.go
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package main
|
||||
|
||||
import "math"
|
||||
|
||||
type Color interface {
|
||||
GetColor(Vector3) Vector3
|
||||
}
|
||||
|
||||
type GridColor struct {
|
||||
color1 Color
|
||||
color2 Color
|
||||
size float64
|
||||
}
|
||||
|
||||
func (grid GridColor) GetColor(p Vector3) Vector3 {
|
||||
ix := int(math.Floor(p.X / grid.size))
|
||||
iy := int(math.Floor(p.Y / grid.size))
|
||||
iz := int(math.Floor(p.Z/grid.size)) * 0
|
||||
|
||||
if (ix+iy+iz)%2 == 0 {
|
||||
return grid.color1.GetColor(p)
|
||||
}
|
||||
return grid.color2.GetColor(p)
|
||||
}
|
||||
|
||||
// Ambre je te copie
|
||||
type Material struct {
|
||||
ambiantColor Color
|
||||
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{
|
||||
ambiantColor: Vector3{0, 0, 0},
|
||||
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 MixMat(mat1 Material, mat2 Material, t float64, p Vector3) Material {
|
||||
return Material{
|
||||
(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,
|
||||
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}
|
||||
|
||||
var WHITE_GREY_GRID = GridColor{WHITE, GREY, 5}
|
||||
var RED_BLUE_GRID = GridColor{RED, BLUE, 5}
|
||||
|
||||
var GRID_OF_GRID = GridColor{WHITE_GREY_GRID, RED_BLUE_GRID, 10}
|
||||
|
||||
// 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)
|
||||
|
||||
var WHITE_GREY_GRID_MAT = DefaultMaterial(WHITE_GREY_GRID)
|
||||
var GRID_OF_GRID_MAT = DefaultMaterial(GRID_OF_GRID)
|
||||
Loading…
Add table
Add a link
Reference in a new issue