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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "Headers/GFXDevice.h"

#include "Core/Headers/Kernel.h"
#include "Core/Headers/Application.h"
#include "Core/Headers/ParamHandler.h"
#include "Scenes/Headers/SceneState.h"
#include "Core/Time/Headers/ApplicationTimer.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Rendering/Camera/Headers/Camera.h"
#include "Platform/Video/Headers/IMPrimitive.h"
#include "Platform/Video/Textures/Headers/Texture.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"
#include "Platform/Video/Buffers/RenderTarget/Headers/RenderTarget.h"

namespace Divide {

void GFXDevice::renderDebugViews() {
    static DebugView* HiZPtr;

    // As this is touched once per frame, we'll only enable it in debug builds
    if (Config::Build::IS_DEBUG_BUILD) {
        // Early out if we didn't request the preview
        if (!ParamHandler::instance().getParam<bool>(_ID("rendering.previewDebugViews"), false)) {
            return;
        }

        // Lazy-load preview shader
        if (!_previewDepthMapShader) {
            // The LinearDepth variant converts the depth values to linear values
            // between the 2 scene z-planes
            ResourceDescriptor fbPreview("fbPreview.LinearDepth.ScenePlanes");
            fbPreview.setPropertyList("USE_SCENE_ZPLANES");
            _previewDepthMapShader = CreateResource<ShaderProgram>(parent().resourceCache(), fbPreview);
            assert(_previewDepthMapShader != nullptr);

            DebugView_ptr HiZ = std::make_shared<DebugView>();
            HiZ->_shader = _previewDepthMapShader;
            HiZ->_texture = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getAttachment(RTAttachment::Type::Depth, 0).asTexture();
            HiZ->_shaderData._floatValues.push_back(std::make_pair("lodLevel", to_float(HiZ->_texture->getMaxMipLevel() - 1)));

            DebugView_ptr DepthPreview = std::make_shared<DebugView>();
            DepthPreview->_shader = _previewDepthMapShader;
            DepthPreview->_texture = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getAttachment(RTAttachment::Type::Depth, 0).asTexture();
            DepthPreview->_shaderData._floatValues.push_back(std::make_pair("lodLevel", 0.0f));

            DebugView_ptr NormalPreview = std::make_shared<DebugView>();
            NormalPreview->_shader = _renderTargetDraw;
            NormalPreview->_texture = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getAttachment(RTAttachment::Type::Colour, to_const_ubyte(ScreenTargets::NORMALS)).asTexture();
            NormalPreview->_shaderData._boolValues.push_back(std::make_pair("linearSpace", false));
            NormalPreview->_shaderData._boolValues.push_back(std::make_pair("unpack2Channel", true));

            DebugView_ptr VelocityPreview = std::make_shared<DebugView>();
            VelocityPreview->_shader = _renderTargetDraw;
            VelocityPreview->_texture = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getAttachment(RTAttachment::Type::Colour, to_const_ubyte(ScreenTargets::VELOCITY)).asTexture();
            VelocityPreview->_shaderData._boolValues.push_back(std::make_pair("linearSpace", false));
            VelocityPreview->_shaderData._boolValues.push_back(std::make_pair("unpack2Channel", false));


            addDebugView(HiZ);
            addDebugView(DepthPreview);
            addDebugView(NormalPreview);
            addDebugView(VelocityPreview);

            HiZPtr = HiZ.get();
        }

        if (HiZPtr) {
            //HiZ preview
            I32 LoDLevel = 0;
            if (Config::USE_HIZ_CULLING && Config::USE_Z_PRE_PASS) {
                LoDLevel = to_int(std::ceil(Time::ElapsedMilliseconds() / 750.0f)) %
                    (renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getAttachment(RTAttachment::Type::Depth, 0).asTexture()->getMaxMipLevel() - 1);
            }
            HiZPtr->_shaderData._floatValues[0].second = to_float(LoDLevel);
        }
    

        constexpr I32 maxViewportColumnCount = 10;
        I32 viewCount = to_int(_debugViews.size());
        I32 columnCount = std::min(viewCount, maxViewportColumnCount);
        I32 rowCount = viewCount / maxViewportColumnCount;
        if (viewCount % maxViewportColumnCount > 0) {
            rowCount++;
        }

        RenderTarget& screenRT = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN));
        U16 screenWidth = std::max(screenRT.getWidth(), to_const_ushort(1280));
        U16 screenHeight = std::max(screenRT.getHeight(), to_const_ushort(720));
        F32 aspectRatio = to_float(screenWidth) / screenHeight;

        I32 viewportWidth = screenWidth / maxViewportColumnCount;
        I32 viewportHeight = to_int(viewportWidth / aspectRatio);
        vec4<I32> viewport(screenWidth - viewportWidth, 0, viewportWidth, viewportHeight);

        GenericDrawCommand triangleCmd;
        triangleCmd.primitiveType(PrimitiveType::TRIANGLES);
        triangleCmd.drawCount(1);
        triangleCmd.stateHash(_defaultStateNoDepthHash);

        I32 viewIndex = 0;
        for (U8 i = 0; i < rowCount; ++i) {
            for (U8 j = 0; j < columnCount; ++j) {
                DebugView& view = *_debugViews[viewIndex];
                triangleCmd.shaderProgram(view._shader);
                view._texture->bind(view._textureBindSlot);

                DebugView::ShaderData& shaderData = view._shaderData;
                for (const std::pair<stringImpl, I32>& data : shaderData._intValues) {
                    view._shader->Uniform(data.first.c_str(), data.second);
                }
                for (const std::pair<stringImpl, F32>& data : shaderData._floatValues) {
                    view._shader->Uniform(data.first.c_str(), data.second);
                }
                for (const std::pair<stringImpl, bool>& data : shaderData._boolValues) {
                    view._shader->Uniform(data.first.c_str(), data.second);
                }
                {
                    GFX::ScopedViewport sView(*this, viewport);
                    draw(triangleCmd);
                }

                viewport.x -= viewportWidth;
                viewIndex++;
            }
            viewport.y -= viewportHeight;
        }
    }
}


void GFXDevice::addDebugView(const std::shared_ptr<DebugView>& view) {
    _debugViews.push_back(view);
    std::sort(std::begin(_debugViews),
              std::end(_debugViews),
              [](const std::shared_ptr<DebugView>& a, const std::shared_ptr<DebugView>& b)-> bool {
                  return a->_shader->getGUID() < b->_shader->getGUID();
               });
}

void GFXDevice::drawDebugFrustum(RenderSubPassCmds& subPassesInOut) {
    if (_debugFrustum != nullptr) {
        static const vec4<U8> redColour(Util::ToByteColour(DefaultColours::RED()));
        static const vec4<U8> greenColour(Util::ToByteColour(DefaultColours::GREEN()));

        vectorImpl<vec3<F32>> corners;
        _debugFrustum->getCornersViewSpace(corners);

        vectorImpl<Line> lines;
        for (U8 i = 0; i < 4; ++i) {
            // Draw Near Plane
            lines.emplace_back(corners[i], corners[(i + 1) % 4], redColour);
            // Draw Far Plane
            lines.emplace_back(corners[i + 4], corners[(i + 4 + 1) % 4], redColour);
            // Connect Near Plane with Far Plane
            lines.emplace_back(corners[i], corners[(i + 4) % 8], greenColour);
        }

        _debugFrustumPrimitive->fromLines(lines);
        subPassesInOut.back()._commands.push_back(_debugFrustumPrimitive->toDrawCommand());
    }
}

