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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "Headers/SceneNode.h"

#include "Rendering/Headers/Frustum.h"
#include "Core/Math/Headers/Transform.h"
#include "Managers/Headers/SceneManager.h"
#include "Managers/Headers/ShaderManager.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Geometry/Shapes/Headers/Mesh.h"
#include "Geometry/Shapes/Headers/SubMesh.h"
#include "Geometry/Material/Headers/Material.h"

SceneNode::SceneNode(const SceneNodeType& type) : Resource(),
										   _material(NULL),
                                           _customShader(NULL),
										   _refreshMaterialData(true),
										   _isSelectable(false),
										   _type(type),
										   _lodLevel(0),
										   _LODcount(1), ///<Defaults to 1 LOD level
										   _physicsAsset(NULL)
{
}

SceneNode::SceneNode(const std::string& name,const SceneNodeType& type) : Resource(name),
															 _material(NULL),
                                                             _customShader(NULL),
															 _refreshMaterialData(true),
															 _isSelectable(false),
															 _type(type),
															 _lodLevel(0),
															 _LODcount(1), ///<Defaults to 1 LOD level
															 _physicsAsset(NULL)
{
	U8 i = 0, j = 0;
	for(; i <  Material::TEXTURE_UNIT0; ++i)
		sprintf_s(_textureOperationUniformSlots[i], "textureOperation%d", Material::TEXTURE_UNIT0 + i);

	for(i = Material::TEXTURE_UNIT0; i < Config::MAX_TEXTURE_STORAGE; ++i)
		sprintf_s(_textureOperationUniformSlots[i], "textureOperation%d", j++);
}

SceneNode::~SceneNode() {
	SAFE_DELETE(_physicsAsset);
}

void SceneNode::sceneUpdate(const U32 sceneTime, SceneGraphNode* const sgn, SceneState& sceneState){
	if(!_material) 
		return;

	_refreshMaterialData = _material->isDirty();
	_material->clean();
}

void SceneNode::onDraw(const RenderStage& currentStage){
	Material* mat = getMaterial();

	if(!mat)
		return;

	mat->computeShader(false);
	mat->computeShader(false,DEPTH_STAGE);
}

void SceneNode::preFrameDrawEnd(SceneGraphNode* const sgn){
	//draw bounding box if needed and only in the final stage to prevent Shadow/PostFX artifacts
	//Draw the bounding box if it's always on or if the scene demands it
	if(sgn->getBoundingBox().getVisibility() || GET_ACTIVE_SCENE()->renderState().drawBBox()){
		drawBoundingBox(sgn);
	}
}

bool SceneNode::isInView(const BoundingBox& boundingBox,const BoundingSphere& sphere, const bool distanceCheck){
	Frustum& frust = Frustum::getInstance();

	const vec3<F32>& center  = sphere.getCenter();
	vec3<F32> eyeToNode      = center - frust.getEyePos();
	F32       cameraDistance = eyeToNode.length();

	if(distanceCheck && 
	   cameraDistance + boundingBox.getHalfExtent().length() > GET_ACTIVE_SCENE()->state().getGeneralVisibility())
			return false;
	

	if(!boundingBox.ContainsPoint(frust.getEyePos())){
		switch(frust.ContainsSphere(center, sphere.getRadius())) {
			case FRUSTUM_OUT: return false;
			case FRUSTUM_INTERSECT:	{
				if(!frust.ContainsBoundingBox(boundingBox)) return false;
			}
		}
	}

	U8 lod = 0;
	if(cameraDistance > Config::SCENE_NODE_LOD0)		lod = 2;
	else if(cameraDistance > Config::SCENE_NODE_LOD1)	lod = 1;
	_lodLevel = lod;

	return true;
}

Material* SceneNode::getMaterial(){
    //UpgradableReadLock ur_lock(_materialLock);
	if(_material == NULL){
		if(!_renderState._noDefaultMaterial){
			ResourceDescriptor defaultMat("defaultMaterial");
            //UpgradeToWriteLock uw_lock(ur_lock);
			_material = CreateResource<Material>(defaultMat);
			REGISTER_TRACKED_DEPENDENCY(_material);
		}
	}
	return _material;
}

