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

+ 2 - 1
README

@@ -1,3 +1,4 @@
 For build info see build/README
 
-Currently there are no assets (models, textures, materials etc) so even if you compile it the application will crash if you try to run it
+Currently there are no assets (models, textures, materials etc) so even if you
+compile it, the application will fail to run

+ 21 - 2
build/debug/Makefile

@@ -4,8 +4,8 @@ PHFLAGS = -c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -pipe -O0 -g3 -pg
 LFLAGS = -rdynamic -L../../../SDL-hg/build/.libs -L../../../glew/lib -L../../../bullet_svn/src/BulletSoftBody -L../../../bullet_svn/src/BulletDynamics -L../../../bullet_svn/src/BulletCollision -L../../../bullet_svn/src/LinearMath -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lSDL_image -lGLU -lSDL -Wl,-Bdynamic -lGL -ljpeg -lpng -ltiff
 EXECUTABLE = AnKi.bin
 INCPATH = -I../../src/Math/ -I../../src/Util/Tokenizer/ -I../../src/Misc/ -I../../src/ -I../../src/Renderer/ -I../../src/Scene/ -I../../src/Ui/ -I../../src/Resources/ -I../../src/Util/ -I../../src/Scene/Controllers/ -I../../src/Physics/ -I../../src/Renderer/BufferObjects/ -I../../src/Resources/Helpers/ -I../../../bullet_svn/src/ -I../../../SDL-hg/include -I../../glew/include 
