| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsRenderBeastPrerequisites.h"
- #include "BsRendererMaterial.h"
- #include "BsParamBlocks.h"
- #include "BsVectorNI.h"
- namespace bs { namespace ct
- {
- class GPULightData;
- /** @addtogroup RenderBeast
- * @{
- */
- BS_PARAM_BLOCK_BEGIN(LightGridParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector3I, gLightOffsets)
- BS_PARAM_BLOCK_ENTRY(INT32, gNumCells)
- BS_PARAM_BLOCK_ENTRY(Vector3I, gGridSize)
- BS_PARAM_BLOCK_ENTRY(INT32, gMaxNumLightsPerCell)
- BS_PARAM_BLOCK_ENTRY(Vector2I, gGridPixelSize)
- BS_PARAM_BLOCK_END
- extern LightGridParamDef gLightGridParamDefDef;
- /** Shader that creates a linked list for each light grid cell, containing which light affects each cell. */
- class LightGridLLCreationMat : public RendererMaterial<LightGridLLCreationMat>
- {
- RMAT_DEF("LightGridLLCreation.bsl");
- public:
- LightGridLLCreationMat();
- /** Binds parameter buffers and prepares any internal buffers. Must be called before execute(). */
- void setParams(const Vector3I& gridSize, const SPtr<GpuParamBlockBuffer>& gridParams,
- const SPtr<GpuBuffer>& lightsBuffer);
- /** Binds the material for rendering, sets up per-camera parameters and executes it. */
- void execute(const RendererCamera& view);
- /** Returns the buffers generated by execute(). */
- void getOutputs(SPtr<GpuBuffer>& linkedListHeads, SPtr<GpuBuffer>& linkedList) const;
- private:
- GpuParamBuffer mLightBufferParam;
- GpuParamBuffer mLinkedListCounterParam;
- GpuParamBuffer mLinkedListHeadsParam;
- GpuParamBuffer mLinkedListParam;
- SPtr<GpuBuffer> mLinkedListCounter;
- SPtr<GpuBuffer> mLinkedListHeads;
- SPtr<GpuBuffer> mLinkedList;
- UINT32 mBufferNumCells;
- Vector3I mGridSize;
- };
- /** Shader that reduces the linked list created by LightGridLLCreationMat into a sequential array. */
- class LightGridLLReductionMat : public RendererMaterial<LightGridLLReductionMat>
- {
- RMAT_DEF("LightGridLLReduction.bsl");
- public:
- LightGridLLReductionMat();
- /** Binds parameter buffers and prepares any internal buffers. Must be called before execute(). */
- void setParams(const Vector3I& gridSize, const SPtr<GpuParamBlockBuffer>& gridParams,
- const SPtr<GpuBuffer>& linkedListHeads, const SPtr<GpuBuffer>& linkedList);
- /** Binds the material for renderingand executes it. */
- void execute(const RendererCamera& view);
- /** Returns the buffers generated by execute(). */
- void getOutputs(SPtr<GpuBuffer>& gridOffsetsAndSize, SPtr<GpuBuffer>& gridLightIndices) const;
- private:
- GpuParamBuffer mLinkedListHeadsParam;
- GpuParamBuffer mLinkedListParam;
- GpuParamBuffer mGridDataCounterParam;
- GpuParamBuffer mGridLightOffsetAndSizeParam;
- GpuParamBuffer mGridLightIndicesParam;
- SPtr<GpuBuffer> mGridDataCounter;
- SPtr<GpuBuffer> mGridLightOffsetAndSize;
- SPtr<GpuBuffer> mGridLightIndices;
- UINT32 mBufferNumCells;
- Vector3I mGridSize;
- };
- /**
- * Helper class that is used for generating a grid in view space, whose cells contain information about lights
- * affecting them. Used for forward rendering.
- */
- class LightGrid
- {
- public:
- LightGrid();
- /** Updates the light grid from the provided view. */
- void updateGrid(const RendererCamera& view, const GPULightData& lightData, bool noLighting);
- /**
- * Returns the buffers containing light indices per grid cell and global grid parameters.
- *
- * @param[out] gridOffsetsAndSize Flattened array of grid cells, where each entry contains the number of lights
- * affecting that cell, and a index into the @p gridLightIndices buffer.
- * @param[out] gridLightIndices A list of light indices. Each cell's indices start at specific position and
- * are placed sequentially one after another. Lookup into this array is done
- * through offset & size provided by @p gridOffsetsAndSize.
- * @param[out] gridParams Global grid parameter block.
- */
- void getOutputs(SPtr<GpuBuffer>& gridOffsetsAndSize, SPtr<GpuBuffer>& gridLightIndices,
- SPtr<GpuParamBlockBuffer>& gridParams) const;
- private:
- LightGridLLCreationMat mLLCreationMat;
- LightGridLLReductionMat mLLReductionMat;
- SPtr<GpuParamBlockBuffer> mGridParamBuffer;
- };
- /** @} */
- }}
|