Grid
This commit is contained in:
parent
9e8028f904
commit
a7b5306fa9
2 changed files with 29 additions and 2 deletions
27
material.go
27
material.go
|
|
@ -1,9 +1,28 @@
|
|||
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))
|
||||
|
||||
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
|
||||
|
|
@ -56,6 +75,11 @@ 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)
|
||||
|
|
@ -63,3 +87,6 @@ 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)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ const HEIGHT = 500
|
|||
const PI = math.Pi
|
||||
|
||||
var lightPos Vector3 = Vector3{0, 200, 400}
|
||||
var sphere Sphere = Sphere{Vector3{0, 100, 10}, 10, RED_MAT}
|
||||
var plane Plane = Plane{Vector3{0, 0, 1}, -10, GREY_MAT}
|
||||
var sphere Sphere = Sphere{Vector3{0, 100, 10}, 10, WHITE_GREY_GRID_MAT}
|
||||
var plane Plane = Plane{Vector3{0, 0, 1}, -10, GRID_OF_GRID_MAT}
|
||||
var scene UnionSDF = UnionSDF{sphere, plane}
|
||||
|
||||
var cameraPos Vector3 = Vector3{0, -10, 0}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue