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
#include "stdafx.h"

#include "Headers/Sky.h"

#include "Managers/Headers/SceneManager.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Geometry/Material/Headers/Material.h"
#include "Platform/File/Headers/FileManagement.h"
#include "Platform/Video/Headers/RenderStateBlock.h"
#include "Geometry/Shapes/Predefined/Headers/Sphere3D.h"

namespace Divide {

Sky::Sky(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, U32 diameter)
    : SceneNode(parentCache, descriptorHash, name, SceneNodeType::TYPE_SKY),
      _context(context),
      _sky(nullptr),
      _skyShader(nullptr),
      _skyShaderPrePass(nullptr),
      _skybox(nullptr),
      _diameter(diameter)
{
    _renderState.addToDrawExclusionMask(RenderStage::SHADOW);

    // Generate a render state
    RenderStateBlock skyboxRenderState;
    skyboxRenderState.setCullMode(CullMode::CCW);
    skyboxRenderState.setZFunc(ComparisonFunction::LESS);
    _skyboxRenderStateHashPrePass = skyboxRenderState.getHash();
    skyboxRenderState.setZFunc(ComparisonFunction::LEQUAL);
    _skyboxRenderStateHash = skyboxRenderState.getHash();

    skyboxRenderState.setCullMode(CullMode::CW);
    _skyboxRenderStateReflectedHash = skyboxRenderState.getHash();
}

Sky::~Sky()
{
}

bool Sky::load(const DELEGATE_CBK<void, CachedResource_wptr>& onLoadCallback) {
    if (_sky != nullptr) {
        return false;
    }

    SamplerDescriptor skyboxSampler;
    skyboxSampler.setFilters(TextureFilter::LINEAR);
    skyboxSampler.setAnisotropy(0);
    skyboxSampler.setWrapMode(TextureWrap::CLAMP_TO_EDGE);
    skyboxSampler.toggleSRGBColourSpace(true);

    TextureDescriptor skyboxTexture(TextureType::TEXTURE_CUBE_MAP);
    skyboxTexture.setSampler(skyboxSampler);

    ResourceDescriptor skyboxTextures("SkyboxTextures");
    skyboxTextures.setResourceName("skybox_1.jpg, skybox_2.jpg, skybox_3.jpg, skybox_4.jpg, skybox_5.jpg, skybox_6.jpg");
    skyboxTextures.setResourceLocation(Paths::g_assetsLocation + Paths::g_imagesLocation);
    skyboxTextures.setPropertyDescriptor(skyboxTexture);

    _skybox = CreateResource<Texture>(_parentCache, skyboxTextures);

    F32 radius = _diameter * 0.5f;

    ResourceDescriptor skybox("SkyBox");
    skybox.setFlag(true);  // no default material;
    skybox.setID(4); // resolution
    skybox.setEnumValue(to_U32(radius)); // radius
    _sky = CreateResource<Sphere3D>(_parentCache, skybox);
    _sky->renderState().setDrawState(false);

    ResourceDescriptor skyShaderDescriptor("sky.Display");
    _skyShader = CreateResource<ShaderProgram>(_parentCache, skyShaderDescriptor);

    ResourceDescriptor skyShaderPrePassDescriptor("sky.PrePass");
    _skyShaderPrePass = CreateResource<ShaderProgram>(_parentCache, skyShaderPrePassDescriptor);

    assert(_skyShader && _skyShaderPrePass);
    _boundingBox.set(vec3<F32>(-radius), vec3<F32>(radius));
    Console::printfn(Locale::get(_ID("CREATE_SKY_RES_OK")));

    return SceneNode::load(onLoadCallback);
}

void Sky::postLoad(SceneGraphNode& sgn) {
    static const U32 normalMask = to_base(ComponentType::TRANSFORM) |
                                  to_base(ComponentType::BOUNDS) |
                                  to_base(ComponentType::RENDERING) |
                                  to_base(ComponentType::NAVIGATION);

    assert(_sky != nullptr);

    sgn.addNode(_sky, normalMask, PhysicsGroup::GROUP_IGNORE);

    RenderingComponent* renderable = sgn.get<RenderingComponent>();
    if (renderable) {
        renderable->toggleRenderOption(RenderingComponent::RenderOptions::CAST_SHADOWS, false);
        renderable->registerTextureDependency(_skybox->getData(),
                                              to_U8(ShaderProgram::TextureUsage::UNIT0));
    }

    SceneNode::postLoad(sgn);
}

bool Sky::onRender(SceneGraphNode& sgn,
                   const SceneRenderState& sceneRenderState,
                   const RenderStagePass& renderStagePass) {
    return _sky->onRender(sgn, sceneRenderState, renderStagePass);
}

void Sky::buildDrawCommands(SceneGraphNode& sgn,
                            const RenderStagePass& renderStagePass,
                            RenderPackage& pkgInOut) {
    if (renderStagePass.stage() == RenderStage::SHADOW) {
        return;
    }

    GenericDrawCommand cmd;
    cmd.sourceBuffer(_sky->getGeometryVB());
    cmd.cmd().indexCount = _sky->getGeometryVB()->getIndexCount();

    GFX::DrawCommand drawCommand;
    drawCommand._drawCommands.push_back(cmd);
    pkgInOut.addDrawCommand(drawCommand);

    const Pipeline* pipeline = pkgInOut.pipeline(0);
    PipelineDescriptor pipeDesc = pipeline->descriptor();
    if (renderStagePass.pass() == RenderPassType::DEPTH_PASS) {
        pipeDesc._stateHash = _skyboxRenderStateHashPrePass;
        pipeDesc._shaderProgram = _skyShaderPrePass;
    } else {
        pipeDesc._stateHash = (renderStagePass.stage() == RenderStage::REFLECTION
                                                        ? _skyboxRenderStateReflectedHash
                                                        : _skyboxRenderStateHash);
        pipeDesc._shaderProgram = _skyShader;
    }

    pkgInOut.pipeline(0, _context.newPipeline(pipeDesc));

    SceneNode::buildDrawCommands(sgn, renderStagePass, pkgInOut);
}

};