void SceneNode::setMaterial(Material* const m){
	if(m){ //If we need to update the material
        //UpgradableReadLock ur_lock(_materialLock);
		if(_material){ //If we had an old material
			if(_material->getMaterialId().i != m->getMaterialId().i){ //if the old material isn't the same as the new one
				PRINT_FN(Locale::get("REPLACE_MATERIAL"),_material->getName().c_str(),m->getName().c_str());
                //UpgradeToWriteLock uw_lock(ur_lock);
				RemoveResource(_material);			//remove the old material
				UNREGISTER_TRACKED_DEPENDENCY(_material);
                //ur_lock.lock();
			}
		}
        //UpgradeToWriteLock uw_lock(ur_lock);
		_material = m;				   //set the new material
		REGISTER_TRACKED_DEPENDENCY(_material);
	}else{ //if we receive a null material, the we need to remove this node's material
        //UpgradableReadLock ur_lock(_materialLock);
		if(_material){
            //UpgradeToWriteLock uw_lock(ur_lock);
			UNREGISTER_TRACKED_DEPENDENCY(_material);
			RemoveResource(_material);
		}
	}
}

void SceneNode::clearMaterials(){
	setMaterial(NULL);
}

void SceneNode::prepareMaterial(SceneGraphNode* const sgn){
    //UpgradableReadLock ur_lock(_materialLock);
    if(!_material)  
		return;

	if(GFX_DEVICE.isCurrentRenderStage(REFLECTION_STAGE))
		SET_STATE_BLOCK(_material->getRenderState(REFLECTION_STAGE));
	else
		SET_STATE_BLOCK(_material->getRenderState(FINAL_STAGE));
	
	ShaderProgram* s = _material->getShaderProgram();
	Scene* activeScene = GET_ACTIVE_SCENE();
	LightManager& lightMgr = LightManager::getInstance();

	s->bind();

	Texture2D* texture = NULL;
	for(U16 i = 0; i < Config::MAX_TEXTURE_STORAGE; ++i)
		if((texture = _material->getTexture(i)) != NULL){
			texture->Bind(i);

			if(i >= Material::TEXTURE_UNIT0)
				s->Uniform(_textureOperationUniformSlots[i], (I32)_material->getTextureOperation(i));
		}

	s->Uniform("material",_material->getMaterialMatrix());
	s->Uniform("opacity", _material->getOpacityValue());
	s->Uniform("textureCount",_material->getTextureCount());

	if(lightMgr.shadowMappingEnabled()){
        s->Uniform("worldHalfExtent", activeScene->getSceneGraph()->getRoot()->getBoundingBox().getWidth() * 0.5f);
		s->Uniform("dvd_lightProjectionMatrices",lightMgr.getLightProjectionMatricesCache());
		s->Uniform("dvd_enableShadowMapping",_material->getReceivesShadows());
	}else{
		s->Uniform("dvd_enableShadowMapping",false);
	}

	s->Uniform("dvd_lightType",        lightMgr.getLightTypesForCurrentNode());
	s->Uniform("dvd_lightCount",       lightMgr.getLightCountForCurrentNode());
    s->Uniform("dvd_lightEnabled",     lightMgr.getLightsEnabledForCurrentNode());
	s->Uniform("dvd_lightCastsShadows",lightMgr.getShadowCastingLightsForCurrentNode());

	s->Uniform("windDirection",vec2<F32>(activeScene->state().getWindDirX(),activeScene->state().getWindDirZ()));
	s->Uniform("windSpeed", activeScene->state().getWindSpeed());

	if(!sgn->animationTransforms().empty()){
		s->Uniform("hasAnimations", true);
		s->Uniform("boneTransforms", sgn->animationTransforms());
	}else{
		s->Uniform("hasAnimations",false);
	}
}

void SceneNode::releaseMaterial(){
    //UpgradableReadLock ur_lock(_materialLock);
	if(!_material) return;

	Texture2D* texture = NULL;
	for(U16 i = 0; i < Config::MAX_TEXTURE_STORAGE; ++i)
		if((texture = _material->getTexture(i)) != NULL)
			texture->Unbind(i);
}

void SceneNode::prepareDepthMaterial(SceneGraphNode* const sgn){
	if(getType() != TYPE_OBJECT3D && getType() != TYPE_TERRAIN) 
		return;

    //UpgradableReadLock ur_lock(_materialLock);
	// general depth descriptor for objects without material
	if(!_material) {
		SET_STATE_BLOCK(_renderState.getDepthStateBlock());
		return;
	}

	SET_STATE_BLOCK(_material->getRenderState(DEPTH_STAGE));

	ShaderProgram* s = _material->getShaderProgram(DEPTH_STAGE);
	assert(s != NULL);
	s->bind();

	Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);

	if(opacityMap)
		opacityMap->Bind(Material::TEXTURE_OPACITY);
	
	s->Uniform("opacity", _material->getOpacityValue());

	if(!sgn->animationTransforms().empty()){
		s->Uniform("hasAnimations", true);
		s->Uniform("boneTransforms", sgn->animationTransforms());
	}else{
		s->Uniform("hasAnimations",false);
	}
}

