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
#include "Headers/SingleShadowMap.h"

#include "Scenes/Headers/SceneState.h"
#include "Core/Headers/ParamHandler.h"
#include "Managers/Headers/SceneManager.h"
#include "Rendering/Headers/Renderer.h"
#include "Rendering/Camera/Headers/Camera.h"
#include "Rendering/Lighting/Headers/Light.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"

namespace Divide {

SingleShadowMap::SingleShadowMap(Light* light, Camera* shadowCamera)
    : ShadowMap(light, shadowCamera, SHADOW_TYPE_Single) {
    Console::printfn(Locale::get("LIGHT_CREATE_SHADOW_FB"), light->getGUID(),
                     "Single Shadow Map");
    ResourceDescriptor shadowPreviewShader("fbPreview.LinearDepth");
    shadowPreviewShader.setThreadedLoading(false);
    _previewDepthMapShader = CreateResource<ShaderProgram>(shadowPreviewShader);
    SamplerDescriptor depthMapSampler;
    depthMapSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
    depthMapSampler.toggleMipMaps(false);
    depthMapSampler._useRefCompare = true;
    depthMapSampler._cmpFunc = CMP_FUNC_LEQUAL;
    // Default filters, LINEAR is OK for this
    TextureDescriptor depthMapDescriptor(TEXTURE_2D, DEPTH_COMPONENT,
                                         UNSIGNED_INT);

    depthMapDescriptor.setSampler(depthMapSampler);
    _depthMap = GFX_DEVICE.newFB();
    _depthMap->AddAttachment(depthMapDescriptor, TextureDescriptor::Depth);
    _depthMap->toggleColorWrites(false);
}

SingleShadowMap::~SingleShadowMap() { RemoveResource(_previewDepthMapShader); }

void SingleShadowMap::init(ShadowMapInfo* const smi) {
    resolution(smi->resolution(), _light->shadowMapResolutionFactor());
    _init = true;
}

void SingleShadowMap::resolution(U16 resolution, U8 resolutionFactor) {
    U16 resolutionTemp = resolution * resolutionFactor;
    if (resolutionTemp != _resolution) {
        _resolution = resolutionTemp;
        // Initialize the FB's with a variable resolution
        Console::printfn(Locale::get("LIGHT_INIT_SHADOW_FB"),
                         _light->getGUID());
        _depthMap->Create(_resolution, _resolution);
    }

    ShadowMap::resolution(resolution, resolutionFactor);
}

void SingleShadowMap::render(SceneRenderState& renderState,
                             const DELEGATE_CBK<>& sceneRenderFunction) {
    /// Only if we have a valid callback;
    if (!sceneRenderFunction) {
        Console::errorfn(Locale::get("ERROR_LIGHT_INVALID_SHADOW_CALLBACK"),
                         _light->getGUID());
        return;
    }

    renderState.getCameraMgr().pushActiveCamera(_shadowCamera, false);
    renderInternal(renderState, sceneRenderFunction);
    renderState.getCameraMgr().popActiveCamera(false);
}

void SingleShadowMap::renderInternal(
    const SceneRenderState& renderState,
    const DELEGATE_CBK<>& sceneRenderFunction) {
    _shadowCamera->lookAt(_light->getPosition(),
                          _light->getPosition() * _light->getDirection());
    _shadowCamera->setProjection(1.0f, 90.0f,
                                 vec2<F32>(1.0, _light->getRange()));
    _shadowCamera->renderLookAt();

    _depthMap->Begin(Framebuffer::defaultPolicy());
    // draw the scene
    GFX_DEVICE.getRenderer().render(sceneRenderFunction, renderState);
    // unbind the associated depth map
    _depthMap->End();
    LightManager::getInstance().registerShadowPass();
}

void SingleShadowMap::previewShadowMaps() {
    _depthMap->Bind(ShaderProgram::TEXTURE_UNIT0);
    GFX_DEVICE.drawPoints(1, GFX_DEVICE.getDefaultStateBlock(true),
                          _previewDepthMapShader);
}
};

Commits for Divide-Framework/trunk/Source Code/Rendering/Lighting/ShadowMapping/SingleShadowMap.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

343 Diff Diff IonutCava picture IonutCava Thu 15 Jan, 2015 17:30:12 +0000

[Ionut]
- Refactored 2 singletons into static classes (Console and TerrainLoader)
- Changed some C-casts to static_casts
- Updated copyright notices

334 Diff Diff IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project

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)

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

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 Diff Diff 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)

296 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Aug, 2014 14:54:21 +0000

[Ionut]
- nVidia compatibility fixes (GUI, shadows, post-processing)
- Texture bind slots are now part of ShaderProgram class
- Renamed ForwardRenderer class to ForwardPlusRenderer and moved ligh grid creation to it
- More code cleanups and comments

292 k1ngp1n picture k1ngp1n Mon 28 Jul, 2014 20:23:56 +0000

[Ionut]
- More nVidia compatibility issues (including the ability to disable persistent mapped buffer altogether. Thanks nsight ....)
- Cross-platform compatibility fixes for types (custom types now mirror types in stdint.h and are now typdefed instead of defined)
- Removed redundant files