-
Notifications
You must be signed in to change notification settings - Fork 18
/
world.go
89 lines (73 loc) · 3.18 KB
/
world.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tetra3d
const (
FogAdd = iota // Additive blended fog
FogSub // Subtractive blended fog
FogOverwrite // Color overwriting fog (mixing base with fog color over depth distance)
FogTransparent // Fog influences transparency of the render
)
const (
FogCurveLinear = iota
FogCurveOutCirc
FogCurveInCirc
// FogCurveInOutCirc //easeInOutCirc
// FogCurveInOutBounce //easeInOutBounce
)
type FogMode int
// World represents a collection of settings that one uses to control lighting and ambience. This includes the screen clear color, fog color,
// mode, and range, whether lighting is globally enabled or not, and finally the ambient lighting level (using the World's AmbientLight).
type World struct {
Name string
ClearColor Color // The clear color of the screen; note that this doesn't clear the color of the camera buffer or screen automatically;
// this is just what the color is if the scene was exported using the Tetra3D addon from Blender. It's up to you as to how you'd like to
// use it.
FogColor Color // The Color of any fog present in the Scene.
FogMode FogMode // The FogMode, indicating how the fog color is blended if it's on (not FogOff).
// FogRange is the depth range at which the fog is active. FogRange consists of two numbers,
// ranging from 0 to 1. The first indicates the start of the fog, and the second the end, in
// terms of total depth of the near / far clipping plane. The default is [0, 1].
FogOn bool
DitheredFogSize float32 // If greater than zero, how large the dithering effect is for transparent fog. If <= 0, dithering is disabled.
FogRange []float32 // The distances at which the fog is at 0% and 100%, respectively.
FogCurve int
LightingOn bool // If lighting is enabled when rendering the scene.
AmbientLight *AmbientLight // Ambient lighting for this world
}
// NewWorld creates a new World with the specified name and default values for fog, lighting, etc).
func NewWorld(name string) *World {
return &World{
Name: name,
FogColor: NewColor(0, 0, 0, 0),
FogRange: []float32{0, 1},
FogOn: true,
LightingOn: true,
DitheredFogSize: 0,
ClearColor: NewColor(0.08, 0.09, 0.1, 1),
AmbientLight: NewAmbientLight("ambient light", 1, 1, 1, 0),
}
}
// Clone returns a new World with the same properties as the existing World.
func (world *World) Clone() *World {
newWorld := NewWorld(world.Name)
newWorld.ClearColor = world.ClearColor
newWorld.FogColor = world.FogColor
newWorld.FogMode = world.FogMode
newWorld.FogRange[0] = world.FogRange[0]
newWorld.FogRange[1] = world.FogRange[1]
newWorld.LightingOn = world.LightingOn
newWorld.FogCurve = world.FogCurve
newWorld.AmbientLight = world.AmbientLight.Clone().(*AmbientLight)
newWorld.DitheredFogSize = world.DitheredFogSize
return newWorld
}
func (world *World) fogAsFloatSlice() []float32 {
fog := []float32{
float32(world.FogColor.R),
float32(world.FogColor.G),
float32(world.FogColor.B),
float32(world.FogMode),
}
if !world.FogOn {
fog[3] = -1
}
return fog
}