Light.pkg 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. $#include "Light.h"
  2. /// %Light types.
  3. enum LightType
  4. {
  5. LIGHT_DIRECTIONAL = 0,
  6. LIGHT_SPOT,
  7. LIGHT_POINT
  8. };
  9. /// Shadow depth bias parameters.
  10. struct BiasParameters
  11. {
  12. /// Construct undefined.
  13. BiasParameters()
  14. {
  15. }
  16. /// Construct with initial values.
  17. BiasParameters(float constantBias, float slopeScaledBias) :
  18. constantBias_(constantBias),
  19. slopeScaledBias_(slopeScaledBias)
  20. {
  21. }
  22. };
  23. /// Cascaded shadow map parameters.
  24. struct CascadeParameters
  25. {
  26. /// Construct undefined.
  27. CascadeParameters()
  28. {
  29. }
  30. /// Construct with initial values.
  31. CascadeParameters(float split1, float split2, float split3, float split4, float fadeStart, float biasAutoAdjust = 1.0f) :
  32. fadeStart_(fadeStart),
  33. biasAutoAdjust_(biasAutoAdjust)
  34. {
  35. splits_[0] = split1;
  36. splits_[1] = split2;
  37. splits_[2] = split3;
  38. splits_[3] = split4;
  39. }
  40. };
  41. /// Shadow map focusing parameters.
  42. struct FocusParameters
  43. {
  44. /// Construct undefined.
  45. FocusParameters()
  46. {
  47. }
  48. /// Construct with initial values.
  49. FocusParameters(bool focus, bool nonUniform, bool autoSize, float quantize, float minView) :
  50. focus_(focus),
  51. nonUniform_(nonUniform),
  52. autoSize_(autoSize),
  53. quantize_(quantize),
  54. minView_(minView)
  55. {
  56. }
  57. };
  58. /// %Light component.
  59. class Light : public Drawable
  60. {
  61. public:
  62. /// Set light type.
  63. void SetLightType(LightType type);
  64. /// Set vertex lighting mode.
  65. void SetPerVertex(bool enable);
  66. /// Set color.
  67. void SetColor(const Color& color);
  68. /// Set specular intensity.
  69. void SetSpecularIntensity(float intensity);
  70. /// Set range.
  71. void SetRange(float range);
  72. /// Set spotlight field of view.
  73. void SetFov(float fov);
  74. /// Set spotlight aspect ratio.
  75. void SetAspectRatio(float aspectRatio);
  76. /// Set fade out start distance.
  77. void SetFadeDistance(float distance);
  78. /// Set shadow fade out start distance. Only has effect if shadow distance is also non-zero.
  79. void SetShadowFadeDistance(float distance);
  80. /// Set shadow depth bias parameters.
  81. void SetShadowBias(const BiasParameters& parameters);
  82. /// Set directional light cascaded shadow parameters.
  83. void SetShadowCascade(const CascadeParameters& parameters);
  84. /// Set shadow map focusing parameters.
  85. void SetShadowFocus(const FocusParameters& parameters);
  86. /// Set shadow intensity between 0.0 - 1.0. 0.0 (the default) gives fully dark shadows.
  87. void SetShadowIntensity(float intensity);
  88. /// Set shadow resolution between 0.25 - 1.0. Determines the shadow map to use.
  89. void SetShadowResolution(float resolution);
  90. /// Set shadow camera near/far clip distance ratio.
  91. void SetShadowNearFarRatio(float nearFarRatio);
  92. /// Set range attenuation texture.
  93. void SetRampTexture(Texture* texture);
  94. /// Set spotlight attenuation texture.
  95. void SetShapeTexture(Texture* texture);
  96. /// Return light type.
  97. LightType GetLightType() const { return lightType_; }
  98. /// Return vertex lighting mode.
  99. bool GetPerVertex() const { return perVertex_; }
  100. /// Return color.
  101. const Color& GetColor() const { return color_; }
  102. /// Return specular intensity.
  103. float GetSpecularIntensity() const { return specularIntensity_; }
  104. /// Return range.
  105. float GetRange() const { return range_; }
  106. /// Return spotlight field of view.
  107. float GetFov() const { return fov_; }
  108. /// Return spotlight aspect ratio.
  109. float GetAspectRatio() const { return aspectRatio_; }
  110. /// Return fade start distance.
  111. float GetFadeDistance() const { return fadeDistance_; }
  112. /// Return shadow fade start distance.
  113. float GetShadowFadeDistance() const { return shadowFadeDistance_; }
  114. /// Return shadow depth bias parameters.
  115. const BiasParameters& GetShadowBias() const { return shadowBias_; }
  116. /// Return directional light cascaded shadow parameters.
  117. const CascadeParameters& GetShadowCascade() const { return shadowCascade_; }
  118. /// Return shadow map focus parameters.
  119. const FocusParameters& GetShadowFocus() const { return shadowFocus_; }
  120. /// Return shadow intensity.
  121. float GetShadowIntensity() const { return shadowIntensity_; }
  122. /// Return shadow resolution.
  123. float GetShadowResolution() const { return shadowResolution_; }
  124. /// Return shadow camera near/far clip distance ratio.
  125. float GetShadowNearFarRatio() const { return shadowNearFarRatio_; }
  126. /// Return range attenuation texture.
  127. Texture* GetRampTexture() const { return rampTexture_; }
  128. /// Return spotlight attenuation texture.
  129. Texture* GetShapeTexture() const { return shapeTexture_; }
  130. /// Return spotlight frustum.
  131. Frustum GetFrustum() const;
  132. };