-SOURCES = ../../src/Util/Tokenizer//Scanner.cpp ../../src/Misc//skybox.cpp ../../src/Misc//particles.cpp ../../src/Misc//memory.cpp ../../src/Misc//collision.cpp ../../src/Misc//map.cpp ../../src//Main.cpp ../../src/Renderer//Sm.cpp ../../src/Renderer//Pps.cpp ../../src/Renderer//Renderer.cpp ../../src/Renderer//Ssao.cpp ../../src/Renderer//Is.cpp ../../src/Renderer//MainRenderer.cpp ../../src/Renderer//Ms.cpp ../../src/Renderer//Hdr.cpp ../../src/Renderer//Dbg.cpp ../../src/Scene//MeshNode.cpp ../../src/Scene//SkelNode.cpp ../../src/Scene//SkelModelNode.cpp ../../src/Scene//Light.cpp ../../src/Scene//Camera.cpp ../../src/Scene//Scene.cpp ../../src/Scene//ParticleEmitter.cpp ../../src/Scene//SceneNode.cpp ../../src/Ui//Ui.cpp ../../src/Resources//Material.cpp ../../src/Resources//ShaderProg.cpp ../../src/Resources//Texture.cpp ../../src/Resources//SkelAnim.cpp ../../src/Resources//Extension.cpp ../../src/Resources//Skeleton.cpp ../../src/Resources//Resource.cpp ../../src/Resources//LightProps.cpp ../../src/Resources//Mesh.cpp ../../src/Util//Input.cpp ../../src/Util//App.cpp ../../src/Util//Common.cpp ../../src/Util//Util.cpp ../../src/Scene/Controllers//Controller.cpp ../../src/Scene/Controllers//SkelAnimCtrl.cpp ../../src/Physics//PhyWorld.cpp ../../src/Resources/Helpers//ShaderPrePreprocessor.cpp ../../src/Resources/Helpers//Image.cpp 
-OBJECTS = Scanner.o skybox.o particles.o memory.o collision.o map.o Main.o Sm.o Pps.o Renderer.o Ssao.o Is.o MainRenderer.o Ms.o Hdr.o Dbg.o MeshNode.o SkelNode.o SkelModelNode.o Light.o Camera.o Scene.o ParticleEmitter.o SceneNode.o Ui.o Material.o ShaderProg.o Texture.o SkelAnim.o Extension.o Skeleton.o Resource.o LightProps.o Mesh.o Input.o App.o Common.o Util.o Controller.o SkelAnimCtrl.o PhyWorld.o ShaderPrePreprocessor.o Image.o 
+SOURCES = ../../src/Util/Tokenizer//Scanner.cpp ../../src/Misc//skybox.cpp ../../src/Misc//particles.cpp ../../src/Misc//memory.cpp ../../src/Misc//collision.cpp ../../src/Misc//map.cpp ../../src//Main.cpp ../../src/Renderer//EarlyZ.cpp ../../src/Renderer//Sm.cpp ../../src/Renderer//Pps.cpp ../../src/Renderer//Renderer.cpp ../../src/Renderer//Ssao.cpp ../../src/Renderer//Is.cpp ../../src/Renderer//MainRenderer.cpp ../../src/Renderer//Ms.cpp ../../src/Renderer//Hdr.cpp ../../src/Renderer//Dbg.cpp ../../src/Scene//MeshNode.cpp ../../src/Scene//SkelNode.cpp ../../src/Scene//SkelModelNode.cpp ../../src/Scene//Light.cpp ../../src/Scene//Camera.cpp ../../src/Scene//Scene.cpp ../../src/Scene//ParticleEmitter.cpp ../../src/Scene//SceneNode.cpp ../../src/Ui//Ui.cpp ../../src/Resources//Material.cpp ../../src/Resources//ShaderProg.cpp ../../src/Resources//Texture.cpp ../../src/Resources//SkelAnim.cpp ../../src/Resources//Extension.cpp ../../src/Resources//Skeleton.cpp ../../src/Resources//Resource.cpp ../../src/Resources//LightProps.cpp ../../src/Resources//Mesh.cpp ../../src/Util//Input.cpp ../../src/Util//App.cpp ../../src/Util//Common.cpp ../../src/Util//Util.cpp ../../src/Scene/Controllers//Controller.cpp ../../src/Scene/Controllers//SkelAnimCtrl.cpp ../../src/Physics//PhyWorld.cpp ../../src/Resources/Helpers//ShaderPrePreprocessor.cpp ../../src/Resources/Helpers//Image.cpp 
+OBJECTS = Scanner.o skybox.o particles.o memory.o collision.o map.o Main.o EarlyZ.o Sm.o Pps.o Renderer.o Ssao.o Is.o MainRenderer.o Ms.o Hdr.o Dbg.o MeshNode.o SkelNode.o SkelModelNode.o Light.o Camera.o Scene.o ParticleEmitter.o SceneNode.o Ui.o Material.o ShaderProg.o Texture.o SkelAnim.o Extension.o Skeleton.o Resource.o LightProps.o Mesh.o Input.o App.o Common.o Util.o Controller.o SkelAnimCtrl.o PhyWorld.o ShaderPrePreprocessor.o Image.o 
 PRECOMPILED_HEADERS = 
 
 all: $(PRECOMPILED_HEADERS) $(SOURCES) $(EXECUTABLE)
@@ -504,6 +504,25 @@ Main.o: ../../src//Main.cpp ../../src/Util/Common.h \
 	@echo Compiling ../../src//Main.cpp...
 	@$(CXX) $(INCPATH) $(CFLAGS) ../../src//Main.cpp -o Main.o
 
