point.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 material
  5. import (
  6. "github.com/g3n/engine/gls"
  7. "github.com/g3n/engine/math32"
  8. )
  9. type Point struct {
  10. Material // Embedded base material
  11. emissive gls.Uniform3f // point emissive uniform
  12. size gls.Uniform1f // point size uniform
  13. opacity gls.Uniform1f // point opacity uniform
  14. rotationZ gls.Uniform1f // point z rotation
  15. }
  16. // NewPoint creates and returns a pointer to a new point material
  17. func NewPoint(color *math32.Color) *Point {
  18. pm := new(Point)
  19. pm.Material.Init()
  20. pm.SetShader("shaderPoint")
  21. // Creates color uniform
  22. pm.emissive.Init("MatEmissiveColor")
  23. pm.emissive.SetColor(color)
  24. // Creates point size uniform
  25. pm.size.Init("PointSize")
  26. pm.size.Set(1.0)
  27. // Creates point opacity uniform
  28. pm.opacity.Init("MatOpacity")
  29. pm.opacity.Set(1.0)
  30. // Creates point rotation Z uniform
  31. pm.rotationZ.Init("RotationZ")
  32. pm.rotationZ.Set(0)
  33. return pm
  34. }
  35. // SetEmissiveColor sets the material emissive color
  36. // The default is {0,0,0}
  37. func (pm *Point) SetEmissiveColor(color *math32.Color) {
  38. pm.emissive.SetColor(color)
  39. }
  40. // EmissiveColor returns the material current emissive color
  41. func (pm *Point) EmissiveColor() math32.Color {
  42. return pm.emissive.GetColor()
  43. }
  44. func (pm *Point) SetSize(size float32) {
  45. pm.size.Set(size)
  46. }
  47. func (pm *Point) SetOpacity(opacity float32) {
  48. pm.opacity.Set(opacity)
  49. }
  50. func (pm *Point) SetRotationZ(rot float32) {
  51. pm.rotationZ.Set(rot)
  52. }
  53. func (pm *Point) RenderSetup(gs *gls.GLS) {
  54. pm.Material.RenderSetup(gs)
  55. pm.emissive.Transfer(gs)
  56. pm.size.Transfer(gs)
  57. pm.opacity.Transfer(gs)
  58. pm.rotationZ.Transfer(gs)
  59. }