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
/*
   Copyright (c) 2015 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_MANAGER_H_
#define _LIGHT_MANAGER_H_

#include "Rendering/Lighting/Headers/Light.h"

namespace Divide {

class ShaderBuffer;
class SceneGraphNode;
class SceneRenderState;

DEFINE_SINGLETON(LightManager)
  protected:
      struct LightProperties {
          /// rgb = diffuse
          /// w = cosOuterConeAngle;
          vec4<F32> _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:
    void init();

    /// 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_uint(type)] = state;
    }
    inline bool lightTypeEnabled(LightType type) const {
        return _lightTypeState[to_uint(type)];
    }
    /// Retrieve the number of active lights in the scene;
    inline const U32 getActiveLightCount(LightType type) const { return _activeLightCount[to_uint(type)]; }
    inline Light* currentShadowCastingLight() const { return _currentShadowCastingLight; }

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

    /// shadow mapping
    void bindShadowMaps();
    bool shadowMappingEnabled() const;

    /// shadow mapping
    void previewShadowMaps(Light* light);
    void togglePreviewShadowMaps();

    void updateAndUploadLightData(const vec3<F32>& eyePos, const mat4<F32>& viewMatrix);
    void uploadLightData(ShaderBufferLocation location);

    /// Get the appropriate shadow bind slot for every light's shadow
    U8 getShadowBindSlotOffset(ShadowType type);
    /// Get the appropriate shadow bind slot offset for every light's shadow
    inline 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);
        };
    }

    void drawLightImpostors() const;

  protected:
    friend class RenderPass;
    bool generateShadowMaps();

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

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

    LightManager();
    ~LightManager();

  private:
    std::array<bool, to_const_uint(LightType::COUNT)> _lightTypeState;
    std::array<Light::LightList, to_const_uint(LightType::COUNT)> _lights;
    bool _init;
    bool _previewShadowMaps;
    bool _shadowMapsEnabled;
    Texture* _lightIconsTexture;
    Light* _currentShadowCastingLight;
    ShaderProgram* _lightImpostorShader;
    std::array<U32, to_const_uint(LightType::COUNT)> _activeLightCount;

    std::array<ShaderBuffer*, to_const_uint(ShaderBufferType::COUNT)>  _lightShaderBuffer;
    std::array<U8, to_const_uint(ShadowType::COUNT)> _shadowLocation;

    typedef std::array<LightProperties, Config::Lighting::MAX_POSSIBLE_LIGHTS> LightPropertiesArray;
    std::array<LightPropertiesArray, to_const_uint(LightType::COUNT)> _lightProperties;
    std::array<Light::ShadowProperties, Config::Lighting::MAX_POSSIBLE_LIGHTS> _lightShadowProperties;
    std::array<Light*, Config::Lighting::MAX_SHADOW_CASTING_LIGHTS> _shadowCastingLights;
    vectorImpl<std::future<void>> _lightSortingTasks;
END_SINGLETON

};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Managers/Headers/LightManager.h

Diff revisions: vs.
Revision Author Commited Message
631 Diff Diff IonutCava picture IonutCava Sun 24 Jan, 2016 20:28:21 +0000

[IonutCava]
- Fix and optimize particle rendering system
- Temporarily disable Z_PRE_PASS system for testing
- Improve thread pool destruction system a bit
- Fix texture loading when used as fb attachment
- Forward+ renderer now takes the entire light buffer (no need to split up by light type)
- Start work on occlusion culling fixes:
— ToDo: Take into account batching system
— Fix gl_DrawIDARB usage

625 Diff Diff IonutCava picture IonutCava Mon 18 Jan, 2016 17:19:59 +0000

[IonutCava]
- Limit number of shader compilations per frame
- Add initial support for deferred SGN postLoad calls (think multi-threaded loading support in the future)
- Various small profile-guided optimizations
- Removed some indirections in draw command submission

622 Diff Diff IonutCava picture IonutCava Thu 14 Jan, 2016 17:18:49 +0000

[IonutCava]
- Remove onCameraUpdate call from LightManager and SceneGraph as it’s not needed
- Remove special threading handlers from Resource class as very few derived classes use them for now
— Use ResourceState to check current loading state
- Use insertion sort for particles as most entries should already be sorted from the previous frame
- Use async RenderBin sorting system

601 Diff Diff IonutCava picture IonutCava Wed 09 Dec, 2015 17:12:38 +0000

[IonutCava]
- Shadow mapping system improvements:
— Point and spot light support
— Variable number of debug preview planes
- Light impostor rendering fix and update:
— Displays coloured icons for point and spot lights
- Camera system improvement:
— Camera manager is the only class allowed to instantiate new cameras
- Initial dual paraboloid rendering code
- Remove discard statements from shader code (should use blending if visual artefacts are encountered)

600 Diff Diff IonutCava picture IonutCava Tue 08 Dec, 2015 17:22:11 +0000

[IonutCava]
- Cleanup SceneGraphNode class
- Rework AABB calculation and update system and fix various AABB problems (e.g. light AABB, parent mesh AABB, etc)
- Create a list of closest shadow casting lights for faster shadow map generation
- Texture creation bug fixed (related to descriptor enum value)
- Better FPS and Frametime calculation system

597 Diff Diff IonutCava picture IonutCava Sun 06 Dec, 2015 21:20:04 +0000

[IonutCava]
- Secondary light impostor rendering system

593 Diff Diff IonutCava picture IonutCava Thu 03 Dec, 2015 17:17:30 +0000

[IonutCava]
- Culling, light rendering, physics transforms and impostor updates

588 Diff Diff IonutCava picture IonutCava Mon 30 Nov, 2015 17:11:02 +0000

[IonutCava]
- More work on the Forward+ renderer

587 Diff Diff IonutCava picture IonutCava Fri 27 Nov, 2015 17:00:25 +0000

[IonutCava]
- Finished multi-light rendering:
— Proper position/distance transform (homogeneous trans for positions / non-homogeneous trans for directions)
-— Point lights with range based attenuation
-— Spot lights with inner and outer cones for smooth falloff
-— Directional lights same as before
- Added a basic Flashlight system: spot light at the camera’s position facing forward (toggled with L key)
- WarScene updated:
— 16 point lights moving around the scene with random colours

572 IonutCava picture IonutCava Wed 18 Nov, 2015 17:15:43 +0000

[Ionut]
- Attempt to pack all shadowmaps in Shadowmap arrays
- Cleanup lighting and material info
- Fix light impostor rendering