ambient.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package light
  5. import (
  6. "github.com/g3n/engine/core"
  7. "github.com/g3n/engine/gls"
  8. "github.com/g3n/engine/math32"
  9. )
  10. type Ambient struct {
  11. core.Node // Embedded node
  12. color math32.Color // Light color
  13. intensity float32 // Light intensity
  14. uColor gls.Uniform3f // Light color uniform (color * intensity)
  15. }
  16. // NewAmbient returns a pointer to a new ambient color with the specified
  17. // color and intensity
  18. func NewAmbient(color *math32.Color, intensity float32) *Ambient {
  19. la := new(Ambient)
  20. la.Node.Init()
  21. la.color = *color
  22. la.intensity = intensity
  23. la.uColor.Init("AmbientLightColor")
  24. la.SetColor(color)
  25. return la
  26. }
  27. // SetColor sets the color of this light
  28. func (la *Ambient) SetColor(color *math32.Color) {
  29. la.color = *color
  30. tmpColor := la.color
  31. tmpColor.MultiplyScalar(la.intensity)
  32. la.uColor.SetColor(&tmpColor)
  33. }
  34. // Color returns the current color of this light
  35. func (la *Ambient) Color() math32.Color {
  36. return la.color
  37. }
  38. // SetIntensity sets the intensity of this light
  39. func (la *Ambient) SetIntensity(intensity float32) {
  40. la.intensity = intensity
  41. tmpColor := la.color
  42. tmpColor.MultiplyScalar(la.intensity)
  43. la.uColor.SetColor(&tmpColor)
  44. }
  45. // Intensity returns the current intensity of this light
  46. func (la *Ambient) Intensity() float32 {
  47. return la.intensity
  48. }
  49. // RenderSetup is called by the engine before rendering the scene
  50. func (la *Ambient) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
  51. la.uColor.TransferIdx(gs, idx)
  52. }