12 #ifndef hifi_RenderShadowTask_h
13 #define hifi_RenderShadowTask_h
15 #include <gpu/Framebuffer.h>
16 #include <gpu/Pipeline.h>
18 #include <render/CullTask.h>
20 #include "Shadows_shared.slh"
22 #include "LightingModel.h"
23 #include "LightStage.h"
27 class RenderShadowMap {
29 using Inputs = render::VaryingSet3<render::ShapeBounds, AABox, LightStage::ShadowFramePointer>;
30 using JobModel = render::Job::ModelI<RenderShadowMap, Inputs>;
32 RenderShadowMap(render::ShapePlumberPointer shapePlumber,
unsigned int cascadeIndex) : _shapePlumber{ shapePlumber }, _cascadeIndex{ cascadeIndex } {}
33 void run(
const render::RenderContextPointer& renderContext,
const Inputs& inputs);
36 render::ShapePlumberPointer _shapePlumber;
37 unsigned int _cascadeIndex;
41 class RenderShadowTaskConfig :
public render::Task::Config {
45 RenderShadowTaskConfig() {}
51 class RenderShadowTask {
54 using CascadeBoxes = render::VaryingArray<AABox, SHADOW_CASCADE_MAX_COUNT>;
55 using Input = render::VaryingSet2<LightStage::FramePointer, LightingModelPointer>;
56 using Output = render::VaryingSet2<CascadeBoxes, LightStage::ShadowFramePointer>;
57 using Config = RenderShadowTaskConfig;
58 using JobModel = render::Task::ModelIO<RenderShadowTask, Input, Output, Config>;
61 void build(JobModel& task,
const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cameraCullFunctor, uint8_t tagBits = 0x00, uint8_t tagMask = 0x00);
63 void configure(
const Config& configuration);
66 float _minSquareSize{ 0.0f };
68 bool operator()(
const RenderArgs* args,
const AABox& bounds)
const {
70 const auto boundsSquareRadius = glm::dot(bounds.getDimensions(), bounds.getDimensions());
71 return boundsSquareRadius > _minSquareSize;
75 CullFunctor _cullFunctor;
78 class RenderShadowSetupConfig :
public render::Job::Config {
80 Q_PROPERTY(
float constantBias0 MEMBER constantBias0 NOTIFY dirty)
81 Q_PROPERTY(
float constantBias1 MEMBER constantBias1 NOTIFY dirty)
82 Q_PROPERTY(
float constantBias2 MEMBER constantBias2 NOTIFY dirty)
83 Q_PROPERTY(
float constantBias3 MEMBER constantBias3 NOTIFY dirty)
84 Q_PROPERTY(
float slopeBias0 MEMBER slopeBias0 NOTIFY dirty)
85 Q_PROPERTY(
float slopeBias1 MEMBER slopeBias1 NOTIFY dirty)
86 Q_PROPERTY(
float slopeBias2 MEMBER slopeBias2 NOTIFY dirty)
87 Q_PROPERTY(
float slopeBias3 MEMBER slopeBias3 NOTIFY dirty)
88 Q_PROPERTY(
float biasInput MEMBER biasInput NOTIFY dirty)
89 Q_PROPERTY(
float maxDistance MEMBER maxDistance NOTIFY dirty)
93 float constantBias0 { 0.0f };
94 float constantBias1 { 0.0f };
95 float constantBias2 { 0.0f };
96 float constantBias3 { 0.0f };
97 float slopeBias0 { 0.0f };
98 float slopeBias1 { 0.0f };
99 float slopeBias2 { 0.0f };
100 float slopeBias3 { 0.0f };
101 float biasInput { 0.0f };
102 float maxDistance { 0.0f };
108 class RenderShadowSetup {
110 using Input = RenderShadowTask::Input;
111 using Output = render::VaryingSet5<RenderArgs::RenderMode, glm::ivec2, ViewFrustumPointer, LightStage::ShadowFramePointer, graphics::LightPointer>;
112 using Config = RenderShadowSetupConfig;
113 using JobModel = render::Job::ModelIO<RenderShadowSetup, Input, Output, Config>;
116 void configure(
const Config& config);
117 void run(
const render::RenderContextPointer& renderContext,
const Input& input, Output& output);
120 ViewFrustumPointer _cameraFrustum;
121 ViewFrustumPointer _coarseShadowFrustum;
125 } _bias[SHADOW_CASCADE_MAX_COUNT];
127 LightStage::ShadowFrame::Object _globalShadowObject;
128 LightStage::ShadowFramePointer _shadowFrameCache;
142 void setConstantBias(
int cascadeIndex,
float value);
143 void setSlopeBias(
int cascadeIndex,
float value);
144 void calculateBiases(
float biasInput);
147 class RenderShadowCascadeSetup {
149 using Inputs = LightStage::ShadowFramePointer;
150 using Outputs = render::VaryingSet3<render::ItemFilter, ViewFrustumPointer, RenderShadowTask::CullFunctor>;
151 using JobModel = render::Job::ModelIO<RenderShadowCascadeSetup, Inputs, Outputs>;
153 RenderShadowCascadeSetup(
unsigned int cascadeIndex, render::ItemFilter filter) : _cascadeIndex(cascadeIndex), _filter(filter) {}
155 void run(
const render::RenderContextPointer& renderContext,
const Inputs& input, Outputs& output);
158 unsigned int _cascadeIndex;
159 render::ItemFilter _filter;
162 class RenderShadowCascadeTeardown {
164 using Input = render::ItemFilter;
165 using JobModel = render::Job::ModelI<RenderShadowCascadeTeardown, Input>;
166 void run(
const render::RenderContextPointer& renderContext,
const Input& input);
169 class RenderShadowTeardown {
171 using Input = RenderShadowSetup::Output;
172 using JobModel = render::Job::ModelI<RenderShadowTeardown, Input>;
173 void run(
const render::RenderContextPointer& renderContext,
const Input& input);
176 class CullShadowBounds {
178 using Inputs = render::VaryingSet5<render::ShapeBounds, render::ItemFilter, ViewFrustumPointer, graphics::LightPointer, RenderShadowTask::CullFunctor>;
179 using Outputs = render::VaryingSet2<render::ShapeBounds, AABox>;
180 using JobModel = render::Job::ModelIO<CullShadowBounds, Inputs, Outputs>;
182 void run(
const render::RenderContextPointer& renderContext,
const Inputs& inputs, Outputs& outputs);