/// Render all of our immediate mode primitives. This isn't very optimised and
/// most are recreated per frame!
void GFXDevice::debugDraw(const SceneRenderState& sceneRenderState, const Camera& activeCamera, RenderSubPassCmds& subPassesInOut) {
    if (Config::Build::IS_DEBUG_BUILD) {
        drawDebugFrustum(subPassesInOut);

        // Debug axis form the axis arrow gizmo in the corner of the screen
        // This is togglable, so check if it's actually requested
        if (BitCompare(to_uint(sceneRenderState.gizmoState()),
                       to_const_uint(SceneRenderState::GizmoState::SCENE_GIZMO))) {

            // Apply the inverse view matrix so that it cancels out in the shader
            // Submit the draw command, rendering it in a tiny viewport in the lower
            // right corner
            U16 windowWidth = renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).getWidth();
            _axisGizmo->fromLines(_axisLines, vec4<I32>(windowWidth - 120, 8, 128, 128));
        
            // We need to transform the gizmo so that it always remains axis aligned
            // Create a world matrix using a look at function with the eye position
            // backed up from the camera's view direction
            _axisGizmo->worldMatrix(mat4<F32>(-activeCamera.getForwardDir() * 2,
                                               VECTOR3_ZERO,
                                               activeCamera.getUpDir()) * getMatrix(MATRIX::VIEW_INV));
            _axisGizmo->paused(false);
        
            subPassesInOut.back()._commands.push_back(_axisGizmo->toDrawCommand());
        } else {
            _axisGizmo->paused(true);
        }
    }
}

};

Commits for Divide-Framework/trunk/Source Code/Platform/Video/GFXDeviceDebug.cpp

Diff revisions: vs.
Revision Author Commited Message
847 Diff Diff IonutCava picture IonutCava Sun 05 Feb, 2017 21:16:24 +0000

[IonutCava]
- Code rot fixes:
— Terrain loading (8 bit heightmap only for now)
— Terrain rendering
— Water Plane loading and rendering
— Reflection and Refraction rendering passes (hack for now: need environment cubemaps as separate from reflect/refract maps for planar rendering)
-— ToDo: Separate Reflection / Refraction render targets to Planar R/R and Cube R/R. Environment probes should use Cube Reflections, Water should use planar reflection targets.
- Added a way to register debug views: texture, shader and params. Viewports get automatically scaled and positioned
— ToDo: Add a hover-preview feature
— ToDo: Add a click-lock preview feature

825 Diff Diff IonutCava picture IonutCava Fri 20 Jan, 2017 14:35:31 +0000

[IonutCava]
- Small corrections and optimizations to the TaskPool
- Fix buffer update bug in LightPool

809 Diff Diff IonutCava picture IonutCava Tue 10 Jan, 2017 17:16:26 +0000

[IonutCava]
- Move velocity calc to the normal colour pass.
- Optimise glFramebuffer and cleanup RTAttachment class

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
787 Diff Diff IonutCava picture IonutCava Wed 19 Oct, 2016 16:13:09 +0000

[IonutCava]
- Added a Frustum debug rendering system

784 Diff Diff IonutCava picture IonutCava Mon 17 Oct, 2016 16:20:49 +0000

[IonutCava]
- Removed the CameraManager and move most of its functionality into static members of the Camera class
- Removed Camera push/pop system in favour of a stateless ptr based system to better fit the RenderPass structure

777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

776 Diff Diff IonutCava picture IonutCava Thu 06 Oct, 2016 15:57:56 +0000

[IonutCava]
- Improve the CommandBuffer system to include the notion of a RenderPass /RenderSubPass with output render target info stored in them (not used yet)

771 Diff Diff IonutCava picture IonutCava Tue 27 Sep, 2016 15:39:49 +0000

[IonutCava]
- Modify GFXDevice::flushRenderQueues so that it creates command buffers instead of directly calling rendering calls:
— Command buffers contain buffer, shader, texture and geometry info
— Command buffer state is now parsed and set at the API level instead of GFXDevice level
— This will allow easier porting to low level APIs later on
- Indirect draw is now a GenericDrawCommand render option instead of an explicit buffer draw parameter

770 IonutCava picture IonutCava Tue 20 Sep, 2016 16:12:27 +0000

[IonutCava]
- Prepare velocity map calculation (later used for temporal AA and motion blur):
— Add a previous depth buffer render target that blits the main depth buffer at the end of the frame
— Add a new render target to the screen FBO: velocity map
- Store normals as RG instead of RGB and pack/unpack in shaders. (compute >>>> bandwith)
- Rename Forward+ renderer to something more descriptive

(Requires deletion of all parsed & cached data)