Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/Rendering/ForwardPlusRenderer.cpp

Diff revisions: vs.
  @@ -7,12 +7,17 @@
7 7
8 8 ForwardPlusRenderer::ForwardPlusRenderer() : Renderer(RENDERER_FORWARD_PLUS)
9 9 {
10 - _opaqueGrid = New LightGrid();
11 - _transparentGrid = New LightGrid();
10 + _opaqueGrid = MemoryManager_NEW LightGrid();
11 + _transparentGrid = MemoryManager_NEW LightGrid();
12 12 /// Initialize our depth ranges construction shader (see LightManager.cpp for more documentation)
13 13 ResourceDescriptor rangesDesc("DepthRangesConstruct");
14 - rangesDesc.setPropertyList(stringAlg::toBase("LIGHT_GRID_TILE_DIM_X " + Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_X) + "," +
15 - "LIGHT_GRID_TILE_DIM_Y " + Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_Y)));
14 +
15 + stringImpl gridDim("LIGHT_GRID_TILE_DIM_X ");
16 + gridDim.append(Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_X).c_str());
17 + gridDim.append(",LIGHT_GRID_TILE_DIM_Y ");
18 + gridDim.append(Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_Y).c_str());
19 + rangesDesc.setPropertyList(gridDim);
20 +
16 21 _depthRangesConstructProgram = CreateResource<ShaderProgram>(rangesDesc);
17 22 _depthRangesConstructProgram->UniformTexture("depthTex", 0);
18 23 /// Depth ranges are used for grid based light culling
  @@ -22,7 +27,8 @@
22 27 depthRangesSampler.toggleMipMaps(false);
23 28 TextureDescriptor depthRangesDescriptor(TEXTURE_2D, RGBA32F, FLOAT_32);
24 29 depthRangesDescriptor.setSampler(depthRangesSampler);
25 - // The down-sampled depth buffer is used to cull screen space lights for our Forward+ rendering algorithm. It's only updated on demand.
30 + // The down-sampled depth buffer is used to cull screen space lights for our Forward+ rendering algorithm.
31 + // It's only updated on demand.
26 32 _depthRanges = GFX_DEVICE.newFB(false);
27 33 _depthRanges->AddAttachment(depthRangesDescriptor, TextureDescriptor::Color0);
28 34 _depthRanges->toggleDepthBuffer(false);
  @@ -35,53 +41,66 @@
35 41
36 42 ForwardPlusRenderer::~ForwardPlusRenderer()
37 43 {
38 - MemoryManager::SAFE_DELETE( _depthRanges );
39 - MemoryManager::SAFE_DELETE( _opaqueGrid );
40 - MemoryManager::SAFE_DELETE( _transparentGrid );
44 + MemoryManager::DELETE( _depthRanges );
45 + MemoryManager::DELETE( _opaqueGrid );
46 + MemoryManager::DELETE( _transparentGrid );
41 47 RemoveResource(_depthRangesConstructProgram);
42 48 }
43 49
44 - void ForwardPlusRenderer::processVisibleNodes(const vectorImpl<SceneGraphNode* >& visibleNodes, const GFXDevice::GPUBlock& gpuBlock) {
50 + void ForwardPlusRenderer::processVisibleNodes(const vectorImpl<SceneGraphNode* >& visibleNodes,
51 + const GFXDevice::GPUBlock& gpuBlock) {
45 52 buildLightGrid(gpuBlock);
46 53 }
47 54
48 - void ForwardPlusRenderer::render(const DELEGATE_CBK<>& renderCallback, const SceneRenderState& sceneRenderState) {
55 + void ForwardPlusRenderer::render(const DELEGATE_CBK<>& renderCallback,
56 + const SceneRenderState& sceneRenderState) {
49 57 renderCallback();
50 58 }
51 59
52 60 void ForwardPlusRenderer::updateResolution(U16 width, U16 height) {
53 - vec2<U16> tileSize(Config::Lighting::LIGHT_GRID_TILE_DIM_X, Config::Lighting::LIGHT_GRID_TILE_DIM_Y);
54 - vec2<U16> resTemp(GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)->getResolution() + tileSize);
55 - _depthRanges->Create(resTemp.x / tileSize.x - 1, resTemp.y / tileSize.y - 1);
61 + vec2<U16> tileSize(Config::Lighting::LIGHT_GRID_TILE_DIM_X,
62 + Config::Lighting::LIGHT_GRID_TILE_DIM_Y);
63 + vec2<U16> resTemp(GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)->getResolution() +
64 + tileSize);
65 + _depthRanges->Create(resTemp.x / tileSize.x - 1,
66 + resTemp.y / tileSize.y - 1);
56 67 }
57 68
58 69 bool ForwardPlusRenderer::buildLightGrid(const GFXDevice::GPUBlock& gpuBlock) {
59 70 const Light::LightMap& lights = LightManager::getInstance().getLights();
60 71
61 72 _omniLightList.clear();
62 - _omniLightList.reserve(lights.size());
73 + _omniLightList.reserve(static_cast<vectorAlg::vecSize>(lights.size()));
63 74
64 75 for (const Light::LightMap::value_type& it : lights) {
65 76 const Light& light = *it.second;
66 77 if ( light.getLightType() == LIGHT_TYPE_POINT ) {
67 - _omniLightList.push_back( LightGrid::make_light( light.getPosition(), light.getDiffuseColor(), light.getRange() ) );
78 + _omniLightList.push_back( LightGrid::makeLight(light.getPosition(),
79 + light.getDiffuseColor(),
80 + light.getRange() ) );
68 81 }
69 82 }
70 83
71 84 if ( !_omniLightList.empty() ) {
72 - _transparentGrid->build(vec2<U16>(Config::Lighting::LIGHT_GRID_TILE_DIM_X, Config::Lighting::LIGHT_GRID_TILE_DIM_Y),
73 - vec2<U16>(gpuBlock._ViewPort.z, gpuBlock._ViewPort.w), //< render target resolution
85 + _transparentGrid->build(vec2<U16>(Config::Lighting::LIGHT_GRID_TILE_DIM_X,
86 + Config::Lighting::LIGHT_GRID_TILE_DIM_Y),
87 + // render target resolution
88 + vec2<U16>(gpuBlock._ViewPort.z,
89 + gpuBlock._ViewPort.w),
74 90 _omniLightList,
75 91 gpuBlock._ViewMatrix,
76 92 gpuBlock._ProjectionMatrix,
77 - gpuBlock._ZPlanesCombined.x, //< current near plane
93 + // current near plane
94 + gpuBlock._ZPlanesCombined.x,
78 95 vectorImpl<vec2<F32> >());
79 96
80 97
81 98 downSampleDepthBuffer(_depthRangesCache);
82 - // We take a copy of this, and prune the grid using depth ranges found from pre-z pass (for opaque geometry).
99 + // We take a copy of this, and prune the grid using depth ranges found from pre-z pass
100 + // (for opaque geometry).
83 101 _opaqueGrid = _transparentGrid;
84 - // Note that the pruning does not occur if the pre-z pass was not performed (depthRanges is empty in this case).
102 + // Note that the pruning does not occur if the pre-z pass was not performed
103 + // (depthRanges is empty in this case).
85 104 _opaqueGrid->prune(_depthRangesCache);
86 105 _transparentGrid->pruneFarOnly(gpuBlock._ZPlanesCombined.x, _depthRangesCache);
87 106 return true;
  @@ -91,14 +110,16 @@
91 110 }
92 111
93 112 /// Extract the depth ranges and store them in a different render target used to cull lights against
94 - void ForwardPlusRenderer::downSampleDepthBuffer(vectorImpl<vec2<F32>> &depthRanges){
113 + void ForwardPlusRenderer::downSampleDepthBuffer(vectorImpl<vec2<F32>> &depthRanges) {
95 114 depthRanges.resize(_depthRanges->getWidth() * _depthRanges->getHeight());
96 115
97 116 _depthRanges->Begin(Framebuffer::defaultPolicy());
98 117 {
99 118 _depthRangesConstructProgram->bind();
100 - _depthRangesConstructProgram->Uniform("dvd_ProjectionMatrixInverse", GFX_DEVICE.getMatrix(PROJECTION_INV_MATRIX));
101 - GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)->Bind(ShaderProgram::TEXTURE_UNIT0, TextureDescriptor::Depth);
119 + _depthRangesConstructProgram->Uniform("dvd_ProjectionMatrixInverse",
120 + GFX_DEVICE.getMatrix(PROJECTION_INV_MATRIX));
121 + GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)->Bind(ShaderProgram::TEXTURE_UNIT0,
122 + TextureDescriptor::Depth);
102 123 GFX_DEVICE.drawPoints(1, GFX_DEVICE.getDefaultStateBlock(true), _depthRangesConstructProgram);
103 124
104 125 _depthRanges->ReadData(RG, FLOAT_32, &depthRanges[0]);