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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
   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 DIVIDE_LIGHT_H_
#define DIVIDE_LIGHT_H_

#include "config.h"

#include "Graphs/Headers/SceneNode.h"
#include "Rendering/Lighting/ShadowMapping/Headers/ShadowMap.h"

namespace Divide {

/// The different types of lights supported
enum class LightType : U32 {
    DIRECTIONAL = 0,
    POINT = 1,
    SPOT = 2,
    COUNT
};

class Camera;
class LightPool;
class ImpostorSphere;
class SceneRenderState;
/// A light object placed in the scene at a certain position
class Light : public SceneNode {
   public:
       struct ShadowProperties {
           vec4<U32> _arrayOffset;
           /// light viewProjection matrices
           mat4<F32> _lightVP[Config::Lighting::MAX_SPLITS_PER_LIGHT];
           /// light's position in world space
           vec4<F32> _lightPosition[Config::Lighting::MAX_SPLITS_PER_LIGHT];
           /// random float values (e.g. split distances)
           vec4<F32> _floatValues[Config::Lighting::MAX_SPLITS_PER_LIGHT];

           inline void set(const ShadowProperties& other) {
               _arrayOffset.set(other._arrayOffset);
               for (U8 i = 0; i < Config::Lighting::MAX_SPLITS_PER_LIGHT; ++i) {
                   _lightVP[i].set(other._lightVP[i]);
                   _lightPosition[i].set(other._lightPosition[i]);
                   _floatValues[i].set(other._floatValues[i]);
               }
           }
       };

    typedef vectorImpl<Light*> LightList;

    /// Create a new light assigned to the specified slot with the specified range
    /// @param slot = the slot the light is assigned to (as in OpenGL slot for example)
    /// @param range = the light influence range (for spot/point lights)
    explicit Light(ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, const F32 range, const LightType& type, LightPool& parentPool);
    virtual ~Light();

    /// Is the light a shadow caster?
    inline bool castsShadows() const { return _castsShadows; }

    inline F32 getRange() const { return _positionAndRange.w; }

    void setRange(F32 range);

    /// Get light diffuse colour
    inline void getDiffuseColour(vec3<F32>& colourOut) const {
        Util::ToFloatColour(_colour.rgb(), colourOut);
    }

    inline vec3<F32> getDiffuseColour() const {
        return Util::ToFloatColour(_colour.rgb());
    }

    void setDiffuseColour(const vec3<U8>& newDiffuseColour);

    inline void setDiffuseColour(const vec4<U8>& newDiffuseColour) {
        setDiffuseColour(newDiffuseColour.rgb());
    }

    inline void setDiffuseColour(const vec4<F32>& newDiffuseColour) {
        setDiffuseColour(newDiffuseColour.rgb());
    }

    inline void setDiffuseColour(const vec3<F32>& newDiffuseColour) {
        setDiffuseColour(Util::ToByteColour(newDiffuseColour));
    }

    /// Get light position for omni and spot or direction for a directional light
    inline vec3<F32> getPosition() const { return _positionAndRange.xyz(); }

    /// Get direction for spot lights
    inline vec3<F32> getSpotDirection() const { return _spotProperties.xyz(); }

    inline F32 getSpotAngle() const { return _spotProperties.w; }

    void setSpotAngle(F32 newAngle);

    inline F32 getSpotCosOuterConeAngle() const { return _spotCosOuterConeAngle; }

    void setSpotCosOuterConeAngle(F32 newCosAngle);

    /// Light state (on/off)
    inline void toggleEnabled() { setEnabled(!getEnabled()); }

    inline bool getEnabled() const { return _enabled; }

    /// Does this list cast shadows?
    inline void setCastShadows(const bool state) { _castsShadows = state; }

    /// Draw a sphere at the lights position
    /// The impostor has the range of the light's effect range and the diffuse
    /// colour as the light's diffuse property
    inline void setDrawImpostor(const bool state) { _drawImpostor = state; }

    /// Turn the light on/off
    inline void setEnabled(const bool state) { _enabled = state; }

    /// Get the light type. (see LightType enum)
    inline const LightType& getLightType() const { return _type; }

    /// Get a pointer to the light's impostor
    inline ImpostorSphere* const getImpostor() const { return _impostor.get(); }

