/
ambient.go
64 lines (49 loc) 路 1.05 KB
/
ambient.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
// Copyright 2021 Changkun Ou <changkun.de>. All rights reserved.
// Use of this source code is governed by a GPLv3 license that
// can be found in the LICENSE file.
package light
import (
"image/color"
"changkun.de/x/polyred/math"
"changkun.de/x/polyred/object"
)
var (
_ Environment = &Ambient{}
_ object.Object = &Ambient{}
)
type Ambient struct {
math.TransformContext // not used
color color.RGBA
intensity float64
}
type AmbientOption func(a *Ambient)
func WithAmbientIntensity(I float64) AmbientOption {
return func(a *Ambient) {
a.intensity = I
}
}
func WithAmbientColor(c color.RGBA) AmbientOption {
return func(a *Ambient) {
a.color = c
}
}
func NewAmbient(opts ...AmbientOption) *Ambient {
a := &Ambient{
intensity: 0.1,
color: color.RGBA{0xff, 0xff, 0xff, 0xff},
}
for _, opt := range opts {
opt(a)
}
a.ResetContext()
return a
}
func (l *Ambient) Type() object.Type {
return object.TypeLight
}
func (a *Ambient) Color() color.RGBA {
return a.color
}
func (a *Ambient) Intensity() float64 {
return a.intensity
}