ambient.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. uni gls.Uniform2 // Uniform location cache
  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.uni.Init("AmbientLightColor")
  24. return la
  25. }
  26. // SetColor sets the color of this light
  27. func (la *Ambient) SetColor(color *math32.Color) {
  28. la.color = *color
  29. }
  30. // Color returns the current color of this light
  31. func (la *Ambient) Color() math32.Color {
  32. return la.color
  33. }
  34. // SetIntensity sets the intensity of this light
  35. func (la *Ambient) SetIntensity(intensity float32) {
  36. la.intensity = intensity
  37. }
  38. // Intensity returns the current intensity of this light
  39. func (la *Ambient) Intensity() float32 {
  40. return la.intensity
  41. }
  42. // RenderSetup is called by the engine before rendering the scene
  43. func (la *Ambient) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
  44. color := la.color
  45. color.MultiplyScalar(la.intensity)
  46. location := la.uni.LocationIdx(gs, int32(idx))
  47. gs.Uniform3f(location, color.R, color.G, color.B)
  48. }