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
#include "Headers/Water.h"

#include "Managers/Headers/SceneManager.h"
#include "Core/Headers/Application.h"
#include "Core/Headers/ParamHandler.h"
#include "Hardware/Video/RenderStateBlock.h"

WaterPlane::WaterPlane() : SceneNode(TYPE_WATER), Reflector(TYPE_WATER_SURFACE,vec2<I32>(2048,2048)), 
						   _plane(NULL),_texture(NULL), _shader(NULL),_planeTransform(NULL),
						   _node(NULL),_planeSGN(NULL),_waterLevel(0){}

bool WaterPlane::setInitialData(const std::string& name){
	if(!_texture && !_shader && !_plane) return false;

	_shader->bind();
		_shader->Uniform("water_shininess",50.0f );
		_shader->Uniform("noise_tile", 50.0f );
		_shader->Uniform("noise_factor", 0.1f);
	_shader->unbind();

	_farPlane = 2.0f * ParamHandler::getInstance().getParam<F32>("zFar");
	_plane->setCorner(Quad3D::TOP_LEFT, vec3<F32>(   -_farPlane, 0, -_farPlane));
	_plane->setCorner(Quad3D::TOP_RIGHT, vec3<F32>(   _farPlane, 0, -_farPlane));
	_plane->setCorner(Quad3D::BOTTOM_LEFT, vec3<F32>(-_farPlane, 0,  _farPlane));
	_plane->setCorner(Quad3D::BOTTOM_RIGHT, vec3<F32>(_farPlane, 0,  _farPlane));
	_plane->setDrawState(false);


	return true;
}

void WaterPlane::postLoad(SceneGraphNode* const sgn){
	_node = sgn;
	_planeSGN = _node->addNode(_plane);
	_planeSGN->setActive(false);
	_planeTransform = _planeSGN->getTransform();
	///The water doesn't cast shadows, doesn't need ambient occlusion and doesn't have real "depth"
	addToDrawExclusionMask(SHADOW_STAGE | SSAO_STAGE | DEPTH_STAGE);
}

bool WaterPlane::computeBoundingBox(SceneGraphNode* const sgn){
	BoundingBox& bb = _node->getBoundingBox();
	if(bb.isComputed()) return true;
	_waterLevel = GET_ACTIVE_SCENE()->getWaterLevel();
	F32 waterDepth = GET_ACTIVE_SCENE()->getWaterDepth();
	bb.set(vec3<F32>(-_farPlane,_waterLevel - waterDepth, -_farPlane),vec3<F32>(_farPlane, _waterLevel, _farPlane));
	_planeSGN->getBoundingBox().Add(bb);
	PRINT_FN("Water plane height placement: %f", bb.getMax().y);
	PRINT_FN("Water plane depth level: %f", bb.getMin().y);
	bool state = SceneNode::computeBoundingBox(sgn);
	_shader->bind();
		_shader->Uniform("win_width",  (I32)Application::getInstance().getWindowDimensions().width);
		_shader->Uniform("win_height", (I32)Application::getInstance().getWindowDimensions().height);
		_shader->Uniform("water_bb_min",bb.getMin());
		_shader->Uniform("water_bb_max",bb.getMax());
	_shader->unbind();
	return state;
}

bool WaterPlane::unload(){
	bool state = false;
	state = SceneNode::unload();
	return state;
}


void WaterPlane::setParams(F32 shininess, F32 noiseTile, F32 noiseFactor, F32 transparency){
	_shader->bind();
		_shader->Uniform("water_shininess",shininess );
		_shader->Uniform("noise_tile", noiseTile );
		_shader->Uniform("noise_factor", noiseFactor);
	_shader->unbind();
}

void WaterPlane::onDraw(){
	BoundingBox& bb = _node->getBoundingBox();
	_planeTransform->setPosition(vec3<F32>(_eyePos.x,bb.getMax().y,_eyePos.z));
}

void WaterPlane::prepareMaterial(SceneGraphNode const* const sgn){
	
	SET_STATE_BLOCK(getMaterial()->getRenderState(FINAL_STAGE));

	GFX_DEVICE.setMaterial(getMaterial());
	
	_reflectedTexture->Bind(0);
	_texture->Bind(1);	
	_shader->bind();
	_shader->UniformTexture("texWaterReflection", 0);
	_shader->UniformTexture("texWaterNoiseNM", 1);
}

void WaterPlane::releaseMaterial(){

	_texture->Unbind(1);
	_reflectedTexture->Unbind(0);
}

void WaterPlane::render(SceneGraphNode* const sgn){
	
	GFX_DEVICE.setObjectState(_planeTransform);
	GFX_DEVICE.renderModel(_plane);
	GFX_DEVICE.releaseObjectState(_planeTransform);
}

bool WaterPlane::getDrawState(RENDER_STAGE currentStage)  const{
	/// Wait for the Reflector to update
	if(!_createdFBO){
		return false;
	}
	/// Make sure we are not drawing ourself
	if(_updateSelf){
		/// unless this is desired
		return false;
	}
	/// Else, process normal exclusion
	return SceneNode::getDrawState(currentStage);
}

/// Update water reflections
void WaterPlane::updateReflection(){
	/// Early out check for render callback
	if(_renderCallback.empty()) return;
    /// Set the correct stage
	RENDER_STAGE prev = GFX_DEVICE.getRenderStage();
	bool underwater = isCameraUnderWater();
	if(!underwater){
		GFX_DEVICE.setRenderStage(REFLECTION_STAGE);
	}
	/// bind the reflective texture
	_reflectedTexture->Begin();
		/// render to the reflective texture
		_renderCallback();
	_reflectedTexture->End();

	if(!underwater){
		GFX_DEVICE.setRenderStage(prev);
	}
}

Commits for Divide-Framework/trunk/Source Code/Environment/Water/Water.cpp

Diff revisions: vs.
Revision Author Commited Message
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]]

113 Diff Diff k1ngp1n picture k1ngp1n Fri 01 Jun, 2012 16:51:23 +0000

[Ionut] [[BR]]
-Fixed animated bounding box calculations[[BR]]
-BoundingBox recalculation per frame is now a general SceneNode property [[BR]]
--Note: Animated BB’s have problems with multi-threaded collision detection for now (see AITenisScene) [[BR]]
-Wrapped boost::mutex to separate file and moved it to shared_mutex structure as read requests are more frequent than write requests [[BR]]
-Mesh class now calls animations update on all of it’s subclasses so animations for each node in a mesh are in sync [[BR]]
-Split up GUI elements by class [[BR]]
-Added base code for a console GUI element (disabled) [[BR]]
-Animations can now be disabled in confg file [[BR]]
-Added a “texture not found” default texture [[BR]]
-Some AI rewrite in AITenisScene (translation to english in next commit) [[BR]]
-Inlines, const’s, cleanups, etc [[BR]]

106 Diff Diff k1ngp1n picture k1ngp1n Wed 28 Mar, 2012 21:50:23 +0000

[Ionut] [[BR]]
Unstable revision – New animation code is not yet optimized and loading performance is low [[BR]]
[[BR]]
-Added animation loading and bone matrix calculations (actual skinning not implemented yet)[[BR]]
-Modified VBO classes to support dynamic data and faster updates [[BR]]
-Templatized Math classes (vec2,vec3,vec4,mat3,mat4) for greater flexibility [[BR]]
-Separated Rendering API from Rendering API version [[BR]]
-Fixed buggy GL error checking [[BR]]
-Small bugs fixed in Projectile and Weapon classes [[BR]]

103 Diff Diff k1ngp1n picture k1ngp1n Mon 12 Mar, 2012 19:06:00 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a proper RenderState Management system similar to the D3D default one[[BR]]
--All possible states are managed: cull, blend, alpha-blend, color mask, lighting, stencil mask, fill mode etc [[BR]]
--Every material has different states for normal rendering, shadow rendering and reflection rendering [[BR]]
--Nodes are sorted by shader first then by state hash depending on current render stage [[BR]]
--Redundant states are not changed [[BR]]
--Every entity submits it’s desired state before render [[BR]]
--Every state is checked before rendering a VBO or other primitive type[[BR]]
[[BR]]
-Added a Reflector base class used for reflection calculations and updates (useful for water, mirrors, portals etc)[[BR]]
--Reflections are triggered between pre-render and render calls [[BR]]
--Water now derives from Reflector class as well [[BR]]
[[BR]]
-Material now properly calculates if it has transparency or is double sided, setting desired states to handle this feature (cull, blend) [[BR]]
-Added some basic defines or inline template functions to facilitate access to useful classes and methods (hardware devices, resource management, console printing, etc) [[BR]]
-Lights are updated after every camera update[[BR]]
-Added a new FrameListener event triggered after pre-render call is finished (used by reflectors) [[BR]]
-Added a CRC class to compute unique hash values for entities[[BR]]
-Added D3D dummy files [[BR]]
-Removed executables from subversion [[BR]]
Performance: [[BR]]
-Image loading has been improved a bit [[BR]]
-Terrain texel density now varies with LOD level [[BR]]
-Light API specific calls,except position, are set only if values changed[[BR]]
-Specific GUI casting and rendering are the Rendering API’s job now, not the GUI class [[BR]]
-Rendering Queue processing is now more efficient in sorting valid visible nodes and setting appropriate states/materials
[[BR]]
Bug fixes: [[BR]]
-Better drawState checks[[BR]]
-Proper light effects in deferred rendering[[BR]]
-Light dummy now renders properly[[BR]]
-Reworked bounding box computation [[BR]]
[[BR]]
Known bugs: [[BR]]
-Terrain infinite plain still not visible [[BR]]
-Some z-fighting occurs when looking at certain objects from a distance. (looking at another object and back again fixes it) [[BR]]

100 Diff Diff k1ngp1n picture k1ngp1n Mon 05 Mar, 2012 17:45:11 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a physics system interface instead of direct PhysX interaction to allow other physics engines (Bullet, ODE etc) to be easily implemented [[BR]]
--This will aid in Object-Object collisions and character control in future revisions [[BR]]
-Added an Ogre3D inspired FrameListener which now allows Before-frame/during-frame/after-frame event plugins of callbacks [[BR]]
-Added a renderInViewport system to draw elements in a user defined rectangle on screen [[BR]]
--Current uses: shadowmap preview (F10) [[BR]]
-Separated Shaders from ShaderPrograms[[BR]]
--ShaderPrograms can now use multiple Shaders [[BR]]
-Error output is now sent to errors.log[[BR]]
-All SceneNode based elements now have a postDraw calls as well [[BR]]
-A cubemap generating function has been added to the GFXDevice class[[BR]]
-Added debug only print options to the Console class [[BR]]
[[BR]]
Performance: [[BR]]
-All shadows are now filtered by a faster Gaussian 3x3 blur filter [[BR]]
-All renderables are now sorted and rendered by material/front-to-back/back-to-front, depending on case [[BR]]
-RenderQueue now sorts and queue’s translucent and opaque objects separately[[BR]]
-Shader uniforms/attributes are now cached to reduce number of address calls to the GPU[[BR]]
-Shaders are now cached, so that if multiple ShaderPrograms use an already compiled Shader, that Shader is returned from memory instead of creating a new copy[[BR]]
-Shaders are not unbound/rebound except when an objects demands so (vastly improves performance)[[BR]]
-Reduced calls to glEnable[[BR]]
[[BR]]
Bug fixes: [[BR]]
-Preprocessor configurations now work properly [[BR]]
-Video API is now unloaded before destruction [[BR]]
-Manager base class now properly frees memory [[BR]]
-Materials are saved to XML only if they are changed at any point [[BR]]

99 Diff Diff k1ngp1n picture k1ngp1n Fri 10 Feb, 2012 22:17:24 +0000

[ Ionut ] [[BR]]
- Added a PreRenderStage Builder that allows multiple pre-render stages to be added to the pre-render step [[ BR ]]
--A PreRenderStage is composed of a series of PreRender Operators that generate certain PostFX outputs that are used by the PostFX class [[BR]]
--Each PreRenderOperator, similar to a “plugin”, can use any number of input FBO’s, any input shader and render target to generate an effect [[BR]]
--Rendering pipeline has been modified to allow the specification of current render stage [[BR]]
[[BR]]
Added C++<>Shader attribute passing support for shaders[[BR]]
-Added per-pixel fog [[BR]]
-Fixed some typo’s in uniform names [[BR]]
-Optimized shadow generation pipeline [[BR]]
-Added cast/receive shadow options for materials [[BR]]
-FBO’s now clear color and depth buffers when Begin() is called [[BR]]
-Fixed loading of primitives' material properties [[BR]]
-All shaders now use the same shadowmapping techniques [[BR]]
-Quad3D’s can now be modified by specifying a target rect [[BR]]
-Split the “lighting.frag” shader in 3 variants: one that only applies color properties, one with textures and one with bump-mapping [[BR]]
--This reduces fragment shader complexity for the first 2 shaders [[BR]]
--Each material change will now force a shader recalculation for the object [[BR]]
-Renamed sphere’s “size” member to “radius” [[BR]]

97 k1ngp1n picture k1ngp1n Tue 07 Feb, 2012 15:23:45 +0000

[ Ionut ] [[BR]]
-Restructured code base to a more logical layout [[BR]]
--Geometry folder contains shapes, materials, animations and the importer; Environment folder holds sky, terrain, water, vegetation; etc [[BR]]
--All header files are moved to a “Headers” sub-folder [[BR]]
--Renamed most of the Romanian code/comments/files/folders to English [[BR]]
--Added comments to parts of the code (ongoing from now on) [[BR]]
[[BR]]
-Rewrote the entire lighting system [[BR]]
--Added a LightManager class to handle all lights [[BR]]
---LightManager calls updates and render calls to all lights it manages [[BR]]
--Lights have all needed properties stored in 2 maps (one for vector values, one for float values) [[BR]]
--Added a LightImpostor class that takes the light’s properties and applies it to a dummy sphere [[BR]]
--If a light should draw it’s impostor, the impostor draws the dummy sphere [[BR]]
--Rewrote the Light <-> GFXDevice interaction [[BR]]
---Each light stores it’s type in a variable and passes all properties to the rendering API that then decides what to use based on that type [[BR]]
--Each light handles it’s own ShadowMapping [[BR]]
[[BR]]
-ShadowMapping: [[BR]]
-Each light stores it’s own depth maps and generates them based on it’s type [[BR]]
-LightManager binds all available depth maps and shaders pick them up automatically for use [[BR]]
-Each shadow map (of a total of 3 per light) corresponds to a detail level[[BR]]
-The final shadow map resolution is decided by the shadow detail level set in the config [[BR]]
--Camera and Frustum are set up for shadow rendering and applied to the render callback set for the current light (for example, Scene::render()) [[BR]]
--The light manager tells every light that has “_castShadows = true” to generate shadowmaps automatically after the Scene::PreRender stage [[BR]]
--ShadowMaps are blurred before applied to the fragment’s final color via shaders. [[BR]]
[[BR]]
-Added detail level configuration options [[BR]]
--ToDo: add shaders for each detail level [[BR]]
[[BR]]
-Moved all predefined geometry from immediate mode to VBO’s [[BR]]
--This allowed the rendering pipeline to be more streamlined (one render function for all geometry) [[BR]]
[[BR]]
-Fixed GuiElement visibility toggle [[BR]]
-Fixed GuiText color state problem [[BR]]
-Added FBO texture format options [[BR]]
-VBO rendering uses U16 as default instead of U32 (better for GPU) [[BR]]
-VBO’s now contain BiTangent data as well [[BR]]
-Added OpenGL 2.0 compatibility (not guaranteed!) [[BR]]
-Added static (on load) shader selection based on detail level [[BR]]
-Added SSAO PostFX option, but this won’t work until the implementation of “plugins” for PostFX system [[BR]]
-Optimized/Fixed code based on VisualLint + CppCheck analysis [[BR]]