2#include "glm/gtc/type_ptr.hpp"
3#include <engine/engine_export.h>
18#include <hpp/small_vector.hpp>
204 u_params0 = bgfx::createUniform(
"u_params0", bgfx::UniformType::Vec4);
205 u_params1 = bgfx::createUniform(
"u_params1", bgfx::UniformType::Vec4);
206 u_params2 = bgfx::createUniform(
"u_params2", bgfx::UniformType::Vec4);
207 u_color = bgfx::createUniform(
"u_color", bgfx::UniformType::Vec4);
208 u_smSamplingParams = bgfx::createUniform(
"u_smSamplingParams", bgfx::UniformType::Vec4);
209 u_csmFarDistances = bgfx::createUniform(
"u_csmFarDistances", bgfx::UniformType::Vec4);
210 u_lightMtx = bgfx::createUniform(
"u_lightMtx", bgfx::UniformType::Mat4);
212 u_tetraNormalGreen = bgfx::createUniform(
"u_tetraNormalGreen", bgfx::UniformType::Vec4);
213 u_tetraNormalYellow = bgfx::createUniform(
"u_tetraNormalYellow", bgfx::UniformType::Vec4);
214 u_tetraNormalBlue = bgfx::createUniform(
"u_tetraNormalBlue", bgfx::UniformType::Vec4);
215 u_tetraNormalRed = bgfx::createUniform(
"u_tetraNormalRed", bgfx::UniformType::Vec4);
217 u_shadowMapMtx0 = bgfx::createUniform(
"u_shadowMapMtx0", bgfx::UniformType::Mat4);
218 u_shadowMapMtx1 = bgfx::createUniform(
"u_shadowMapMtx1", bgfx::UniformType::Mat4);
219 u_shadowMapMtx2 = bgfx::createUniform(
"u_shadowMapMtx2", bgfx::UniformType::Mat4);
220 u_shadowMapMtx3 = bgfx::createUniform(
"u_shadowMapMtx3", bgfx::UniformType::Mat4);
222 u_shadowCutoutBaseColor = bgfx::createUniform(
"u_base_color", bgfx::UniformType::Vec4);
223 u_shadowCutoutSurfaceData = bgfx::createUniform(
"u_surface_data", bgfx::UniformType::Vec4);
224 u_shadowCutoutTiling = bgfx::createUniform(
"u_tiling", bgfx::UniformType::Vec4);
225 s_shadowCutoutColor = bgfx::createUniform(
"s_tex_color", bgfx::UniformType::Sampler);
231 float* _shadowMapMtx0,
232 float* _shadowMapMtx1,
233 float* _shadowMapMtx2,
234 float* _shadowMapMtx3)
283 bgfx::setTexture(0, s_shadowCutoutColor, cutout.
color_map->native_handle());
285 bgfx::setUniform(u_shadowCutoutBaseColor, math::value_ptr(cutout.
base_color.
value));
287 bgfx::setUniform(u_shadowCutoutSurfaceData, math::value_ptr(surface_data));
288 const math::vec4 tiling{cutout.
tiling.x, cutout.
tiling.y, 0.0f, 0.0f};
289 bgfx::setUniform(u_shadowCutoutTiling, math::value_ptr(tiling));
294 auto safe_destroy = [](bgfx::UniformHandle&
handle)
299 handle = {bgfx::kInvalidHandle};
302 safe_destroy(u_params0);
303 safe_destroy(u_params1);
304 safe_destroy(u_params2);
305 safe_destroy(u_color);
306 safe_destroy(u_smSamplingParams);
307 safe_destroy(u_csmFarDistances);
309 safe_destroy(u_tetraNormalGreen);
310 safe_destroy(u_tetraNormalYellow);
311 safe_destroy(u_tetraNormalBlue);
312 safe_destroy(u_tetraNormalRed);
314 safe_destroy(u_shadowMapMtx0);
315 safe_destroy(u_shadowMapMtx1);
316 safe_destroy(u_shadowMapMtx2);
317 safe_destroy(u_shadowMapMtx3);
319 safe_destroy(u_shadowCutoutBaseColor);
320 safe_destroy(u_shadowCutoutSurfaceData);
321 safe_destroy(u_shadowCutoutTiling);
322 safe_destroy(s_shadowCutoutColor);
324 safe_destroy(u_lightMtx);
394 bgfx::UniformHandle u_params0;
395 bgfx::UniformHandle u_params1;
396 bgfx::UniformHandle u_params2;
397 bgfx::UniformHandle u_color;
398 bgfx::UniformHandle u_smSamplingParams;
399 bgfx::UniformHandle u_csmFarDistances;
401 bgfx::UniformHandle u_tetraNormalGreen;
402 bgfx::UniformHandle u_tetraNormalYellow;
403 bgfx::UniformHandle u_tetraNormalBlue;
404 bgfx::UniformHandle u_tetraNormalRed;
406 bgfx::UniformHandle u_shadowMapMtx0;
407 bgfx::UniformHandle u_shadowMapMtx1;
408 bgfx::UniformHandle u_shadowMapMtx2;
409 bgfx::UniformHandle u_shadowMapMtx3;
411 bgfx::UniformHandle u_shadowCutoutBaseColor;
412 bgfx::UniformHandle u_shadowCutoutSurfaceData;
413 bgfx::UniformHandle u_shadowCutoutTiling;
414 bgfx::UniformHandle s_shadowCutoutColor;
416 bgfx::UniformHandle u_lightMtx;
453 .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
454 .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8,
true)
455 .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
467 decl.begin().add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float).end();
527#define SHADOW_FLOAT_PARAM(_name) \
528 float _name{}, _name##Min{}, _name##Max{}, _name##Step \
547#undef SHADOW_FLOAT_PARAM
572 ClearValues(uint32_t _clearRgba = 0x30303000,
float _clearDepth = 1.0f, uint8_t _clearStencil = 0)
707 auto render_scene_into_shadowmap(uint8_t shadowmap_1_id,
724 Light directional_light_;
726 float light_mtx_[16];
732 uint16_t current_shadow_map_size_{};
733 uint8_t current_num_splits_{};
743 bgfx::UniformHandle tex_color_{bgfx::kInvalidHandle};
746 bgfx::FrameBufferHandle rt_blur_{bgfx::kInvalidHandle};
750 uint64_t last_update_ = -1;
753 std::vector<shadow_batch_collector> cascade_batch_collectors_;
755 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
762 adaptive_shadow_params adaptive_params_;
Storage for frustum planes / values and wraps up common functionality.
Class representing a camera. Contains functionality for manipulating and updating a camera....
Class representing a GPU program.
std::shared_ptr< gpu_program > ptr
Structure describing a LOD group (set of meshes), LOD transitions, and their materials.
Shadow mapping generator with improved algorithms for high-altitude cameras.
void set_adaptive_params(const adaptive_shadow_params ¶ms)
auto get_csm_optimization_flags() const -> uint32_t
auto get_frustum_calculation_method() const -> frustum_calculation_method::Enum
auto get_adaptive_params() const -> const adaptive_shadow_params &
auto get_min_altitude_boost() const -> float
auto get_depth_type() const -> PackDepth::Enum
void submit_uniforms(uint8_t stage) const
auto get_rt_texture(uint8_t split) const -> bgfx::TextureHandle
auto get_max_altitude_boost() const -> float
void set_altitude_boost_range(float min_boost, float max_boost)
void update(const camera &cam, const light &l, const math::transform <rans, bool is_active)
void generate_shadowmaps(const shadow_map_models_t &model, const camera &cam, ::unravel::rendering::pipeline_stats *stats=nullptr)
void init(rtti::context &ctx)
void set_csm_optimization_flags(uint32_t flags)
auto already_updated() const -> bool
void set_altitude_scale_factor(float factor)
auto get_depth_render_program(PackDepth::Enum depth) const -> gpu_program::ptr
void set_frustum_calculation_method(frustum_calculation_method::Enum method)
auto get_altitude_scale_factor() const -> float
void enable_adaptive_shadows(bool enable)
bgfx::VertexLayout vertex_layout
hpp::small_vector< shadow_visibility_data > shadow_map_models_t
Struct representing a light.
Contains level of detail (LOD) data for an entity per view. Uses distance-based hysteresis for stable...
ClearValues(uint32_t _clearRgba=0x30303000, float _clearDepth=1.0f, uint8_t _clearStencil=0)
SpotDirectionInner m_spotDirectionInner
static void init(gfx::vertex_layout &decl)
static void init(gfx::vertex_layout &decl)
gpu_program::ptr m_packDepthSkinned[DepthImpl::Count][PackDepth::Count]
gpu_program::ptr m_hBlur[PackDepth::Count]
gpu_program::ptr m_packDepth[DepthImpl::Count][PackDepth::Count]
gpu_program::ptr m_packDepthInstanced[DepthImpl::Count][PackDepth::Count]
void init(rtti::context &ctx)
gpu_program::ptr m_drawDepth[PackDepth::Count]
gpu_program::ptr m_packDepthSkinnedCutout[DepthImpl::Count][PackDepth::Count]
gpu_program::ptr m_packDepthInstancedCutout[DepthImpl::Count][PackDepth::Count]
gpu_program::ptr m_packDepthCutout[DepthImpl::Count][PackDepth::Count]
gpu_program::ptr m_vBlur[PackDepth::Count]
uint32_t m_blendFactorRgba
@ ShadowMap_PackDepthHoriz
@ Custom_BlendLightTexture
@ ShadowMap_PackDepthVert
float m_splitDistribution
DepthImpl::Enum m_depthImpl
LightType::Enum m_lightType
SHADOW_FLOAT_PARAM(m_yNum)
SHADOW_FLOAT_PARAM(m_customParam1)
SHADOW_FLOAT_PARAM(m_xNum)
SHADOW_FLOAT_PARAM(m_sizePwrTwo)
SHADOW_FLOAT_PARAM(m_bias)
SHADOW_FLOAT_PARAM(m_yOffset)
SHADOW_FLOAT_PARAM(m_far)
SHADOW_FLOAT_PARAM(m_depthValuePow)
SHADOW_FLOAT_PARAM(m_xOffset)
gpu_program * m_progPackSkinned
SHADOW_FLOAT_PARAM(m_normalOffset)
gpu_program * m_progPackInstanced
SHADOW_FLOAT_PARAM(m_near)
SHADOW_FLOAT_PARAM(m_customParam0)
float scene_bounds_margin
float altitude_scale_factor
@ stabilized_light_matrix
unravel::lod_data lod_data
Per-draw state for alpha-cutout shadow batches (texture + clip threshold).
std::shared_ptr< gfx::texture > color_map