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
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _LIGHT_POOL_H_
#define _LIGHT_POOL_H_

#include "config.h"

#include "Scenes/Headers/SceneComponent.h"
#include "Rendering/Lighting/Headers/Light.h"
#include "Platform/Threading/Headers/Task.h"

namespace Divide {

namespace Time {
    class ProfileTimer;
};

class ShaderBuffer;
class SceneGraphNode;
class SceneRenderState;

class LightPool : public SceneComponent {
  protected:
      struct LightProperties {
          /// rgb = diffuse
          /// w = cosOuterConeAngle;
          FColour _diffuse;
          /// light position (or direction for Directional lights)
          /// w = range
          vec4<F32> _position;
          /// xyz = spot direction
          /// w = spot angle
          vec4<F32> _direction;
          /// x = light type: 0.0 - directional, 1.0  - point, 2.0 - spot#
          /// y = casts shadows, 
          /// z - shadow block index
          /// w - reserved;
          vec4<I32> _options;

          inline void set(const LightProperties& other) {
              _diffuse.set(other._diffuse);
              _position.set(other._position);
              _direction.set(other._direction);
              _options.set(other._options);
          }
      };



  public:
    enum class ShaderBufferType : U32 {
        NORMAL = 0,
        SHADOW = 1,
        COUNT
    };

    explicit LightPool(Scene& parentScene, GFXDevice& context);
    ~LightPool();

    /// Add a new light to the manager
    bool addLight(Light& light);
    /// remove a light from the manager
    bool removeLight(I64 lightGUID, LightType type);
    /// disable or enable a specific light type
    inline void toggleLightType(LightType type) {
        toggleLightType(type, !lightTypeEnabled(type));
    }
    inline void toggleLightType(LightType type, const bool state) {
        _lightTypeState[to_U32(type)] = state;
    }
    inline bool lightTypeEnabled(LightType type) const {
        return _lightTypeState[to_U32(type)];
    }
    /// Retrieve the number of active lights in the scene;
    inline const U32 getActiveLightCount(LightType type) const { return _activeLightCount[to_U32(type)]; }

    bool clear();
    inline Light::LightList& getLights(LightType type) { return _lights[to_U32(type)]; }
    Light* getLight(I64 lightGUID, LightType type);

    void prepareLightData(const vec3<F32>& eyePos, const mat4<F32>& viewMatrix);
    void uploadLightData(ShaderBufferLocation lightDataLocation,
                         ShaderBufferLocation shadowDataLocation);

    void drawLightImpostors(GFX::CommandBuffer& bufferInOut) const;

    static void idle();
    /// shadow mapping
    static void bindShadowMaps(GFXDevice& context, GFX::CommandBuffer& bufferInOut);
    static void togglePreviewShadowMaps(GFXDevice& context);

    /// Get the appropriate shadow bind slot for every light's shadow
    static U8 getShadowBindSlotOffset(ShadowType type) {
        return _shadowLocation[to_U32(type)];
    }

    /// Get the appropriate shadow bind slot offset for every light's shadow
    static U8 getShadowBindSlotOffset(LightType lightType) {
        switch (lightType) {
            default:
            case LightType::SPOT:
                return getShadowBindSlotOffset(ShadowType::SINGLE);
            case LightType::POINT:
                return getShadowBindSlotOffset(ShadowType::CUBEMAP);
            case LightType::DIRECTIONAL:
                return getShadowBindSlotOffset(ShadowType::LAYERED);
        };
    }

    static Light* currentShadowCastingLight() { 
        return _currentShadowCastingLight;
    }

  protected:
    friend class SceneManager;
    bool generateShadowMaps(SceneRenderState& sceneRenderState, GFX::CommandBuffer& bufferInOut);

    inline Light::LightList::const_iterator findLight(I64 GUID, LightType type) const {
        return std::find_if(std::begin(_lights[to_U32(type)]), std::end(_lights[to_U32(type)]),
                            [&GUID](Light* const light) {
                                return (light && light->getGUID() == GUID);
                            });
    }

  private:
      void init();
      void waitForTasks();
      void uploadLightBuffers();

  private:
    GFXDevice& _context;

    vectorImpl<TaskHandle> _lightUpdateTask;

    bool _buffersUpdated;
    std::array<bool, to_base(LightType::COUNT)> _lightTypeState;
    std::array<Light::LightList, to_base(LightType::COUNT)> _lights;
    bool _init;
    Texture_ptr _lightIconsTexture;
    ShaderProgram_ptr _lightImpostorShader;
    std::array<U32, to_base(LightType::COUNT)> _activeLightCount;

    std::array<ShaderBuffer*, to_base(ShaderBufferType::COUNT)>  _lightShaderBuffer;

    typedef vectorImpl<LightProperties> LightPropertiesVec;
    typedef vectorImpl<Light::ShadowProperties> LightShadowProperties;
    typedef vectorImpl<Light*> LightVec;

    LightVec _sortedLights;
    LightVec _sortedShadowCastingLights;
    LightPropertiesVec _sortedLightProperties;
    LightShadowProperties _sortedShadowProperties;

    Time::ProfileTimer& _shadowPassTimer;

    static bool _previewShadowMaps;
    static Light* _currentShadowCastingLight;
    static std::array<U8, to_base(ShadowType::COUNT)> _shadowLocation;
};

};  // namespace Divide

#endif //_LIGHT_POOL_H_

Commits for Divide-Framework/trunk/Source Code/Rendering/Lighting/Headers/LightPool.h

Diff revisions: vs.
Revision Author Commited Message
1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

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)

893 Diff Diff IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

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

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

828 Diff Diff IonutCava picture IonutCava Mon 23 Jan, 2017 17:19:22 +0000

[Ionut]
- XML loading/saving cleanup PART I

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

823 IonutCava picture IonutCava Wed 18 Jan, 2017 17:11:00 +0000

[IonutCava]
- Fix some issues with Camera initialisation code.
- ToDo: Cleanup camera class. (e.g. setRotation / setGlobalRotation calls)