Panagiotis Christopoulos Charitos 15 лет назад
Родитель
Сommit
ad7dddc88f

+ 3 - 0
build/update-and-build-externals.sh

@@ -12,6 +12,9 @@ hg pull
 make
 cd ../glew
 svn update
+cd auto
+make destroy
+cd ..
 make extensions
 make
 

+ 0 - 0
shaders/ms_mp format (dnspgke) → shaders/MS_NAMING


+ 63 - 60
shaders/ms_mp_generic.glsl

@@ -1,4 +1,10 @@
-//
+/**
+ * @file
+ *
+ * This a generic shader to fill the deferred shading buffers. You can always build your own if you dont need to write
+ * in all the buffers
+ */
+ 
 #if defined( _DIFFUSE_MAPPING_ ) || defined( _NORMAL_MAPPING_ ) || defined( _SPECULAR_MAPPING_ )
 	#define NEEDS_TEX_MAPPING 1
 #else
@@ -15,10 +21,6 @@
 
 #pragma anki vertShaderBegins
 
-/**
- * This a generic shader to fill the deferred shading buffers. You can always build your own if you dont need to write in all the
- * buffers.
- */
 #pragma anki include "shaders/hw_skinning.glsl"
 
 // attributes
@@ -28,9 +30,12 @@ attribute vec2 texCoords;
 attribute vec4 tangent;
 
 // uniforms
-uniform mat4 MVP_mat;
-uniform mat4 MV_mat;
-uniform mat3 N_mat;
+uniform mat4 modelMat;
+uniform mat4 viewMat;
+uniform mat4 projectionMat;
+uniform mat4 modelViewMat;
+uniform mat3 normalMat;
+uniform mat4 modelViewProjectionMat;
 
 // varyings
 varying vec3 normal_v2f;
@@ -41,9 +46,9 @@ varying vec3 vertPosEyeSpace_v2f; ///< For env mapping. AKA view_vector
 
 
 
-//=====================================================================================================================================
-// main                                                                                                                               =
-//=====================================================================================================================================
+//======================================================================================================================
+// main                                                                                                                =
+//======================================================================================================================
 void main()
 {
 	// calculate the vert pos, normal and tangent
@@ -55,24 +60,24 @@ void main()
 
 		HWSkinning( _rot, _tsl );
 
-		normal_v2f = gl_NormalMatrix * ( _rot * normal );
+		normal_v2f = normalMat * ( _rot * normal );
 
 		#if NEEDS_TANGENT
-			tangent_v2f = gl_NormalMatrix * ( _rot * vec3(tangent) );
+			tangent_v2f = normalMat * ( _rot * vec3(tangent) );
 		#endif
 
 		vec3 pos_lspace = ( _rot * position) + _tsl;
-		gl_Position =  gl_ModelViewProjectionMatrix * vec4(pos_lspace, 1.0);
+		gl_Position =  modelViewProjectionMat * vec4(pos_lspace, 1.0);
 
 	// if DONT have hardware skinning
 	#else
-		normal_v2f = gl_NormalMatrix * normal;
+		normal_v2f = normalMat * normal;
 
 		#if NEEDS_TANGENT
-			tangent_v2f = gl_NormalMatrix * vec3(tangent);
+			tangent_v2f = normalMat * vec3(tangent);
 		#endif
 
-		gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
+		gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 	#endif
 
 
@@ -89,7 +94,7 @@ void main()
 
 
 	#if defined( _ENVIRONMENT_MAPPING_ ) || defined( _PARALLAX_MAPPING_ )
-		vertPosEyeSpace_v2f = vec3( gl_ModelViewMatrix * vec4(position, 1.0) );
+		vertPosEyeSpace_v2f = vec3( modelViewMat * vec4(position, 1.0) );
 	#endif
 }
 
@@ -97,21 +102,16 @@ void main()
 #pragma anki fragShaderBegins
 
 /**
- * Note: The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first happens before the
- * normal calculation and the other just after it. In the first part we read the texture (or the gl_Color) and we set the _diff_color.
- * In case of grass we discard. In the second part we calculate a SEM color and we combine it with the _diff_color. We cannot put
- * the second part before normal calculation because SEM needs the newNormal. Also we cannot put the first part after normal
- * calculation because in case of grass we will waste calculations for the normal. For that two reasons we split the diffuse
- * calculations in two parts
+ * Note: The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first happens
+ * before the normal calculation and the other just after it. In the first part we read the texture (or the gl_Color)
+ * and we set the _diff_color. In case of grass we discard. In the second part we calculate a SEM color and we combine
+ * it with the _diff_color. We cannot put the second part before normal calculation because SEM needs the newNormal.
+ * Also we cannot put the first part after normal calculation because in case of grass we will waste calculations for
+ * the normal. For that two reasons we split the diffuse calculations in two parts
  */
 
 #pragma anki include "shaders/pack.glsl"
 
-/*
-=======================================================================================================================================
-VARS                                                                                                                                  =
-=======================================================================================================================================
-*/
 
 uniform sampler2D diffuseMap;
 uniform sampler2D normalMap;
@@ -126,22 +126,21 @@ varying vec3 normal_v2f;
 varying vec3 tangent_v2f;
 varying float w_v2f;
 varying vec2 texCoords_v2f;
-varying vec3 eye;
 varying vec3 vertPosEyeSpace_v2f;
+// @todo 
+varying vec3 eye;
 
 
 
-/*
-=======================================================================================================================================
-main                                                                                                                                  =
-=======================================================================================================================================
-*/
+//======================================================================================================================
+// main                                                                                                                =
+//======================================================================================================================
 void main()
 {
-	//===================================================================================================================================
-	// Paralax Mapping Calculations                                                                                                     =
-	// The code below reads the height map, makes some calculations and returns a new texCoords                                        =
-	//===================================================================================================================================
+	//====================================================================================================================
+	// Paralax Mapping Calculations                                                                                      =
+	// The code below reads the height map, makes some calculations and returns a new texCoords                          =
+	//====================================================================================================================
 	#if defined( _PARALLAX_MAPPING_ )
 		/*const float _scale = 0.04;
 		const float _bias = scale * 0.4;
@@ -179,10 +178,10 @@ void main()
 	#endif
 
 
-	//===================================================================================================================================
-	// Diffuse Calculations (Part I)                                                                                                    =
-	// Get the color from the diffuse map and discard if grass                                                                          =
-	//===================================================================================================================================
+	//====================================================================================================================
+	// Diffuse Calculations (Part I)                                                                                     =
+	// Get the color from the diffuse map and discard if grass                                                           =
+	//====================================================================================================================
 	vec3 _diff_color;
 	#if defined( _DIFFUSE_MAPPING_ )
 
@@ -200,10 +199,10 @@ void main()
 	#endif
 
 
-	//===================================================================================================================================
-	// Normal Calculations                                                                                                              =
-	// Either use a normap map and make some calculations or use the vertex normal                                                      =
-	//===================================================================================================================================
+	//====================================================================================================================
+	// Normal Calculations                                                                                               =
+	// Either use a normap map and make some calculations or use the vertex normal                                       =
+	//====================================================================================================================
 	#if defined( _NORMAL_MAPPING_ )
 		vec3 _n = normalize( normal_v2f );
 		vec3 _t = normalize( tangent_v2f );
@@ -219,16 +218,21 @@ void main()
 	#endif
 
 
-	//===================================================================================================================================
-	// Diffuse Calculations (Part II)                                                                                                   =
-	// If SEM is enabled make some calculations and combine colors of SEM and the _diff_color                                           =
-	//===================================================================================================================================
+	//====================================================================================================================
+	// Diffuse Calculations (Part II)                                                                                    =
+	// If SEM is enabled make some calculations and combine colors of SEM and the _diff_color                            =
+	//====================================================================================================================
 
 	// if SEM enabled make some aditional calculations using the vertPosEyeSpace_v2f, environmentMap and the newNormal
 	#if defined( _ENVIRONMENT_MAPPING_ )
 		vec3 _u = normalize( vertPosEyeSpace_v2f );
-		vec3 _r = reflect( _u, newNormal ); // In case of normal mapping I could play with vertex's normal but this gives better...
-		                                      // ...results and its allready computed
+		
+		/**
+		 * In case of normal mapping I could play with vertex's normal but this gives better results and its allready
+		 * computed
+		 */
+		vec3 _r = reflect( _u, newNormal ); 
+		
 		_r.z += 1.0;
 		float _m = 2.0 * length(_r);
 		vec2 _sem_texCoords = _r.xy/_m + 0.5;
@@ -238,9 +242,9 @@ void main()
 	#endif
 
 
-	//===================================================================================================================================
-	// Specular Calculations                                                                                                            =
-	//===================================================================================================================================
+	//====================================================================================================================
+	// Specular Calculations                                                                                             =
+	//====================================================================================================================
 
 	// has specular map
 	#if defined( _SPECULAR_MAPPING_ )
@@ -251,10 +255,9 @@ void main()
 	#endif
 
 
-	//===================================================================================================================================
-	// Final Stage. Write all data                                                                                                      =
-	//===================================================================================================================================
-	//gl_FragData[0].rgb = newNormal;
+	//====================================================================================================================
+	// Final Stage. Write all data                                                                                       =
+	//====================================================================================================================
 	gl_FragData[0].rg = PackNormal( newNormal );
 	gl_FragData[1].rgb = _diff_color;
 	gl_FragData[2] = _specular;

+ 5 - 5
src/Renderer/Hdr.cpp

@@ -50,16 +50,16 @@ void Renderer::Pps::Hdr::init()
 
 	// init shaders
 	const char* shaderFname = "shaders/PpsHdr.glsl";
+	string pps;
 
-	if( !pass0SProg.customLoad( shaderFname, ("#define _PPS_HDR_PASS_0_\n#define IS_FAI_WIDTH " +
-	    Util::floatToStr(r.width) + "\n").c_str() ) )
-	{
+	pps = "#define _PPS_HDR_PASS_0_\n#define IS_FAI_WIDTH " + Util::floatToStr(r.width) + "\n";
+	if( !pass0SProg.customLoad( shaderFname, pps.c_str() ) )
 		FATAL( "See prev error" );
-	}
 
 	pass0SProg.uniVars.fai = pass0SProg.findUniVar("fai");
 
-	if( !pass1SProg.customLoad( shaderFname, ("#define _PPS_HDR_PASS_1_\n#define PASS0_HEIGHT " + Util::floatToStr(height) + "\n").c_str() ) )
+	pps = "#define _PPS_HDR_PASS_1_\n#define PASS0_HEIGHT " + Util::floatToStr(height) + "\n";
+	if( !pass1SProg.customLoad( shaderFname, pps.c_str() ) )
 		FATAL( "See prev error" );
 	pass1SProg.uniVars.fai = pass1SProg.findUniVar("fai");
 

+ 6 - 2
src/Resources/Material.h

@@ -41,7 +41,11 @@ class Material: public Resource
 
 		/**
 		 * Standard uniform variables
-		 * Changes here should update some statics and Renderer::setupMaterial
+		 *
+		 * After changing the enum update also:
+		 * - some statics in Material.cpp
+		 * - Renderer::setupMaterial
+		 * - the generic material shader
 		 */
 		enum StdUniVars
 		{
@@ -55,7 +59,7 @@ class Material: public Resource
 			SUV_MODELVIEW_MAT,
 			SUV_NORMAL_MAT,
 			SUV_MODELVIEWPROJECTION_MAT,
-			// FAIs
+			// FAIs (for materials in blending stage)
 			SUV_MS_NORMAL_FAI,
 			SUV_MS_DIFFUSE_FAI,
 			SUV_MS_SPECULAR_FAI,

+ 2 - 2
src/Resources/Mesh.h

@@ -34,10 +34,10 @@ class Mesh: public Resource
 		Vec<Vec3>         vertCoords;
 		Vec<Vec3>         vertNormals;
 		Vec<Vec4>         vertTangents;
-		Vec<Vec2>         texCoords;    ///< One for every vert so we can use vertex arrays
+		Vec<Vec2>         texCoords;    ///< One for every vert so we can use vertex arrays & VBOs
 		Vec<VertexWeight> vertWeights;
 		Vec<Triangle>     tris;
-		Vec<ushort>       vertIndeces; ///< Used for vertex arrays
+		Vec<ushort>       vertIndeces; ///< Used for vertex arrays & VBOs
 
 		struct
 		{

+ 2 - 2
src/Resources/ShaderProg.cpp

@@ -201,7 +201,7 @@ void ShaderProg::getUniAndAttribVars()
 		int loc = glGetAttribLocation(glId, name_);
 		if( loc == -1 ) // if -1 it means that its an FFP var
 		{
-			//SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
+			SHADER_WARNING( "You are using FFP vertex attributes (\"" << name_ << "\")" );
 			continue;
 		}
 
@@ -222,7 +222,7 @@ void ShaderProg::getUniAndAttribVars()
 		int loc = glGetUniformLocation(glId, name_);
 		if( loc == -1 ) // if -1 it means that its an FFP var
 		{
-			//SHADER_WARNING( "You are using FFP uniforms (\"" << name_ << "\")" );
+			SHADER_WARNING( "You are using FFP uniforms (\"" << name_ << "\")" );
 			continue;
 		}
 

+ 10 - 0
src/Scene/Controllers/MeshSkelNodeCtrl.h

@@ -3,6 +3,7 @@
 
 #include "Common.h"
 #include "Controller.h"
+#include "Vbo.h"
 
 
 class MeshNode;
@@ -20,11 +21,20 @@ class MeshSkelNodeCtrl: public Controller
 		SkelNode* skelNode;
 		MeshNode* meshNode;
 
+		struct
+		{
+			Vbo positions;
+			Vbo normals;
+			Vbo tangents;
+		} vbos;
+
+
 		MeshSkelNodeCtrl( SkelNode* skelNode_, MeshNode* meshNode_ ):
 			Controller( CT_SKEL ),
 			skelNode( skelNode_ ),
 			meshNode( meshNode_ )
 		{}
+
 		/**
 		 * Do nothing! We use HW skinning so its not necessary to update anything in the meshNode. 
 		 * The skelNode's controllers provide us with sufficient data to do the trick.