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
/*
   Copyright (c) 2013 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 "core.h"
#include "Graphs/Headers/SceneNode.h"

///The different types of lights supported
enum LightType{
	LIGHT_TYPE_DIRECTIONAL = 0,
	LIGHT_TYPE_POINT = 1, ///< or omni light, if you prefer
	LIGHT_TYPE_SPOT = 2,
	LIGHT_TYPE_PLACEHOLDER
};

enum LightMode{
	LIGHT_MODE_SIMPLE = 0,    ///< normal light. Can't be moved or changed at runtime
	LIGHT_MODE_TOGGLABLE = 1, ///< can be switched on or off and can change brightness,color, range at runtime
	LIGHT_MODE_MOVABLE = 2,   ///< can change position at runtime / most expensive
	LIGHT_MODE_DOMINANT = 3   ///< only shadow caster in scene
};

///Defines all light properties that are stores as a 3 or 4 component vector
enum LightPropertiesV{
	LIGHT_PROPERTY_DIFFUSE,
	LIGHT_PROPERTY_AMBIENT,
	LIGHT_PROPERTY_SPECULAR,
};
///Defines all light properties that are stored as a floating point value
enum LightPropertiesF{
	LIGHT_PROPERTY_SPOT_EXPONENT,
	LIGHT_PROPERTY_SPOT_CUTOFF,
	LIGHT_PROPERTY_CONST_ATT,
	LIGHT_PROPERTY_LIN_ATT,
	LIGHT_PROPERTY_QUAD_ATT,
	LIGHT_PROPERTY_BRIGHTNESS,
	LIGHT_PROPERTY_RANGE
};

struct LightProperties {
	vec4<F32> _position; ///<Position is a direction for directional lights. w-light type: 0.0 - directional, 1.0  - point 2.0 - spot
	vec4<F32> _direction; ///<Used by spot lights; w-component - padding
	vec4<F32> _ambient;
	vec4<F32> _diffuse;
	vec4<F32> _specular;
	vec4<F32> _attenuation; //x = constAtt, y = linearAtt, z = quadraticAtt, w = range
	F32 _spotExponent;
	F32 _spotCutoff;
	F32 _brightness;
	F32 _padding;
};

class Impostor;
class ParamHandler;
class FrameBufferObject;
class ShadowMapInfo;
class SceneRenderState;
///A light object placed in the scene at a certain position
class Light : public SceneNode {
public:
	///Create a new light assing to the specified slot with the specified range
	/// @param slot = the slot the light is assinged to (as in OpenGL slot for example)
	/// @param range = the light influence range (for spot/point lights)
	Light(const U8 slot,const F32 range,const LightType& type);
	virtual ~Light();

	///Light range controls the distance in which all contained objects are lit by it
	void setRange(const F32 range);
	///Light score determines the importance of this light for the current node queries
	inline I32  getScore()                const {return _score;}
	inline void setScore(const I32 score)       {_score = score;}
	///Set all light vector-properties
    virtual void setLightProperties(const LightPropertiesV& propName, const vec4<F32>& value);
	///Set all light float-properties
	virtual void setLightProperties(const LightPropertiesF& propName, F32 value);
	///Get light vector properties
	virtual const vec4<F32>& getVProperty(const LightPropertiesV& key) const;
	///Get light floating point properties
	virtual F32 getFProperty(const LightPropertiesF& key) const;
	///Get light ID
	inline U32   getId() const {return _id;}
	///Get light slot
	inline U8    getSlot() const {return _slot;}
	///Is the light a shadow caster?
	inline bool  castsShadows() const {return _castsShadows;}
	///Get the entire property block
	inline const LightProperties& getProperties() const {return _properties;}
	///Get light diffuse color
	inline const vec4<F32>& getDiffuseColor() const {return _properties._diffuse;}
	///Get light position for omni and spot or direction for a directional light (also accesible via the "getDirection" method of the "DirectionalLight" class
	inline vec3<F32>  getPosition() const {return _properties._position.rgb();}
		   void       setPosition(const vec3<F32>& newPosition);
	///Get direction for spot lights
	inline vec3<F32>  getDirection()                              const {return _properties._direction.rgb();}
		   void       setDirection(const vec3<F32>& newDirection);
	///Light effect range
	inline F32   getRange()   const {return _properties._attenuation.w;}
	///Light state (on/off)
	inline bool  getEnabled() const {return _enabled;}

	///Set a new light ID.
	///The light ID is not the slot! It is used simply to identify the lights uniquely
	inline void  setId(const U32 id) {_id = id; _dirty = true;}
	///Set the light slot.
	///Slot is used by the rendering API internally
	inline void  setSlot(const U8 slot) {_slot = slot; _dirty = true;}
	///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 color 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; _dirty = true;}
	///Get the light type.
	///See LightType enum
	inline const LightType& getLightType() const {return _type;}
	inline const LightMode& getLightMode() const {return _mode;}
	///Get a pointer to the light's imposter
	inline Impostor* const getImpostor() const {return _impostor;}
	//Checks if this light needs and update
	void updateState();

	///Dummy function from SceneNode;
	void onDraw(const RenderStage& currentStage) {};

	///SceneNode concrete implementations
	bool unload();
	void postLoad(SceneGraphNode* const sgn);
    bool computeBoundingBox(SceneGraphNode* const sgn);
    bool isInView(const bool distanceCheck,const BoundingBox& boundingBox, const BoundingSphere& sphere);
    void updateBBatCurrentFrame(SceneGraphNode* const sgn);
	///When the SceneGraph calls the light's render function, we draw the impostor if needed
	virtual void render(SceneGraphNode* const sgn);

	virtual void setCameraToLightView(const vec3<F32>& eyePos) = 0;
	        void setCameraToSceneView();

	/*----------- Shadow Mapping-------------------*/
	///Set the function used to generate shadows for this light (usually _scenegraph->render)
	inline ShadowMapInfo* getShadowMapInfo() const {return _shadowMapInfo;}
	void setShadowMappingCallback(boost::function0<void> callback);
	void addShadowMapInfo(ShadowMapInfo* const shadowMapInfo);
	bool removeShadowMapInfo();
	inline const mat4<F32 >& getLightProjectionMatrix() const {return _lightProjectionMatrix;}
	///We need to render the scene from the light's perspective
    ///This varies depending on the current pass:
    ///--The higher the pass, the closer the view
    ///sceneHalfExtent is the half extent of the world bounding box
	virtual void renderFromLightView(const U8 depthPass,const F32 sceneHalfExtent = 1) = 0;
	virtual void generateShadowMaps(const SceneRenderState& sceneRenderState);

