introducing the Shadow Stage

This commit is contained in:
Sam Gateau 2018-12-14 00:58:07 -08:00
parent 30277213c6
commit e07bc208f3
8 changed files with 123 additions and 43 deletions

View file

@ -374,6 +374,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
const DeferredFramebufferPointer& deferredFramebuffer,
const LightingModelPointer& lightingModel,
const LightStage::FramePointer& lightFrame,
const LightStage::ShadowFramePointer& shadowFrame,
const HazeStage::FramePointer& hazeFrame,
const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer,
const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer,
@ -627,7 +628,8 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs
auto args = renderContext->args;
const auto& lightFrame = inputs.get7();
const auto& hazeFrame = inputs.get8();
const auto& shadowFrame = inputs.get8();
const auto& hazeFrame = inputs.get9();
if (!_gpuTimer) {
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);

View file

@ -182,9 +182,9 @@ using RenderDeferredConfig = render::GPUJobConfig;
class RenderDeferred {
public:
using Inputs = render::VaryingSet9<
using Inputs = render::VaryingSet10<
DeferredFrameTransformPointer, DeferredFramebufferPointer, LightingModelPointer, SurfaceGeometryFramebufferPointer,
AmbientOcclusionFramebufferPointer, SubsurfaceScatteringResourcePointer, LightClustersPointer, LightStage::FramePointer, HazeStage::FramePointer>;
AmbientOcclusionFramebufferPointer, SubsurfaceScatteringResourcePointer, LightClustersPointer, LightStage::FramePointer, LightStage::ShadowFramePointer, HazeStage::FramePointer>;
using Config = RenderDeferredConfig;
using JobModel = render::Job::ModelI<RenderDeferred, Inputs, Config>;

View file

@ -188,11 +188,11 @@ public:
void clear() {}
using Object = std::pair<gpu::BufferPointer, gpu::TexturePointer>;
using Object = ShadowPointer;
using Objects = std::vector<Object>;
void pushShadow(LightStage::Index index, const gpu::BufferPointer& params, const gpu::TexturePointer& maps) {
_objects.emplace_back(params, maps);
void pushShadow(const ShadowPointer& shadow) {
_objects.emplace_back(shadow);
}

View file

@ -113,42 +113,48 @@ void RenderDeferredTask::configure(const Config& config) {
}
void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows) {
const auto& inputs = input.get<Input>();
const auto& fetchedItems = inputs.get0();
// const auto& fetchedItems = inputs[0];
// const auto& items = fetchedItems[0];
const auto& items = fetchedItems.get0();
auto fadeEffect = DependencyManager::get<FadeEffect>();
// Prepare the ShapePipelines
ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
initDeferredPipelines(*shapePlumber, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
// Extract opaques / transparents / lights / metas / overlays / background
const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE];
const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE];
const auto& lights = items[RenderFetchCullSortTask::LIGHT];
const auto& metas = items[RenderFetchCullSortTask::META];
const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE];
const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE];
const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE];
const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE];
const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE];
const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE];
const auto& inputs = input.get<Input>();
// Separate the fetched items
const auto& fetchedItems = inputs.get0();
const auto& spatialSelection = fetchedItems[1];
const auto& items = fetchedItems.get0();
// Extract opaques / transparents / lights / metas / overlays / background
const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE];
const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE];
const auto& lights = items[RenderFetchCullSortTask::LIGHT];
const auto& metas = items[RenderFetchCullSortTask::META];
const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE];
const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE];
const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE];
const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE];
const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE];
const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE];
const auto& spatialSelection = fetchedItems.get1();
// Extract the Lighting Stages Current frame ( and zones)
const auto lightingStageInputs = inputs.get1();
// Fetch the current frame stacks from all the stages
const auto currentStageFrames = lightingStageInputs.get0();
const auto lightFrame = currentStageFrames[0];
const auto backgroundFrame = currentStageFrames[1];
const auto& hazeFrame = currentStageFrames[2];
const auto& bloomFrame = currentStageFrames[3];
const auto& zones = lightingStageInputs[1];
// Fetch the current frame stacks from all the stages
const auto currentStageFrames = lightingStageInputs.get0();
const auto lightFrame = currentStageFrames[0];
const auto backgroundFrame = currentStageFrames[1];
const auto& hazeFrame = currentStageFrames[2];
const auto& bloomFrame = currentStageFrames[3];
const auto& zones = lightingStageInputs[1];
// Shadow Task Outputs
const auto shadowTaskOutputs = inputs.get2();
// Shadow Stage Frame
const auto shadowFrame = shadowTaskOutputs.get1();
fadeEffect->build(task, opaques);
@ -213,7 +219,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
// DeferredBuffer is complete, now let's shade it into the LightingBuffer
const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel,
surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, hazeFrame).asVarying();
surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, shadowFrame, hazeFrame).asVarying();
task.addJob<RenderDeferred>("RenderDeferred", deferredLightingInputs, renderShadows);
// Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job
@ -224,7 +230,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs);
// Render transparent objects forward in LightingBuffer
const auto transparentsInputs = DrawDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, jitter).asVarying();
const auto transparentsInputs = DrawDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, shadowFrame, jitter).asVarying();
task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
const auto outlineRangeTimer = task.addJob<BeginGPURangeTimer>("BeginHighlightRangeTimer", "Highlight");
@ -279,7 +285,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
}
RenderDeferredTaskDebug::RenderDeferredTaskDebug() {
}
/*
void RenderDeferredTaskDebug::configure(const Config& config) {
@ -308,7 +313,9 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input
const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE];
// RenderShadowTask out
const auto& renderShadowTaskOut = inputs[1];
const auto& shadowOut = inputs.get1();
const auto& renderShadowTaskOut = inputs[0];
// Extract the Lighting Stages Current frame ( and zones)
const auto lightingStageInputs = inputs.get2();
@ -448,7 +455,8 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
const auto& lightFrame = inputs.get2();
const auto& lightingModel = inputs.get3();
const auto& lightClusters = inputs.get4();
const auto jitter = inputs.get5();
const auto& shadowFrame = inputs.get5();
const auto jitter = inputs.get6();
auto deferredLightingEffect = DependencyManager::get<DeferredLightingEffect>();
RenderArgs* args = renderContext->args;

View file

@ -43,7 +43,7 @@ protected:
class DrawDeferred {
public:
using Inputs = render::VaryingSet6<render::ItemBounds, HazeStage::FramePointer, LightStage::FramePointer, LightingModelPointer, LightClustersPointer, glm::vec2>;
using Inputs = render::VaryingSet7<render::ItemBounds, HazeStage::FramePointer, LightStage::FramePointer, LightingModelPointer, LightClustersPointer, LightStage::ShadowFramePointer, glm::vec2>;
using Config = DrawDeferredConfig;
using JobModel = render::Job::ModelI<DrawDeferred, Inputs, Config>;

View file

@ -376,14 +376,14 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c
}
// copy paste the values for the shadow params:
if (!_globalShadowObject.first) {
/* if (!_globalShadowObject) {
LightStage::Shadow::Schema schema;
_globalShadowObject.first = std::make_shared<gpu::Buffer>(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema);
_globalShadowObject = std::make_shared<gpu::Buffer>(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema);
}
_globalShadowObject.first->setData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData());
_globalShadowObject->getBuffersetData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData());
_shadowFrameCache->pushShadow(0, _globalShadowObject.first, _globalShadowObject.second);
_shadowFrameCache->pushShadow(_globalShadowObject);*/
// Now adjust coarse frustum bounds
auto frustumPosition = firstCascadeFrustum->getPosition();

