Refactor scene rendering to use batched culling for main view and shadow projections
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#define SHADOWS_PASS_SS_RR_FORMAT PixelFormat::R11G11B10_Float
|
||||
|
||||
template<typename T>
|
||||
bool CanRenderShadow(RenderView& view, const T& light)
|
||||
bool CanRenderShadow(const RenderView& view, const T& light)
|
||||
{
|
||||
bool result = false;
|
||||
switch ((ShadowsCastingMode)light.ShadowsMode)
|
||||
@@ -42,6 +42,14 @@ class ShadowsPass : public RendererPass<ShadowsPass>
|
||||
{
|
||||
private:
|
||||
|
||||
struct ShadowData
|
||||
{
|
||||
int32 ContextIndex;
|
||||
int32 ContextCount;
|
||||
bool BlendCSM;
|
||||
LightShadowData Constants;
|
||||
};
|
||||
|
||||
// Shader stuff
|
||||
AssetReference<Shader> _shader;
|
||||
GPUPipelineStatePermutationsPs<static_cast<int32>(Quality::MAX) * 2 * 2> _psShadowDir;
|
||||
@@ -57,9 +65,8 @@ private:
|
||||
Quality _currentShadowMapsQuality;
|
||||
|
||||
// Shadow map rendering stuff
|
||||
RenderContext _shadowContext;
|
||||
RenderList _shadowCache;
|
||||
AssetReference<Model> _sphereModel;
|
||||
Array<ShadowData> _shadowData;
|
||||
|
||||
// Cached state for the current frame rendering (setup via Prepare)
|
||||
int32 maxShadowsQuality;
|
||||
@@ -87,6 +94,10 @@ public:
|
||||
LightShadowData LastDirLight;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Setups the shadows rendering for batched scene drawing. Checks which lights will cast a shadow.
|
||||
/// </summary>
|
||||
void SetupShadows(RenderContext& renderContext, RenderContextBatch& renderContextBatch);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether can render shadow for the specified light.
|
||||
@@ -94,7 +105,7 @@ public:
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
|
||||
bool CanRenderShadow(RenderContext& renderContext, const RendererPointLightData& light);
|
||||
bool CanRenderShadow(const RenderContext& renderContext, const RendererPointLightData& light);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether can render shadow for the specified light.
|
||||
@@ -102,7 +113,7 @@ public:
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
|
||||
bool CanRenderShadow(RenderContext& renderContext, const RendererSpotLightData& light);
|
||||
bool CanRenderShadow(const RenderContext& renderContext, const RendererSpotLightData& light);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether can render shadow for the specified light.
|
||||
@@ -110,43 +121,40 @@ public:
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
|
||||
bool CanRenderShadow(RenderContext& renderContext, const RendererDirectionalLightData& light);
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the shadows rendering. Called by the light pass once per frame.
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="context">The GPU command context.</param>
|
||||
void Prepare(RenderContext& renderContext, GPUContext* context);
|
||||
bool CanRenderShadow(const RenderContext& renderContext, const RendererDirectionalLightData& light);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the shadow mask for the given light.
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="renderContextBatch">The rendering context batch.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <param name="shadowMask">The shadow mask (output).</param>
|
||||
void RenderShadow(RenderContext& renderContext, RendererPointLightData& light, GPUTextureView* shadowMask);
|
||||
void RenderShadow(RenderContextBatch& renderContextBatch, RendererPointLightData& light, GPUTextureView* shadowMask);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the shadow mask for the given light.
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="renderContextBatch">The rendering context batch.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <param name="shadowMask">The shadow mask (output).</param>
|
||||
void RenderShadow(RenderContext& renderContext, RendererSpotLightData& light, GPUTextureView* shadowMask);
|
||||
void RenderShadow(RenderContextBatch& renderContextBatch, RendererSpotLightData& light, GPUTextureView* shadowMask);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the shadow mask for the given light.
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="renderContextBatch">The rendering context batch.</param>
|
||||
/// <param name="light">The light.</param>
|
||||
/// <param name="index">The light index.</param>
|
||||
/// <param name="shadowMask">The shadow mask (output).</param>
|
||||
void RenderShadow(RenderContext& renderContext, RendererDirectionalLightData& light, int32 index, GPUTextureView* shadowMask);
|
||||
void RenderShadow(RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light, int32 index, GPUTextureView* shadowMask);
|
||||
|
||||
private:
|
||||
|
||||
void updateShadowMapSize();
|
||||
void SetupRenderContext(RenderContext& renderContext, RenderContext& shadowContext);
|
||||
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light);
|
||||
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererPointLightData& light);
|
||||
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererSpotLightData& light);
|
||||
|
||||
#if COMPILE_WITH_DEV_ENV
|
||||
void OnShaderReloading(Asset* obj)
|
||||
|
||||
Reference in New Issue
Block a user