void SceneNode::releaseDepthMaterial(){
    //UpgradableReadLock ur_lock(_materialLock);
	if(!_material)
		return;

	Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);
	if(opacityMap) 
		opacityMap->Unbind(Material::TEXTURE_OPACITY);
}

bool SceneNode::computeBoundingBox(SceneGraphNode* const sgn) {
	BoundingBox& bb = sgn->getBoundingBox();
	sgn->setInitialBoundingBox(bb);
	bb.setComputed(true);
	return true;
}

void SceneNode::updateBBatCurrentFrame(SceneGraphNode* const sgn){
	sgn->updateBB(false);
}

bool SceneNode::unload(){
	clearMaterials();
	return true;
}

void SceneNode::drawBoundingBox(SceneGraphNode* const sgn){
	const BoundingBox& bb = sgn->getBoundingBox();
	/*mat4<F32> boundingBoxTransformMatrix;
	Transform* tempTransform = sgn->getTransform();
	if(tempTransform){
		boundingBoxTransformMatrix = tempTransform->getGlobalMatrix();
	}*/

	GFX_DEVICE.drawBox3D(bb.getMin(),bb.getMax(),/*boundingBoxTransformMatrix*/mat4<F32>());
}

Commits for Divide-Framework/trunk/Source Code/Graphs/SceneNode.cpp

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]]

154 Diff Diff k1ngp1n picture k1ngp1n Sun 23 Jun, 2013 23:39:07 +0000

[Ionut] [[BR]]
- Changed math computation for: Matrix multiplication, Normal and Tangent calculation, Quaternion to Matrix conversion and more [[BR]]
- Removed useless UBO classes and extended the functionality of the base UBO class [[BR]]
- Changed lighting shaders to be more streamlined [[BR]]
- Added full shader based fog [[BR]]
— Added per-scene optional fog settings [[BR]]
- Re-enabled sorting by shader program for Mesh Delegate Bin (was set to Front to Back for debugging purposes and forgotten there) [[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]]

148 Diff Diff k1ngp1n picture k1ngp1n Sun 14 Apr, 2013 23:07:58 +0000

[Ionut] [[BR]]
- Changed the ParamHandler from using “boost::any” to the more faster “cdiggins::any”. More info here: http://bit.ly/YVGa9X [[BR]]
- Disabled mutexes from BoundingBox. Thread safety should be applied from a higher level [[BR]]
- Fixed a bug with important light selection for scene nodes [[BR]]
- Fixed a bug with material cache involving bump maps [[BR]]
- Fixed a bug with priority vertex properties for GLSL shaders [[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]]

135 Diff Diff k1ngp1n picture k1ngp1n Tue 20 Nov, 2012 19:01:27 +0000

[Ionut] [[BR]]

  • (minor merge with LightingUpdate branch, rev. 134) [[BR]]

-Updated ASSIMP to version 3.0.1,CeGUI to 0.7.7 and PhysX to 3.2.2 [[BR]]
-Moved third party libraries to separate repository with appropriate copyright notices [[BR]]
--New library repository: https://xp-dev.com/svn/Divide-Dependencies [[BR]]
--PhysX can’t be legally shared like the rest of the libs, but you can get ver. 3.2.2 (the version the framework is using) by signing up to the nVidia Developer Website ( https://developer.nvidia.com/ ) [[BR]]

126 Diff Diff k1ngp1n picture k1ngp1n Sun 01 Jul, 2012 11:07:05 +0000

[Ionut] [[BR]]
-Renamed “CommunicationSensor” to “CommunicationInterface” [[BR]]
-More work on ReCast implementation [[BR]]
-Header and namespace cleanups [[BR]]

122 Diff Diff k1ngp1n picture k1ngp1n Mon 11 Jun, 2012 14:39:08 +0000

[Ionut] [[BR]]
-Restructured “Hardware” folder to match the rest of the projects header-separation pattern [[BR]]

121 k1ngp1n picture k1ngp1n Sun 10 Jun, 2012 16:40:45 +0000

[Ionut] [[BR]]
-Added basic localization support [[BR]]
-Added cross-platform INI parsing [[BR]]
-Moved ReCast+Detour to LIBS folder [[BR]]