+EarlyZ.o: ../../src/Renderer//EarlyZ.cpp ../../src/Renderer//Renderer.h \
+ ../../src/Util/Common.h ../../src/Misc/memory.h ../../src/Math/Math.h \
+ ../../src/Math/Vec2.h ../../src/Math/MathForwardDecls.h \
+ ../../src/Math/Vec2.inl.h ../../src/Math/MathDfltHeader.h \
+ ../../src/Math/Vec3.h ../../src/Math/Vec3.inl.h ../../src/Math/Vec4.h \
+ ../../src/Math/Vec4.inl.h ../../src/Math/Quat.h \
+ ../../src/Math/Quat.inl.h ../../src/Math/Axisang.h \
+ ../../src/Math/Axisang.inl.h ../../src/Math/Euler.h \
+ ../../src/Math/Euler.inl.h ../../src/Math/Mat3.h \
+ ../../src/Math/Mat3.inl.h ../../src/Math/Mat4.h \
+ ../../src/Math/Mat4.inl.h ../../src/Math/MathFuncs.h \
+ ../../src/Math/MathFuncs.inl.h ../../src/Math/Transform.h \
+ ../../src/Math/Transform.inl.h ../../src/Renderer/BufferObjects/Fbo.h \
+ ../../src/Resources/Texture.h ../../src/Resources/Resource.h \
+ ../../src/Util/Util.h ../../src/Util/Common.h \
+ ../../src/Resources/ShaderProg.h
+	@echo Compiling ../../src/Renderer//EarlyZ.cpp...
+	@$(CXX) $(INCPATH) $(CFLAGS) ../../src/Renderer//EarlyZ.cpp -o EarlyZ.o
+
 Sm.o: ../../src/Renderer//Sm.cpp ../../src/Renderer//Renderer.h \
  ../../src/Util/Common.h ../../src/Misc/memory.h ../../src/Math/Math.h \
  ../../src/Math/Vec2.h ../../src/Math/MathForwardDecls.h \

+ 1 - 1
src/Renderer/Dbg.cpp

@@ -248,7 +248,7 @@ void Renderer::Dbg::run()
 
 	// OGL stuff
 	r.setProjectionViewMatrices( cam );
-	r.setViewport( 0, 0, r.width, r.height );
+	Renderer::setViewport( 0, 0, r.width, r.height );
 
 	glEnable( GL_DEPTH_TEST );
 	glDisable( GL_BLEND );

+ 23 - 0
src/Renderer/EarlyZ.cpp

@@ -0,0 +1,23 @@
+#include "Renderer.h"
+
+
+//=====================================================================================================================================
+// init                                                                                                                               =
+//=====================================================================================================================================
+void Renderer::Ms::EarlyZ::init()
+{
+	if( !enabled ) return;
+
+	// create FBO
+	fbo.create();
+	fbo.bind();
+
+	fbo.setNumOfColorAttachements( 0 );
+
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0 );
+
+	if( !fbo.isGood() )
+		FATAL( "Cannot create shadowmapping FBO" );
+
+	fbo.unbind();
+}

+ 1 - 1
src/Renderer/Hdr.cpp

@@ -73,7 +73,7 @@ void Renderer::Pps::Hdr::run()
 {
 	int w = renderingQuality * r.width;
 	int h = renderingQuality * r.height;
-	r.setViewport( 0, 0, w, h );
+	Renderer::setViewport( 0, 0, w, h );
 
 	glDisable( GL_BLEND );
 	glDisable( GL_DEPTH_TEST );

+ 1 - 1
src/Renderer/Is.cpp

@@ -479,7 +479,7 @@ void Renderer::Is::run()
 	fbo.bind();
 
 	// OGL stuff
-	r.setViewport( 0, 0, r.width, r.height );
+	Renderer::setViewport( 0, 0, r.width, r.height );
 
 	glMatrixMode( GL_MODELVIEW );
 	glLoadIdentity();

+ 5 - 4
src/Renderer/Ms.cpp

@@ -50,11 +50,11 @@ void Renderer::Ms::init()
 
 
 //=====================================================================================================================================
-// runStage                                                                                                                           =
+// run                                                                                                                                =
 //=====================================================================================================================================
 void Renderer::Ms::run()
 {
-	Camera& cam = *r.cam;
+	const Camera& cam = *r.cam;
 
 	#if defined( _EARLY_Z_ )
 		// run the early z pass
@@ -67,7 +67,7 @@ void Renderer::Ms::run()
 		glClear( GL_DEPTH_BUFFER_BIT );
 	#endif
 	r.setProjectionViewMatrices( cam );
-	r.setViewport( 0, 0, r.width, r.height );
+	Renderer::setViewport( 0, 0, r.width, r.height );
 
 	//glEnable( GL_DEPTH_TEST );
 	app->getScene()->skybox.Render( cam.getViewMatrix().getRotationPart() );
@@ -84,7 +84,8 @@ void Renderer::Ms::run()
 		MeshNode* meshNode = app->getScene()->meshNodes[i];
 		DEBUG_ERR( meshNode->material == NULL );
 		if( meshNode->material->blends || meshNode->material->refracts ) continue;
-		meshNode->material->setup();
+
+		r.setupMaterial( *meshNode->material, *meshNode, cam );
 		meshNode->render();
 	}
 

+ 85 - 4
src/Renderer/Renderer.cpp

@@ -45,7 +45,7 @@ void Renderer::init( const RendererInitializer& initializer )
 	aspectRatio = float(width)/height;
 
 	// a few sanity checks
-	if( width < 1 || height < 1 )
+	if( width < 10 || height < 10 )
 	{
 		FATAL( "Incorrect width" );
 	}
@@ -90,10 +90,14 @@ void Renderer::drawQuad( int vertCoordsUniLoc )
 //=====================================================================================================================================
 // setupMaterial                                                                                                                      =
 //=====================================================================================================================================
-void Renderer::setupMaterial( const Material& mtl )
+void Renderer::setupMaterial( const Material& mtl, const SceneNode& sceneNode, const Camera& cam )
 {
 	mtl.shaderProg->bind();
+	uint textureUnit = 0;
 
+	//
+	// FFP stuff
+	//
 	if( mtl.blends )
 	{
 		glEnable( GL_BLEND );
@@ -115,8 +119,85 @@ void Renderer::setupMaterial( const Material& mtl )
 		glPolygonMode( GL_FRONT, GL_FILL );
 
 
+	//
+	// matrices
+	//
+	Mat4 modelMat( sceneNode.getWorldTransform() );
+	const Mat4& projectionMat = cam.getProjectionMatrix();
+	const Mat4& viewMat = cam.getViewMatrix();
+	Mat4 modelViewMat;
+	Mat3 normalMat;
+	Mat4 modelViewProjectionMat;
+
+	// should I calculate the modelViewMat ?
+	if( mtl.stdUniVars[ Material::SUV_MODELVIEW_MAT ] ||
+			mtl.stdUniVars[ Material::SUV_MODELVIEWPROJECTION_MAT ] ||
+			mtl.stdUniVars[ Material::SUV_NORMAL_MAT ] )
+	{
+		modelViewMat = Mat4::combineTransformations( viewMat, modelMat );
+	}
+
+	// set all the matrices
+	if( mtl.stdUniVars[ Material::SUV_MODEL_MAT ] )
+		mtl.stdUniVars[ Material::SUV_MODEL_MAT ]->setMat4( &modelMat );
+
+	if( mtl.stdUniVars[ Material::SUV_VIEW_MAT ] )
+		mtl.stdUniVars[ Material::SUV_VIEW_MAT ]->setMat4( &viewMat );
+
+	if( mtl.stdUniVars[ Material::SUV_PROJECTION_MAT ] )
+		mtl.stdUniVars[ Material::SUV_PROJECTION_MAT ]->setMat4( &projectionMat );
+
+	if( mtl.stdUniVars[ Material::SUV_MODELVIEW_MAT ] )
+		mtl.stdUniVars[ Material::SUV_MODELVIEW_MAT ]->setMat4( &modelViewMat );
+
+	if( mtl.stdUniVars[ Material::SUV_NORMAL_MAT ] )
+	{
+		normalMat = modelViewMat.getRotationPart();
+		mtl.stdUniVars[ Material::SUV_NORMAL_MAT ]->setMat3( &normalMat );
+	}
+
+	if( mtl.stdUniVars[ Material::SUV_MODELVIEWPROJECTION_MAT ] )
+	{
+		modelViewProjectionMat = projectionMat * modelViewMat;
+		mtl.stdUniVars[ Material::SUV_MODELVIEWPROJECTION_MAT ]->setMat4( &modelViewProjectionMat );
+	}
+
+
+	//
+	// FAis
+	//
+	if( mtl.stdUniVars[ Material::SUV_MS_NORMAL_FAI ] )
+		mtl.stdUniVars[ Material::SUV_MS_NORMAL_FAI ]->setTexture( ms.normalFai, textureUnit++ );
+
+	if( mtl.stdUniVars[ Material::SUV_MS_DIFFUSE_FAI ] )
+		mtl.stdUniVars[ Material::SUV_MS_DIFFUSE_FAI ]->setTexture( ms.diffuseFai, textureUnit++ );
+
+	if( mtl.stdUniVars[ Material::SUV_MS_SPECULAR_FAI ] )
+		mtl.stdUniVars[ Material::SUV_MS_SPECULAR_FAI ]->setTexture( ms.specularFai, textureUnit++ );
+
+	if( mtl.stdUniVars[ Material::SUV_MS_DEPTH_FAI ] )
+		mtl.stdUniVars[ Material::SUV_MS_DEPTH_FAI ]->setTexture( ms.depthFai, textureUnit++ );
+
+	if( mtl.stdUniVars[ Material::SUV_IS_FAI ] )
+		mtl.stdUniVars[ Material::SUV_IS_FAI ]->setTexture( is.fai, textureUnit++ );
+
+	if( mtl.stdUniVars[ Material::SUV_PPS_FAI ] )
+		mtl.stdUniVars[ Material::SUV_PPS_FAI ]->setTexture( pps.fai, textureUnit++ );
+
+
+	//
+	// Other
+	//
+	if( mtl.stdUniVars[ Material::SUV_RENDERER_SIZE ] )
+	{
+		Vec2 v( width, height );
+		mtl.stdUniVars[ Material::SUV_RENDERER_SIZE ]->setVec2( &v );
+	}
+
+
+	//
 	// now loop all the user defined vars and set them
-	uint textureUnit = 0;
+	//
 	for( uint i=0; i<mtl.userDefinedVars.size(); i++ )
 	{
 		const Material::UserDefinedUniVar* udv = &mtl.userDefinedVars[i];
@@ -175,7 +256,7 @@ Vec3 Renderer::unproject( const Vec3& windowCoords, const Mat4& modelViewMat, co
 	Mat4 invPm = projectionMat * modelViewMat;
 	invPm.invert();
 
-	// the vec is in ndc space meaning: -1<=vec.x<=1 -1<=vec.y<=1 -1<=vec.z<=1
+	// the vec is in NDC space meaning: -1<=vec.x<=1 -1<=vec.y<=1 -1<=vec.z<=1
 	Vec4 vec;
 	vec.x = (2.0*(windowCoords.x-view[0]))/view[2] - 1.0;
 	vec.y = (2.0*(windowCoords.y-view[1]))/view[3] - 1.0;

+ 23 - 9
src/Renderer/Renderer.h

@@ -11,6 +11,7 @@ class Camera;
 class PointLight;
 class SpotLight;
 class RendererInitializer;
+class SceneNode;
 
 
 /**
@@ -43,6 +44,24 @@ class Renderer
 		{
 			friend class Renderer;
 
+			public:
+				/**
+				 * EarlyZ pass
+				 */
+				class EarlyZ: public RenderingStage
+				{
+					PROPERTY_R( bool, enabled, isEnabled )
+
+					private:
+						Fbo fbo;
+
+						void init();
+						void run();
+
+					public:
+						EarlyZ( Renderer& r_ ): RenderingStage( r_ ) {}
+				};
+
 			private:
 				Fbo fbo;
 
@@ -54,8 +73,9 @@ class Renderer
 				Texture diffuseFai;
 				Texture specularFai;
 				Texture depthFai;
+				EarlyZ earlyZ;
 
-				Ms( Renderer& r_ ): RenderingStage( r_ ) {}
+				Ms( Renderer& r_ ): RenderingStage( r_ ), earlyZ( r_ ) {}
 		}; // end Ms
 
 		/**
@@ -328,11 +348,11 @@ class Renderer
 
 	protected:
 		// the rest
-		Camera* cam; ///< Current camera
+		const Camera* cam; ///< Current camera
 		static float quadVertCoords [][2];
 
 		static void drawQuad( int vertCoordsUniLoc );
-		void setupMaterial( const Material& mtl );
+		void setupMaterial( const Material& mtl, const SceneNode& sceneNode, const Camera& cam );
 
 	public:
 		// the stages as data members
@@ -341,12 +361,6 @@ class Renderer
 		Pps pps; ///< Postprocessing rendering stage
 		Dbg dbg; ///< Debugging rendering stage
 
-		// matrices & viewing
-		Mat4 modelViewMat; ///< This changes once for every mesh rendering
-		Mat4 projectionMat; ///< This changes once every frame
-		Mat4 modelViewProjectionMat; ///< This changes just like @ref modelViewMat
-		Mat3 normalMat; ///< The rotation part of modelViewMat
-
 		Renderer();
 
 		/**

+ 2 - 2
src/Renderer/Sm.cpp

@@ -66,7 +66,7 @@ void Renderer::Is::Sm::run( const Camera& cam )
 
 	glClear( GL_DEPTH_BUFFER_BIT );
 	r.setProjectionViewMatrices( cam );
-	r.setViewport( 0, 0, resolution, resolution );
+	Renderer::setViewport( 0, 0, resolution, resolution );
 
 	// disable color & blend & enable depth test
 	glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
@@ -87,7 +87,7 @@ void Renderer::Is::Sm::run( const Camera& cam )
 
 		//meshNode->material->dpMtl->setup();
 		//meshNode->renderDepth();
-		meshNode->material->setup();
+		r.setupMaterial( *meshNode->material, *meshNode, cam );
 		meshNode->render();
 	}
 

+ 2 - 2
src/Renderer/Ssao.cpp

@@ -121,7 +121,7 @@ void Renderer::Pps::Ssao::run()
 
 
 	// 1st pass
-	r.setViewport( 0, 0, width, height );
+	Renderer::setViewport( 0, 0, width, height );
 	pass0Fbo.bind();
 	ssaoSProg.bind();
 	Vec2 camRange( cam.getZNear(), cam.getZFar() );
@@ -132,7 +132,7 @@ void Renderer::Pps::Ssao::run()
 	r.drawQuad( 0 );
 
 	// for 2nd and 3rd passes
-	r.setViewport( 0, 0, bwidth, bheight );
+	Renderer::setViewport( 0, 0, bwidth, bheight );
 
 	// 2nd pass
 	pass1Fbo.bind();

+ 4 - 60
src/Resources/Material.cpp

@@ -31,10 +31,12 @@ Material::StdVarInfo Material::stdUniVarInfos[ SUV_NUM ] =
 {
 	{ "skinningRotations", GL_FLOAT_MAT3},
 	{ "skinningTranslations", GL_FLOAT_VEC3 },
-	{ "modelViewMat", GL_FLOAT_MAT4 },
+	{ "modelMat", GL_FLOAT_MAT4 },
+	{ "viewMat", GL_FLOAT_MAT4 },
 	{ "projectionMat", GL_FLOAT_MAT4 },
-	{ "modelViewProjectionMat", GL_FLOAT_MAT4 },
+	{ "modelViewMat", GL_FLOAT_MAT4 },
 	{ "normalMat", GL_FLOAT_MAT3 },
+	{ "modelViewProjectionMat", GL_FLOAT_MAT4 },
 	{ "msNormalFai", GL_TEXTURE_2D },
 	{ "msDiffuseFai", GL_TEXTURE_2D },
 	{ "msSpecularFai", GL_TEXTURE_2D },
@@ -412,61 +414,3 @@ void Material::unload()
 	}
 }
 
-
-//=====================================================================================================================================
-// setup                                                                                                                              =
-//=====================================================================================================================================
-void Material::setup()
-{
-	shaderProg->bind();
-
-	if( blends )
-	{
-		glEnable( GL_BLEND );
-		//glDisable( GL_BLEND );
-		glBlendFunc( blendingSfactor, blendingDfactor );
-	}
-	else
-		glDisable( GL_BLEND );
-
-
-	if( depthTesting )  glEnable( GL_DEPTH_TEST );
-	else                glDisable( GL_DEPTH_TEST );
-
-	if( wireframe )  glPolygonMode( GL_FRONT, GL_LINE );
-	else             glPolygonMode( GL_FRONT, GL_FILL );
-
-
-	// now loop all the user defined vars and set them
-	uint texture_Unit = 0;
-	Vec<UserDefinedUniVar>::iterator udv;
-	for( udv=userDefinedVars.begin(); udv!=userDefinedVars.end(); udv++ )
-	{
-		switch( udv->sProgVar->getGlDataType() )
-		{
-			// texture
-			case GL_SAMPLER_2D:
-				shaderProg->locTexUnit( udv->sProgVar->getLoc(), *udv->value.texture, texture_Unit++ );
-				break;
-			// float
-			case GL_FLOAT:
-				glUniform1f( udv->sProgVar->getLoc(), udv->value.float_ );
-				break;
-			// vec2
-			case GL_FLOAT_VEC2:
-				glUniform2fv( udv->sProgVar->getLoc(), 1, &udv->value.vec2[0] );
-				break;
-			// vec3
-			case GL_FLOAT_VEC3:
-				glUniform3fv( udv->sProgVar->getLoc(), 1, &udv->value.vec3[0] );
-				break;
-			// vec4
-			case GL_FLOAT_VEC4:
-				glUniform4fv( udv->sProgVar->getLoc(), 1, &udv->value.vec4[0] );
-				break;
-		}
-	}
-}
-
-
-

+ 20 - 11
src/Resources/Material.h

@@ -10,16 +10,19 @@
 /**
  * Mesh material @ref Resource
  *
- * Every material keeps among other things the locations of the attribute and uniform variables. The attributes come from a selection
- * of standard vertex attributes. We dont have to write these attribs in the .mtl file. The uniforms on the other hand are in two
- * categories. The standard uniforms that we dont have to write in the file and the user defined.
+ * Every material keeps info of how to render a @ref MeshNode. Among this info it keeps the locations of attribute and uniform
+ * variables. The variables can be standard or user defined. The standard variables have standard names inside the shader program and
+ * we dont have to mention them in the .mtl files. The material init func scoops the shader program for standard variables and keeps
+ * a pointer to the variable. The standard variables are like the GL build-in variables (that we cannot longer use on GL >3) with a few
+ * additions. The user defined variables are defined and values inside the .mtl file. The attribute variables cannot be user defined,
+ * the uniform on the other hand can.
  */
 class Material: public Resource
 {
 	friend class Renderer;
 	friend class MeshNode;
 
-	protected:
+	private:
 		/**
 		 * Standard attribute variables that are acceptable inside the @ref ShaderProg
 		 */
@@ -38,6 +41,7 @@ class Material: public Resource
 
 		/**
 		 * Standard uniform variables
+		 * Changes here should update some statics and Renderer::setupMaterial
 		 */
 		enum StdUniVars
 		{
@@ -45,10 +49,12 @@ class Material: public Resource
 			SUV_SKINNING_ROTATIONS,
 			SUV_SKINNING_TRANSLATIONS,
 			// Matrices
-			SUV_MODELVIEW_MAT,
+			SUV_MODEL_MAT,
+			SUV_VIEW_MAT,
 			SUV_PROJECTION_MAT,
-			SUV_MODELVIEWPROJECTION_MAT,
+			SUV_MODELVIEW_MAT,
 			SUV_NORMAL_MAT,
+			SUV_MODELVIEWPROJECTION_MAT,
 			// FAIs
 			SUV_MS_NORMAL_FAI,
 			SUV_MS_DIFFUSE_FAI,
@@ -58,6 +64,7 @@ class Material: public Resource
 			SUV_PPS_FAI,
 			// Other
 			SUV_RENDERER_SIZE,
+			// num
 			SUV_NUM ///< The number of standard uniform variables
 		};
 
@@ -77,7 +84,10 @@ class Material: public Resource
 		 */
 		struct UserDefinedUniVar
 		{
-			struct Value  // unfortunately we cannot use union because of Vec3 and Vec4
+			/**
+			 * Unfortunately we cannot use union because of complex classes (Vec2, Vec3 etc)
+			 */
+			struct Value
 			{
 				Texture* texture;
 				float float_;
@@ -116,14 +126,13 @@ class Material: public Resource
 		 */
 		bool initStdShaderVars();
 
+		bool hasHWSkinning() const { return stdAttribVars[ SAV_VERT_WEIGHT_BONES_NUM ] != NULL; }
+		bool hasAlphaTesting() const { return dpMtl!=NULL && dpMtl->stdAttribVars[ SAV_TEX_COORDS ] != NULL; }
+
 	public:
 		Material();
-		void setup();
 		bool load( const char* filename );
 		void unload();
-
-		bool hasHWSkinning() const { return stdAttribVars[ SAV_VERT_WEIGHT_BONES_NUM ] != NULL; }
-		bool hasAlphaTesting() const { return dpMtl!=NULL && dpMtl->stdAttribVars[ SAV_TEX_COORDS ] != NULL; }
 };
 
 

+ 5 - 6
src/Scene/Camera.cpp

@@ -136,7 +136,6 @@ bool Camera::insideFrustum( const bvolume_t& bvol ) const
 //=====================================================================================================================================
 // insideFrustum                                                                                                                      =
 //=====================================================================================================================================
-/// Check if the given camera is inside the frustum cliping planes. This is used mainly to test if the projected lights are visible
 bool Camera::insideFrustum( const Camera& cam ) const
 {
 	//** get five points. These points are the tips of the given camera **
@@ -209,13 +208,13 @@ void Camera::calcProjectionMatrix()
 //=====================================================================================================================================
 void Camera::updateViewMatrix()
 {
-	/* The point at which the camera looks:
-	Vec3 viewpoint = translationLspace + z_axis;
-	as we know the up vector, we can easily use gluLookAt:
-	gluLookAt( translationLspace.x, translationLspace.x, translationLspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x, y_axis.y, y_axis.z );
+	/*
+	 * The point at which the camera looks:
+	 * Vec3 viewpoint = translationLspace + z_axis;
+	 * as we know the up vector, we can easily use gluLookAt:
+	 * gluLookAt( translationLspace.x, translationLspace.x, translationLspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x, y_axis.y, y_axis.z );
 	*/
 
-
 	// The view matrix is: Mview = camera.world_transform.Inverted(). Bus instead of inverting we do the following:
 	Mat3 camInvertedRot = getWorldTransform().getRotation().getTransposed();
 	Vec3 camInvertedTsl = -( camInvertedRot * getWorldTransform().getOrigin() );

+ 12 - 3
src/Scene/Camera.h

@@ -35,11 +35,12 @@ class Camera: public SceneNode
 		// matrices
 		Mat4 projectionMat;
 		Mat4 viewMat;
+
 		/**
 		 * Used in deferred shading for the calculation of view vector (see CalcViewVector). The reason we store this matrix here is
 		 * that we dont want it to be re-calculated all the time but only when the projection params (fovX, fovY, zNear, zFar) change.
-		 * Fortunately the projection params change rarely. Note that the Camera as we all know re-calculates the matreces only when the
-		 * parameteres change!!
+		 * Fortunately the projection params change rarely. Note that the Camera as we all know re-calculates the matrices only when the
+		 * parameters change!!
 		 */
 		Mat4 invProjectionMat;
 
@@ -83,8 +84,16 @@ class Camera: public SceneNode
 		void deinit() {}
 
 		// frustum stuff
+
+		/**
+		 * Check if the given camera is inside the frustum clipping planes. This is used mainly to test if the projected lights are visible
+		 */
 		bool insideFrustum( const bvolume_t& vol ) const;
-		bool insideFrustum( const Camera& cam ) const; // check if another camera is inside our view (used for projected lights)
+
+		/**
+		 * Check if another camera is inside our view (used for projected lights)
+		 */
+		bool insideFrustum( const Camera& cam ) const;
 };