| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // Copyright 2016 The G3N Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- package light
- import (
- "github.com/g3n/engine/core"
- "github.com/g3n/engine/gls"
- "github.com/g3n/engine/math32"
- )
- type Ambient struct {
- core.Node // Embedded node
- color math32.Color // Light color
- intensity float32 // Light intensity
- uColor gls.Uniform3f // Light color uniform (color * intensity)
- }
- // NewAmbient returns a pointer to a new ambient color with the specified
- // color and intensity
- func NewAmbient(color *math32.Color, intensity float32) *Ambient {
- la := new(Ambient)
- la.Node.Init()
- la.color = *color
- la.intensity = intensity
- la.uColor.Init("AmbientLightColor")
- la.SetColor(color)
- return la
- }
- // SetColor sets the color of this light
- func (la *Ambient) SetColor(color *math32.Color) {
- la.color = *color
- tmpColor := la.color
- tmpColor.MultiplyScalar(la.intensity)
- la.uColor.SetColor(&tmpColor)
- }
- // Color returns the current color of this light
- func (la *Ambient) Color() math32.Color {
- return la.color
- }
- // SetIntensity sets the intensity of this light
- func (la *Ambient) SetIntensity(intensity float32) {
- la.intensity = intensity
- tmpColor := la.color
- tmpColor.MultiplyScalar(la.intensity)
- la.uColor.SetColor(&tmpColor)
- }
- // Intensity returns the current intensity of this light
- func (la *Ambient) Intensity() float32 {
- return la.intensity
- }
- // RenderSetup is called by the engine before rendering the scene
- func (la *Ambient) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
- la.uColor.TransferIdx(gs, idx)
- }
|