protected:
	///Set light type
	///@param type Directional/Spot/Omni (see LightType enum)
	inline void  setLightType(const LightType& type) {_type = type;}
	///Set light mode
	///@param mode Togglable, Movable, Simple, Dominant (see LightMode enum)
	void setLightMode(const LightMode& mode);
private:
	///Enum to char* translation for vector properties
	const char* LightEnum(const LightPropertiesV& key) const;
	///Enum to char* translation for floating point properties
	const char* LightEnum(const LightPropertiesF& key) const;

protected:

	LightProperties  _properties;

	U32  _id;
	LightType _type;
	LightMode _mode;

private:

	U8   _slot;
	bool _drawImpostor, _castsShadows;
	Impostor* _impostor; ///< Used for debug rendering -Ionut
	SceneGraphNode *_lightSGN, *_impostorSGN;
	boost::function0<void> _callback;
	I32   _score;
	bool  _dirty;
    bool  _enabled;

protected:
	mat4<F32> _lightProjectionMatrix;
	vec3<F32> _lightPos;
	vec2<F32> _zPlanes;
	vec3<F32> _eyePos;
	ShadowMapInfo* _shadowMapInfo;
	ParamHandler& _par;
};

#endif

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

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

160 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Jul, 2013 17:07:04 +0000

[Ionut] [[BR]]
- Changed licensing from LGPL to the MIT license [[BR]]
— Code can now be used in non-commercial or commercial closed or open source projects [[BR]]

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

151 Diff Diff k1ngp1n picture k1ngp1n Tue 07 May, 2013 00:00:52 +0000

[Ionut] [[BR]]
- Better ReCast integration [[BR]]
— Any entity can be used as an obstacle in the NavMesh if that’s specified in each scene’s assets.xml file for said entity [[BR]]
— New console command, “createNavMesh”, that passes geometry data to ReCast [[BR]]
-— NavMesh generation is not yet complete [[BR]]
- Better PhysX integration [[BR]]
— Each scene passes data to and gets data from the Physics API better and safer[[BR]]
- Multi-threaded support extended: [[BR]]
— Event class replaced with Task [[BR]]
— Kernel uses a threadpool for scene tasks [[BR]]
— Each task can be added to a different threadpool if needed [[BR]]
— Most critical sections use the new boost::atomic wrapper for thread safety [[BR]]
- Rendering system updated [[BR]]
— VBO’s keep track of the geometry type internally [[BR]]
— Rendering by specific element list is internal to the VBO [[BR]]
— VBO’s can draw a “lite” version that doesn’t send Tangent, BiTangent and TexCoord data for depth rendering (disabled) [[BR]]
- Reflectors now offer a preview of the generated reflective texture if needed [[BR]]
- Buttons are now added and rendered by CEGUI [[BR]]
[[BR]]
Deprecation: [[BR]]
- Removed fixed pipeline material system [[BR]]
- Removed BoundingBox late update system [[BR]]
- Shadow references in the material system are now depth references [[BR]]
[[BR]]
Bug fixes: [[BR]]
- Problematic FBO double bind check removed [[BR]]
- Faster terrain rendering via chunk size selection through each scene’s terrain.xml[[BR]]
- Rendering is paused when the window is minimized [[BR]]
- CEGUI and impostors now render properly in deferred rendering mode [[BR]]
- Fixed various level 4 (VS2008) warnings [[BR]]
- Better state management and cleaning [[BR]]
- Better SceneGraph node management and trasformation/AABB update calls [[BR]]
- AITenisScene has proper collisions now [[BR]]