    bool onRender(SceneGraphNode& sgn,
                  const SceneRenderState& sceneRenderState,
                  const RenderStagePass& renderStagePass) override;

    /// SceneNode concrete implementations
    bool unload() override;

    void updateBoundsInternal(SceneGraphNode& sgn);

    void sceneUpdate(const U64 deltaTime,
                     SceneGraphNode& sgn,
                     SceneState& sceneState) override;

    /*----------- Shadow Mapping-------------------*/
    /// Set the function used to generate shadows for this light
    inline ShadowMapInfo* getShadowMapInfo() const { return _shadowMapInfo; }

    void addShadowMapInfo(ShadowMapInfo* const shadowMapInfo);
    bool removeShadowMapInfo();

    void validateOrCreateShadowMaps(GFXDevice& context, SceneRenderState& sceneRenderState);
    virtual void generateShadowMaps(U32 passIdx, GFX::CommandBuffer& bufferInOut);

    inline const ShadowProperties& getShadowProperties() const {
        return _shadowProperties;
    }

    inline const mat4<F32>& getShadowVPMatrix(U8 index) const {
        return _shadowProperties._lightVP[index];
    }

    inline const vec4<F32>& getShadowFloatValues(U8 index) const {
        return _shadowProperties._floatValues[index];
    }

    inline const vec4<F32>& getShadowLightPos(U8 index) const {
        return _shadowProperties._lightPosition[index];
    }

    inline void setShadowVPMatrix(U8 index, const mat4<F32>& newValue) {
        _shadowProperties._lightVP[index].set(newValue);
    }

    inline void setShadowFloatValue(U8 index, F32 newValue) {
        _shadowProperties._floatValues[index].set(newValue);
    }

    inline void setShadowFloatValue(U8 index, const vec4<F32>& newValue) {
        _shadowProperties._floatValues[index].set(newValue);
    }

    inline void setShadowLightPos(U8 index, const vec3<F32>& newValue) {
        _shadowProperties._lightPosition[index].set(newValue, 1.0f);
    }

   protected:
    friend class LightPool;
    template <typename T>
    friend class ImplResourceLoader;
    bool load(const DELEGATE_CBK<void, CachedResource_wptr>& onLoadCallback) override;
    void postLoad(SceneGraphNode& sgn) override;

    /// Set light type
    /// @param type Directional/Spot/Omni (see LightType enum)
    inline void setLightType(LightType type) {
        _type = type;
    }

    void updateImpostor();

   protected:
    bool _spotPropertiesChanged;
    /// Used to generate spot light penumbra using D3D's dual-cone method
    F32 _spotCosOuterConeAngle;
    /// xyz - position/direction, w - range
    vec4<F32> _positionAndRange;
    /// xyz - direction, w - cone angle
    vec4<F32> _spotProperties;
    /// rgb - diffuse, w - reserved
    vec4<U8>  _colour;
    // does this light casts shadows?
    bool _castsShadows;
    // Shadow mapping properties
    ShadowProperties _shadowProperties;

    ShadowMapInfo* _shadowMapInfo;

    LightType _type;

   private:
    bool _rangeChanged;
    bool _drawImpostor;
    /// Used for debug rendering
    std::shared_ptr<ImpostorSphere> _impostor;
    SceneGraphNode_wptr _impostorSGN;
    ShadowCameraPool _shadowCameras;
    LightPool& _parentPool;
    bool _enabled;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(Light);

};  // namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

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.

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

883 Diff Diff IonutCava picture IonutCava Fri 24 Mar, 2017 17:15:58 +0000

[IonutCava]
- More terrain work
- Removed GS-based multi pass for shadows. Replaced with a regular multi-draw submit system (ease-of-use reasons)

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

860 Diff Diff IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks

858 Diff Diff IonutCava picture IonutCava Sun 12 Feb, 2017 20:55:05 +0000

[IonutCava]
- More resource loading updates

856 Diff Diff IonutCava picture IonutCava Fri 10 Feb, 2017 17:19:06 +0000

[IonutCava]
- Attempt to improve resource creation mechanism by adding a callback for when the resource finishes loading
— This is useful for multi-threaded loading: shaders, textures, terrain, etc

851 IonutCava picture IonutCava Mon 06 Feb, 2017 23:38:14 +0000

[IonutCava]
- Replaced most RenderStage params with RenderStagePass types
- More work on water rendering