💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.5 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP
  20. #define ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP
  21. #include "scene/light.hpp"
  22. #include "gl/texture-2d.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. namespace scene {
  25. /**
  26. * Light source with parallel rays and constant intensity.
  27. */
  28. class directional_light: public light
  29. {
  30. public:
  31. /// Creates a directional light.
  32. directional_light();
  33. /**
  34. * Sets the light texture, also known as a gobo, cucoloris, or cookie.
  35. *
  36. * @param texture Light texture.
  37. */
  38. void set_light_texture(const gl::texture_2d* texture);
  39. /**
  40. * Sets the opacity of the light texture.
  41. *
  42. * @param opacity Light texture opacity, on `[0, 1]`.
  43. */
  44. void set_light_texture_opacity(float opacity);
  45. /**
  46. * Sets the scale of the light texture.
  47. *
  48. * @param scale Scale of the light texture.
  49. */
  50. void set_light_texture_scale(const float2& scale);
  51. /// Returns light_type::directional.
  52. virtual light_type get_light_type() const;
  53. /// Returns the normalized direction vector of the light.
  54. const float3& get_direction() const;
  55. /// Returns the light texture for this light, or `nullptr` if no light texture is set.
  56. const gl::texture_2d* get_light_texture() const;
  57. /// Returns the light texture opacity.
  58. float get_light_texture_opacity() const;
  59. /// Returns the light texture scale.
  60. const float2& get_light_texture_scale() const;
  61. /// Returns the light direction tween.
  62. const tween<float3>& get_direction_tween() const;
  63. /// Returns the light texture opacity tween.
  64. const tween<float>& get_light_texture_opacity_tween() const;
  65. /// Returns the light texture scale tween.
  66. const tween<float2>& get_light_texture_scale_tween() const;
  67. /// @copydoc object_base::update_tweens();
  68. virtual void update_tweens();
  69. private:
  70. virtual void transformed();
  71. tween<float3> direction;
  72. const gl::texture_2d* light_texture;
  73. tween<float> light_texture_opacity;
  74. tween<float2> light_texture_scale;
  75. };
  76. inline light_type directional_light::get_light_type() const
  77. {
  78. return light_type::directional;
  79. }
  80. inline const float3& directional_light::get_direction() const
  81. {
  82. return direction[1];
  83. }
  84. inline const gl::texture_2d* directional_light::get_light_texture() const
  85. {
  86. return light_texture;
  87. }
  88. inline float directional_light::get_light_texture_opacity() const
  89. {
  90. return light_texture_opacity[1];
  91. }
  92. inline const float2& directional_light::get_light_texture_scale() const
  93. {
  94. return light_texture_scale[1];
  95. }
  96. inline const tween<float3>& directional_light::get_direction_tween() const
  97. {
  98. return direction;
  99. }
  100. inline const tween<float>& directional_light::get_light_texture_opacity_tween() const
  101. {
  102. return light_texture_opacity;
  103. }
  104. inline const tween<float2>& directional_light::get_light_texture_scale_tween() const
  105. {
  106. return light_texture_scale;
  107. }
  108. } // namespace scene
  109. #endif // ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP