/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/RendererCore/Lights/DirectionalLightComponent.h
105 строк
5 KB
Sanakan8472
Area Lights (#1908)
20 апр 2026, 20:27
Не верифицирован
20 апр 2026, 20:27
bdf6e41
Код
Авторство
О чём код?
#pragma once #include <RendererCore/Lights/LightComponent.h> #include <RendererCore/Textures/Texture2DResource.h> using ezDirectionalLightComponentManager = ezComponentManager<class ezDirectionalLightComponent, ezBlockStorageType::Compact>; /// \brief The render data object for directional lights. class EZ_RENDERERCORE_DLL ezDirectionalLightRenderData : public ezLightRenderData { EZ_ADD_DYNAMIC_REFLECTION(ezDirectionalLightRenderData, ezLightRenderData); public: ezVec3 m_vDirection; bool m_bScreenSpaceShadows; }; /// \brief A directional lightsource shines light into one fixed direction and has infinite size. It is usually used for sunlight. /// /// It is very rare to use more than one directional lightsource at the same time. /// Directional lightsources are used to fake the large scale light of the sun (or moon). /// They use cascaded shadow maps to reduce the performance overhead for dynamic shadows of such large lights. class EZ_RENDERERCORE_DLL ezDirectionalLightComponent : public ezLightComponent { EZ_DECLARE_COMPONENT_TYPE(ezDirectionalLightComponent, ezLightComponent, ezDirectionalLightComponentManager); ////////////////////////////////////////////////////////////////////////// // ezComponent public: virtual void SerializeComponent(ezWorldWriter& inout_stream) const override; virtual void DeserializeComponent(ezWorldReader& inout_stream) override; ////////////////////////////////////////////////////////////////////////// // ezRenderComponent public: virtual ezResult GetLocalBounds(ezBoundingBoxSphere& ref_bounds, bool& ref_bAlwaysVisible, ezMsgUpdateLocalBounds& ref_msg) override; ////////////////////////////////////////////////////////////////////////// // ezDirectionalLightComponent public: ezDirectionalLightComponent(); ~ezDirectionalLightComponent(); /// \brief Sets whether to use screen space shadows. Improves contact shadows and self-shadowing for small objects. void SetScreenSpaceShadows(bool bShadows); // [ property ] bool GetScreenSpaceShadows() const; // [ property ] /// Angular diameter of the emitter disc (the "sun disc") as seen from the ground. /// /// A non-zero value produces softer specular highlights via representative-point shading. Has no effect on attenuation since directional lights are treated as infinitely far away. /// Reference values: sun ≈ 0.53°, full moon ≈ 0.52°. Values above a few degrees are physically implausible but may be used for stylised looks. void SetSourceAngle(ezAngle sourceAngle); // [ property ] ezAngle GetSourceAngle() const; // [ property ] /// \brief Sets how many shadow map cascades to use. Typically between 2 and 4. void SetNumCascades(ezUInt32 uiNumCascades); // [ property ] ezUInt32 GetNumCascades() const; // [ property ] /// \brief Sets the distance around the main camera in which to apply dynamic shadows. void SetMinShadowRange(float fMinShadowRange); // [ property ] float GetMinShadowRange() const; // [ property ] /// \brief The factor (0 to 1) at which relative distance to start fading out the shadow map. Typically 0.8 or 0.9. void SetFadeOutStart(float fFadeOutStart); // [ property ] float GetFadeOutStart() const; // [ property ] /// \brief Has something to do with shadow map cascades (TODO: figure out what). void SetSplitModeWeight(float fSplitModeWeight); // [ property ] float GetSplitModeWeight() const; // [ property ] /// \brief Has something to do with shadow map cascades (TODO: figure out what). void SetNearPlaneOffset(float fNearPlaneOffset); // [ property ] float GetNearPlaneOffset() const; // [ property ] protected: void OnMsgExtractRenderData(ezMsgExtractRenderData& msg) const; bool m_bScreenSpaceShadows = false; ezAngle m_SourceAngle = ezAngle::MakeFromDegree(0.0f); ezUInt32 m_uiNumCascades = 3; float m_fMinShadowRange = 50.0f; float m_fFadeOutStart = 0.8f; float m_fSplitModeWeight = 0.7f; float m_fNearPlaneOffset = 100.0f; }; /// Visualizer attribute for the angular size (source angle) of a directional light. /// /// Shows a sphere as an intuitive size reference; its world-space size is proportional to the configured angle. class EZ_RENDERERCORE_DLL ezDirectionalLightVisualizerAttribute : public ezVisualizerAttribute { EZ_ADD_DYNAMIC_REFLECTION(ezDirectionalLightVisualizerAttribute, ezVisualizerAttribute); public: ezDirectionalLightVisualizerAttribute(); ezDirectionalLightVisualizerAttribute(const char* szAngleProperty, const char* szColorProperty); const ezUntrackedString& GetAngleProperty() const { return m_sProperty1; } const ezUntrackedString& GetColorProperty() const { return m_sProperty2; } };