Przeglądaj źródła

- Adding guards to shaders/MsMpGeneric.glsl
- Other minor stuff

Panagiotis Christopoulos Charitos 15 lat temu
rodzic
commit
27ce91c83f

+ 65 - 38
shaders/MsMpGeneric.glsl

@@ -3,8 +3,16 @@
  *
  * 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
+ *
+ * Control defines:
+ * DIFFUSE_MAPPING, NORMAL_MAPPING, SPECULAR_MAPPING, PARALLAX_MAPPING, ENVIRONMENT_MAPPING, ALPHA_TESTING,
+ * HARDWARE_SKINNING
  */
  
+#if defined(ALPHA_TESTING) && !defined(DIFFUSE_MAPPING)
+	#error "Cannot have ALPHA_TESTING without DIFFUSE_MAPPING"
+#endif
+ 
 #if defined(DIFFUSE_MAPPING) || defined(NORMAL_MAPPING) || defined(SPECULAR_MAPPING)
 	#define NEEDS_TEX_MAPPING 1
 #else
@@ -25,13 +33,21 @@
 	#pragma anki include "shaders/hw_skinning.glsl"
 #endif
 
-// attributes
+/*
+ * Attributes
+ */
 attribute vec3 position;
 attribute vec3 normal;
-attribute vec2 texCoords;
-attribute vec4 tangent;
+#if NEEDS_TEX_MAPPING
+	attribute vec2 texCoords;
+#endif
+#if NEEDS_TANGENT
+	attribute vec4 tangent;
+#endif
 
-// uniforms
+/*
+ * Uniforms
+ */
 uniform mat4 modelMat;
 uniform mat4 viewMat;
 uniform mat4 projectionMat;
@@ -39,7 +55,9 @@ uniform mat4 modelViewMat;
 uniform mat3 normalMat;
 uniform mat4 modelViewProjectionMat;
 
-// varyings
+/*
+ * Varyings
+ */
 varying vec3 normal_v2f;
 varying vec2 texCoords_v2f;
 varying vec3 tangent_v2f;
@@ -115,13 +133,23 @@ void main()
 #pragma anki include "shaders/pack.glsl"
 
 
-uniform sampler2D diffuseMap;
-uniform sampler2D normalMap;
-uniform sampler2D specularMap;
-uniform sampler2D heightMap;
-uniform sampler2D environmentMap;
-uniform vec3 diffuseCol = vec3(1.0, 1.0, 1.0);
-uniform vec3 specularCol = vec3(1.0, 1.0, 1.0);
+#if defined(DIFFUSE_MAPPING)
+	uniform sampler2D diffuseMap;
+#endif
+#if defined(NORMAL_MAPPING)
+	uniform sampler2D normalMap;
+#endif
+#if defined(SPECULAR_MAPPING)
+	uniform sampler2D specularMap;
+#endif
+#if defined(PARALLAX_MAPPING)
+	uniform sampler2D heightMap;
+#endif
+#if defined(ENVIRONMENT_MAPPING)
+	uniform sampler2D environmentMap;
+#endif
+uniform vec3 diffuseCol = vec3(1.0, 0.0, 1.0);
+uniform vec3 specularCol = vec3(1.0, 0.0, 1.0);
 uniform float shininess = 50.0;
 
 varying vec3 normal_v2f;
@@ -139,10 +167,10 @@ varying vec3 eye;
 //======================================================================================================================
 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;
@@ -180,16 +208,17 @@ 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 alpha is zero
+	 */
 	vec3 _diff_color;
 	#if defined(DIFFUSE_MAPPING)
 
 		#if defined(ALPHA_TESTING)
 			vec4 _diff_color4 = texture2D(diffuseMap, superTexCoords);
-			if(_diff_color4.a == 0.0) discard;
+			if(_diff_color4.a == 0.0)
+				discard;
 			_diff_color = _diff_color4.rgb;
 		#else
 			_diff_color = texture2D(diffuseMap, superTexCoords).rgb;
@@ -201,10 +230,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);
@@ -220,16 +249,15 @@ 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);
 		
-		/**
+		/*
 		 * In case of normal mapping I could play with vertex's normal but this gives better results and its allready
 		 * computed
 		 */
@@ -244,10 +272,9 @@ void main()
 	#endif
 
 
-	//====================================================================================================================
-	// Specular Calculations                                                                                             =
-	//====================================================================================================================
-
+	/*
+	 * Specular Calculations
+	 */
 	// has specular map
 	#if defined(SPECULAR_MAPPING)
 		vec4 _specular = vec4(texture2D(specularMap, superTexCoords).rgb * specularCol, shininess);
@@ -257,9 +284,9 @@ void main()
 	#endif
 
 
-	//====================================================================================================================
-	// Final Stage. Write all data                                                                                       =
-	//====================================================================================================================
+	/*
+	 * Final Stage. Write all data
+	 */
 	gl_FragData[0].rg = PackNormal(newNormal);
 	gl_FragData[1].rgb = _diff_color;
 	gl_FragData[2] = _specular;

+ 12 - 9
src/Physics/MotionState.h

@@ -12,15 +12,17 @@
 class MotionState: public btMotionState
 {
 	public:
-		MotionState(const btTransform& initialTransform, SceneNode* node_);
-
+		MotionState(const Transform& initialTransform, SceneNode* node_);
 		~MotionState() {}
 
+		/**
+		 * @name Bullet implementation of virtuals
+		 */
+		/**@{*/
 		void getWorldTransform(btTransform& worldTrans) const;
-
 		const btTransform& getWorldTransform() const;
-
 		void setWorldTransform(const btTransform& worldTrans);
+		/**@}*/
 
 	private:
 		btTransform worldTransform;
@@ -32,8 +34,8 @@ class MotionState: public btMotionState
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-inline MotionState::MotionState(const btTransform& initialTransform, SceneNode* node_):
-	worldTransform(initialTransform),
+inline MotionState::MotionState(const Transform& initialTransform, SceneNode* node_):
+	worldTransform(toBt(initialTransform)),
 	node(node_)
 {}
 
@@ -56,9 +58,10 @@ inline void MotionState::setWorldTransform(const btTransform& worldTrans)
 
 	if(node)
 	{
-		float originalScale = node->getLocalTransform().getScale();
-		node->setLocalTransform(Transform(toAnki(worldTrans)));
-		node->getLocalTransform().setScale(originalScale);
+		Transform& nodeTrf = node->getLocalTransform();
+		float originalScale = nodeTrf.getScale();
+		nodeTrf = toAnki(worldTrans);
+		nodeTrf.setScale(originalScale);
 	}
 }
 

+ 1 - 1
src/Physics/PhyCharacter.cpp

@@ -16,7 +16,7 @@ PhyCharacter::PhyCharacter(Physics& physics_, const Initializer& init):
 {
 	ghostObject = new btPairCachingGhostObject();
 
-	motionState = new MotionState(toBt(init.startTrf), init.sceneNode);
+	motionState = new MotionState(init.startTrf, init.sceneNode);
 
 	btAxisSweep3* sweepBp = dynamic_cast<btAxisSweep3*>(physics.broadphase);
 	DEBUG_ERR(sweepBp == NULL);

+ 1 - 1
src/Physics/PhyCharacter.h

@@ -45,7 +45,7 @@ class PhyCharacter
 		void jump();
 
 	private:
-		Physics& physics;
+		Physics& physics; ///< Know your father
 		btPairCachingGhostObject* ghostObject;
 		btConvexShape* convexShape;
 		btKinematicCharacterController* character;

+ 1 - 1
src/Physics/RigidBody.cpp

@@ -21,7 +21,7 @@ RigidBody::RigidBody(Physics& physics_, const Initializer& init):
 	else
 		localInertia = btVector3(0.0, 0.0, 0.0);
 
-	motionState.reset(new MotionState(toBt(init.startTrf), init.sceneNode));
+	motionState.reset(new MotionState(init.startTrf, init.sceneNode));
 
 	btRigidBody::btRigidBodyConstructionInfo cInfo(init.mass, motionState.get(), init.shape, localInertia);
 

+ 1 - 1
src/Resources/Material.cpp

@@ -149,7 +149,7 @@ bool Material::load(const char* filename)
 			// build custom shader
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getString(), "buildMsSProg"))
 			{
-				// paren
+				// (
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_LPAREN)
 				{

+ 2 - 8
src/Resources/Texture.cpp

@@ -44,19 +44,15 @@ bool Texture::load(const char* filename)
 	glGenTextures(1, &glId);
 	bind(0);
 	if(mipmappingEnabled)
-	{
 		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	}
 	else
-	{
 		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	}
 
 	setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
 	texParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
 
-	// leave to GL_REPEAT. There is not real performance impact
+	// leave to GL_REPEAT. There is not real performance hit
 	setRepeat(true);
 
 	// chose formats
@@ -89,11 +85,9 @@ bool Texture::load(const char* filename)
 
 	glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &img.getData()[0]);
 	if(mipmappingEnabled)
-	{
 		glGenerateMipmap(target);
-	}
 
-	return true;
+	return GL_OK();
 }