View file

@ -419,6 +419,7 @@ protected:
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 > using VaryingSet7 = task::VaryingSet7<T0, T1, T2, T3, T4, T5, T6>; \
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > using VaryingSet8 = task::VaryingSet8<T0, T1, T2, T3, T4, T5, T6, T7>; \
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 > using VaryingSet9 = task::VaryingSet9<T0, T1, T2, T3, T4, T5, T6, T7, T8>; \
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 > using VaryingSet10 = task::VaryingSet10<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>; \
template < class T, int NUM > using VaryingArray = task::VaryingArray<T, NUM>;

View file

@ -440,6 +440,75 @@ public:
Varying asVarying() const { return Varying((*this)); }
};
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
class VaryingSet10 : public std::tuple<Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying> {
public:
using Parent = std::tuple<Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying, Varying>;
VaryingSet10() : Parent(Varying(T0()), Varying(T1()), Varying(T2()), Varying(T3()), Varying(T4()), Varying(T5()), Varying(T6()), Varying(T7()), Varying(T8()), Varying(T9())) {}
VaryingSet10(const VaryingSet10& src) : Parent(std::get<0>(src), std::get<1>(src), std::get<2>(src), std::get<3>(src), std::get<4>(src), std::get<5>(src), std::get<6>(src), std::get<7>(src), std::get<8>(src), std::get<9>(src)) {}
VaryingSet10(const Varying& first, const Varying& second, const Varying& third, const Varying& fourth, const Varying& fifth, const Varying& sixth, const Varying& seventh, const Varying& eighth, const Varying& nine, const Varying& ten) : Parent(first, second, third, fourth, fifth, sixth, seventh, eighth, nine, ten) {}
const T0& get0() const { return std::get<0>((*this)).template get<T0>(); }
T0& edit0() { return std::get<0>((*this)).template edit<T0>(); }
const T1& get1() const { return std::get<1>((*this)).template get<T1>(); }
T1& edit1() { return std::get<1>((*this)).template edit<T1>(); }
const T2& get2() const { return std::get<2>((*this)).template get<T2>(); }
T2& edit2() { return std::get<2>((*this)).template edit<T2>(); }
const T3& get3() const { return std::get<3>((*this)).template get<T3>(); }
T3& edit3() { return std::get<3>((*this)).template edit<T3>(); }
const T4& get4() const { return std::get<4>((*this)).template get<T4>(); }
T4& edit4() { return std::get<4>((*this)).template edit<T4>(); }
const T5& get5() const { return std::get<5>((*this)).template get<T5>(); }
T5& edit5() { return std::get<5>((*this)).template edit<T5>(); }
const T6& get6() const { return std::get<6>((*this)).template get<T6>(); }
T6& edit6() { return std::get<6>((*this)).template edit<T6>(); }
const T7& get7() const { return std::get<7>((*this)).template get<T7>(); }
T7& edit7() { return std::get<7>((*this)).template edit<T7>(); }
const T8& get8() const { return std::get<8>((*this)).template get<T8>(); }
T8& edit8() { return std::get<8>((*this)).template edit<T8>(); }
const T9& get9() const { return std::get<9>((*this)).template get<T9>(); }
T9& edit9() { return std::get<9>((*this)).template edit<T9>(); }
virtual Varying operator[] (uint8_t index) const {
switch (index) {
default:
return std::get<0>((*this));
case 1:
return std::get<1>((*this));
case 2:
return std::get<2>((*this));
case 3:
return std::get<3>((*this));
case 4:
return std::get<4>((*this));
case 5:
return std::get<5>((*this));
case 6:
return std::get<6>((*this));
case 7:
return std::get<7>((*this));
case 8:
return std::get<8>((*this));
case 9:
return std::get<9>((*this));
};
}
virtual uint8_t length() const { return 10; }
Varying asVarying() const { return Varying((*this)); }
};
template < class T, int NUM >
class VaryingArray : public std::array<Varying, NUM> {
public: