Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "Headers/ForwardPlusRenderer.h"

#include "Core/Headers/Console.h"
#include "Managers/Headers/LightManager.h"
#include "Core/Resources/Headers/ResourceCache.h"

namespace Divide {

ForwardPlusRenderer::ForwardPlusRenderer() : Renderer(RENDERER_FORWARD_PLUS) {
    _opaqueGrid.reset(/*MemoryManager_NEW*/ new LightGrid());
    _transparentGrid.reset(/*MemoryManager_NEW*/ new LightGrid());
    /// Initialize our depth ranges construction shader (see LightManager.cpp
    /// for more documentation)
    ResourceDescriptor rangesDesc("DepthRangesConstruct");

    stringImpl gridDim("LIGHT_GRID_TILE_DIM_X ");
    gridDim.append(
        Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_X).c_str());
    gridDim.append(",LIGHT_GRID_TILE_DIM_Y ");
    gridDim.append(
        Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_Y).c_str());
    rangesDesc.setPropertyList(gridDim);

    _depthRangesConstructProgram = CreateResource<ShaderProgram>(rangesDesc);
    _depthRangesConstructProgram->UniformTexture("depthTex", 0);
    /// Depth ranges are used for grid based light culling
    SamplerDescriptor depthRangesSampler;
    depthRangesSampler.setFilters(TEXTURE_FILTER_NEAREST);
    depthRangesSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
    depthRangesSampler.toggleMipMaps(false);
    TextureDescriptor depthRangesDescriptor(TEXTURE_2D, RGBA32F, FLOAT_32);
    depthRangesDescriptor.setSampler(depthRangesSampler);
    // The down-sampled depth buffer is used to cull screen space lights for our
    // Forward+ rendering algorithm.
    // It's only updated on demand.
    _depthRanges = GFX_DEVICE.newFB(false);
    _depthRanges->AddAttachment(depthRangesDescriptor,
                                TextureDescriptor::Color0);
    _depthRanges->toggleDepthBuffer(false);
    _depthRanges->setClearColor(vec4<F32>(0.0f, 1.0f, 0.0f, 1.0f));
    vec2<U16> screenRes =
        GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)
            ->getResolution();
    vec2<U16> tileSize(Config::Lighting::LIGHT_GRID_TILE_DIM_X,
                       Config::Lighting::LIGHT_GRID_TILE_DIM_Y);
    vec2<U16> resTemp(screenRes + tileSize);
    _depthRanges->Create(resTemp.x / tileSize.x - 1,
                         resTemp.y / tileSize.y - 1);
}

ForwardPlusRenderer::~ForwardPlusRenderer() {
    MemoryManager::DELETE(_depthRanges);
    RemoveResource(_depthRangesConstructProgram);
}

void ForwardPlusRenderer::processVisibleNodes(
    const vectorImpl<SceneGraphNode*>& visibleNodes,
    const GFXDevice::GPUBlock& gpuBlock) {
    buildLightGrid(gpuBlock);
}

void ForwardPlusRenderer::render(const DELEGATE_CBK<>& renderCallback,
                                 const SceneRenderState& sceneRenderState) {
    renderCallback();
}

void ForwardPlusRenderer::updateResolution(U16 width, U16 height) {
    vec2<U16> tileSize(Config::Lighting::LIGHT_GRID_TILE_DIM_X,
                       Config::Lighting::LIGHT_GRID_TILE_DIM_Y);
    vec2<U16> resTemp(GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)
                          ->getResolution() +
                      tileSize);
    _depthRanges->Create(resTemp.x / tileSize.x - 1,
                         resTemp.y / tileSize.y - 1);
}

bool ForwardPlusRenderer::buildLightGrid(const GFXDevice::GPUBlock& gpuBlock) {
    const Light::LightMap& lights = LightManager::getInstance().getLights();

    _omniLightList.clear();
    _omniLightList.reserve(static_cast<vectorAlg::vecSize>(lights.size()));

    for (const Light::LightMap::value_type& it : lights) {
        const Light& light = *it.second;
        if (light.getLightType() == LIGHT_TYPE_POINT) {
            _omniLightList.push_back(LightGrid::makeLight(
                light.getPosition(), light.getDiffuseColor(),
                light.getRange()));
        }
    }

    if (!_omniLightList.empty()) {
        _transparentGrid->build(
            vec2<U16>(Config::Lighting::LIGHT_GRID_TILE_DIM_X,
                      Config::Lighting::LIGHT_GRID_TILE_DIM_Y),
            // render target resolution
            vec2<U16>(gpuBlock._ViewPort.z, gpuBlock._ViewPort.w),
            _omniLightList, gpuBlock._ViewMatrix, gpuBlock._ProjectionMatrix,
            // current near plane
            gpuBlock._ZPlanesCombined.x, vectorImpl<vec2<F32>>());

        downSampleDepthBuffer(_depthRangesCache);
        // We take a copy of this, and prune the grid using depth ranges found
        // from pre-z pass
        // (for opaque geometry).
        STUBBED("ADD OPTIMIZED COPY!!!");
        *_opaqueGrid = *_transparentGrid;
        // Note that the pruning does not occur if the pre-z pass was not
        // performed
        // (depthRanges is empty in this case).
        _opaqueGrid->prune(_depthRangesCache);
        _transparentGrid->pruneFarOnly(gpuBlock._ZPlanesCombined.x,
                                       _depthRangesCache);
        return true;
    }

    return false;
}

/// Extract the depth ranges and store them in a different render target used to
/// cull lights against
void ForwardPlusRenderer::downSampleDepthBuffer(
    vectorImpl<vec2<F32>>& depthRanges) {
    depthRanges.resize(_depthRanges->getWidth() * _depthRanges->getHeight());

    _depthRanges->Begin(Framebuffer::defaultPolicy());
    {
        _depthRangesConstructProgram->bind();
        _depthRangesConstructProgram->Uniform(
            "dvd_ProjectionMatrixInverse",
            GFX_DEVICE.getMatrix(PROJECTION_INV_MATRIX));
        GFX_DEVICE.getRenderTarget(GFXDevice::RENDER_TARGET_DEPTH)
            ->Bind(ShaderProgram::TEXTURE_UNIT0, TextureDescriptor::Depth);
        GFX_DEVICE.drawPoints(1, GFX_DEVICE.getDefaultStateBlock(true),
                              _depthRangesConstructProgram);

        _depthRanges->ReadData(RG, FLOAT_32, &depthRanges[0]);
    }
    _depthRanges->End();
}
};

Commits for Divide-Framework/trunk/Source Code/Rendering/ForwardPlusRenderer.cpp

Diff revisions: vs.
Revision Author Commited Message
350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

348 Diff Diff IonutCava picture IonutCava Thu 05 Feb, 2015 17:13:01 +0000

[Ionut]
- Replaced some raw pointers with smart pointers or direct data members
- Removed redundant SceneGraph pointer from SceneGraphNode

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

327 Diff Diff IonutCava picture IonutCava Thu 02 Oct, 2014 12:32:15 +0000

[Ionut]
- Removed specular color from lights (specular color should be identical to light’s diffuse color anyway)
- Doublesided materials use their own shader defines now
- Fixed a bug in the particle shader related to screen dimensions never being passed
- Disabled material loading from XML for Primitive type geometry

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

299 IonutCava picture IonutCava Mon 04 Aug, 2014 22:09:22 +0000

[Ionut]
- Disabled shader binary dump/load on non-nVidia GPUs (caused issues)
- More code cleanup/comments/formating (GFXDevice.cpp)