Commits for Divide-Framework/trunk/Source Code/Environment/Sky/Sky.cpp

Diff revisions: vs.
Revision Author Commited Message
996 Diff Diff IonutCava picture IonutCava Tue 12 Dec, 2017 17:16:54 +0000

[Ionut]
- Update and improve SGN creation and destruction
- Fix cleanup issues
- Fix GPU object memory leaks
- Fix duplicate GUID values being generated
- Misc cleanups and optimizations

994 Diff Diff IonutCava picture IonutCava Mon 11 Dec, 2017 18:01:11 +0000

[Ionut]
- Moved remaining components to new ECS system
- Started cleaning up code that was made redundant by the ECS system

992 Diff Diff IonutCava picture IonutCava Thu 07 Dec, 2017 18:01:51 +0000

[Ionut]
- Split PhysicsComponent into 2, ECS-based, components: TransformComponent and RigidBodyComponent
UNTESTED

953 Diff Diff IonutCava picture IonutCava Sat 28 Oct, 2017 21:57:10 +0000

[Ionut]
- Fix blinking issue by caching and hashing pipelines to that we don’t overwrite pipelines used by other elements

950 Diff Diff IonutCava picture IonutCava Sun 22 Oct, 2017 22:25:05 +0000

[Ionut]
- Revamp camera management
- More work on improving the command buffer system:
— Performance tweaks
— Validation
— Debug features
- Some code cleanup for Object3D stuff (preRender/onRender changes)

Still haven’t fixed random flashing issue

948 Diff Diff IonutCava picture IonutCava Tue 17 Oct, 2017 22:41:09 +0000

[Ionut]
- Move rendering data caching outside of CommandBuffer and into RenderPackage for better control.

943 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 11:38:52 +0000

[IonutCava]
- Rework ThreadPool/Task system for clearer parent<->child relationship between tasks
— Disable Prio pool since it doesn’t work properly with the newest boost libraries
— Modify the C++11 threadpool to remove the boost dependency
- Reduce memory usage by allocating command buffers on use instead of on creation

938 Diff Diff IonutCava picture IonutCava Wed 16 Aug, 2017 21:35:55 +0000

[Ionut]
- Separate texture binding slot from TextureData
- Binding slot is now a property of the descriptor set
- Remove bind() calls from texture’s public interface
ToDo
- Add image layer binding options (addTextureLayer(data, binding, layer, ...)

933 Diff Diff IonutCava picture IonutCava Tue 15 Aug, 2017 00:02:05 +0000

[Ionut]
- CommandBuffer Part 2/3: code compiles and splash screen renders and application doesn’t crash (still has drawing issues)

930 IonutCava picture IonutCava Sun 13 Aug, 2017 20:33:31 +0000

[Ionut]
- Fix a bug with Push Constant to Uniform conversion
- Add more push constant types
- Fix RENDER_INDIRECT param for draw commands
- Cleanup Sky, Terrain and Vegetation a bit