146 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]

141 Diff Diff k1ngp1n picture k1ngp1n Wed 30 Jan, 2013 19:35:31 +0000

[Ionut] [[BR]]
-Updated to boost 1.52 and CEGUI 0.7.9 [[BR]]
-Updated to PhysX 3.2 [[BR]]
-Updated copyright notices [[BR]]

117 Diff Diff k1ngp1n picture k1ngp1n Tue 05 Jun, 2012 17:30:40 +0000

[Ionut] [[BR]]
-Separated responsibilities between “Application” and “Kernel” [[BR]]
--“Application” handles data such as window dimensions, logs, “ParamHandler” etc [[BR]]
--“Kernel” handles the main loop, SFX, GFX, physics, sceneManager etc updates [[BR]]
---“Kernel” is now a “Core” component [[BR]]
-Reduced coupling between some classes by passing more info via parameters rather than relying on singleton access [[BR]]
--Ex: eyePos in “Terrain”,“Water” and “Trigger” classes is now passed as a "vec3<F32>" on render call rather than querying “CameraManager” [[BR]]
-Reworked “GLWrapper” shutdown routine [[BR]]
Singleton witch hunt [[BR]]
-“Kernel” is no longer a singleton and it’s initialized on application startup in the “Application” class[[BR]]
-“CameraManager” is no longer a singleton and it’s instantiated in the kernel [[BR]]

116 Diff Diff k1ngp1n picture k1ngp1n Mon 04 Jun, 2012 22:27:07 +0000

[Ionut] [[BR]]
-Removed now useless “BaseCache” class as a simple unordered_map in each manager-type class is all that’s needed [[BR]]
-Moved loading responsibility from each Resource implementation to each "ImplResourceLoader<T>" class (defaults via macro’s are available for convenience) [[BR]]
--Resources now have a “setInitialData” method for setting post-load values [[BR]]
--Also added a loader for Particle Emitters [[BR]]
-Added a new class, “HardwareResource” (for textures, shaders, etc) that needs special loading routines to facilitate future multi-threaded asset streaming [[BR]]
--HardwareResource’s have a “generateHWResource” that should be called after threaded loading routines join with main thread [[BR]]
-Renamed “Guardian” class to “Kernel” as that’s what it’s new responsibility will be in future revisions [[BR]]
-Added the “threadpool” library from here: http://threadpool.sourceforge.net/ (not used yet) [[BR]]
-Added some more macro’s and cleanups [[BR]]

114 Diff Diff k1ngp1n picture k1ngp1n Sat 02 Jun, 2012 13:03:01 +0000

[Ionut][[BR]]
-First steps in moving away from a generalized “ResourceManager”: [[BR]]
--Added templated resource loaders (Core\Resources\ConcreteLoaders). Just add a new loader for a new resource type and it’s ready for use [[BR]]
---Next step involves moving loading responsibility from the resource itself to the resource loader that handles it’s creation [[BR]]
--Renamed the ResourceManager to ResourceCache and limited it’s responsibility from general resource operations to a more standard abstract template factory with cache [[BR]]
---Manager base class is renamed to BaseCache as it’s a wrapper for a cache map in essence [[BR]]
---Next step involves adding a ResourceCache per scene (dropping Singleton status) with the possibility of sharing resources between them (to avoid reloading existing resources for a new scene) [[BR]]
-Translated AITenisScene and PingPongScene source code to english [[BR]]

111 k1ngp1n picture k1ngp1n Tue 08 May, 2012 21:49:31 +0000

[Ionut] [[BR]]
-Added animation support based on Scott Lee’s animation loader library added a few revision’s back [[BR]]
--Added cached skeleton rendering to the library [[BR]]
--Added cached AABB transformations based on current animation frame [[BR]]
--Scene animators are added per submesh and only processed if said submesh is visible and only in the rendering stage: FINAL_STAGE [[BR]]
[[BR]]
-Added support for shader-based VBO data upload (glVertexAttribPointer) with full backwards compatibility to old method (glTexCoordPointer)[[BR]]
-Added support for Index Buffer Object (improper name) indice upload for VBO’s with full backwards compatibility to old method [[BR]]
-Reworked coordination class to better handle AIEntity teams [[BR]]
-Added “updateSceneState(currentTime)” callback that is called once per frame (used for animation update)[[BR]]
-Added “initializeAI/deinitializeAI” scene callbacks for AI creation/destruction [[BR]]
-Templatized the Quaternion class [[BR]]
-Added a “drawLines” subroutine to the rendering api[[BR]]
-Disabled tree loading in MainScene as current ASSIMP implementation is slow. Will be restored after backing and loading models to own format is added in next revision [[BR]]
-Other various small performance tweaks [[BR]]