Panagiotis Christopoulos Charitos 15 سال پیش
والد
کامیت
201f676e18

+ 2 - 2
shaders/IsLpGeneric.glsl

@@ -80,7 +80,7 @@ float getAttenuation( in float _frag_light_dist )
 #if defined(_SPOT_LIGHT_) && defined( _SHADOW_ )
 
 /**
- * @return The blured shadow
+ * @return The blurred shadow
  */
 float pcfOff( in vec3 _shadow_uv )
 {
@@ -243,7 +243,7 @@ void main()
 		vec3 _color = phong( _frag_pos_vspace, _frag_light_dist );
 		gl_FragData[0] = vec4( _color * getAttenuation(_frag_light_dist), 1.0 );
 
-		gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + texture2D( msDepthFai, texCoords );
+		//gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + texture2D( msNormalFai, texCoords );
 
 
 	//

+ 2 - 1
src/Math/Mat3.inl.h

@@ -58,7 +58,8 @@ inline Mat3::Mat3( const Mat3& b )
 // constructor [quat]
 inline Mat3::Mat3( const Quat& q )
 {
-	DEBUG_ERR( !isZero( 1.0f - q.getLength()) ); // Not normalized quat
+	const float tolerance = 0.002;
+	DEBUG_ERR( fabs(1.0 - q.getLength()) > tolerance ); // Not normalized quat
 
 	float xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
 

+ 5 - 3
src/Renderer/BufferObjects/Fbo.h

@@ -8,7 +8,7 @@
 /// The class is created as a wrapper to avoid common mistakes
 class Fbo
 {
-	PROPERTY_R( uint, glId, getGlId ) ///< OpenGL idendification
+	PROPERTY_R( uint, glId, getGlId ) ///< OpenGL identification
 
 	public:
 		Fbo(): glId(0) {}
@@ -55,8 +55,10 @@ class Fbo
 			}
 			else
 			{
-				static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
-				                                     GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
+				static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
+				                                     GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
+				                                     GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
+
 				glDrawBuffers( num, colorAttachments );
 			}
 		}

+ 2 - 2
src/Renderer/BufferObjects/Vbo.h

@@ -5,13 +5,13 @@
 #include "BufferObject.h"
 
 /**
- * @brief This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
+ * This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
  */
 class Vbo: public BufferObject
 {
 	public:
 		/**
-		 * @brief It adds an extra check over @ref BufferObject::create. See @ref BufferObject::create for details
+		 * It adds an extra check over @ref BufferObject::create. See @ref BufferObject::create for details
 		 */
 		bool create( GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_ )
 		{

+ 2 - 14
src/Renderer/Is.cpp

@@ -325,7 +325,7 @@ void Renderer::Is::pointLightPass( const PointLight& light )
 	if( !cam.insideFrustum( sphere ) ) return;
 
 	// stencil optimization
-	stencilOptPass( light );
+	//stencilOptPass( light );
 
 	// bind the shader
 	const LightShaderProg& shader = pointLightSProg; // ensure the const-ness
@@ -443,7 +443,7 @@ void Renderer::Is::spotLightPass( const SpotLight& light )
 	static Mat4 biasMat4( 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0 );
 	Mat4 texProjectionMat;
 	texProjectionMat = biasMat4 * light.camera.getProjectionMatrix() *
-	                   Mat4::combineTransformations( light.camera.getViewMatrix(), Mat4(cam.getWorldTransform()) );
+	                   Mat4::combineTransformations( light.camera.getViewMatrix(), Mat4( cam.getWorldTransform() ) );
 	shdr->uniVars.texProjectionMat->setMat4( &texProjectionMat );
 
 	// the shadow stuff
@@ -511,18 +511,6 @@ void Renderer::Is::run()
 			{
 				const PointLight& pointl = static_cast<const PointLight&>(light);
 				pointLightPass( pointl );
-
-
-				/*pointLightSProg.bind();
-				pointLightSProg.findUniVar( "msNormalFai" )->setTexture( r.ms.diffuseFai, 1 );
-				glEnableVertexAttribArray( 0 );
-				glEnableVertexAttribArray( 1 );
-				glVertexAttribPointer( 0, 2, GL_FLOAT, false, 0, &Renderer::quadVertCoords[0] );
-				glVertexAttribPointer( 1, 3, GL_FLOAT, false, 0, &viewVectors[0] );
-				glDrawArrays( GL_QUADS, 0, 4 );
-				glDisableVertexAttribArray( 0 );
-				glDisableVertexAttribArray( 1 );*/
-
 				break;
 			}
 

+ 2 - 1
src/Renderer/MainRenderer.cpp

@@ -55,6 +55,7 @@ void MainRenderer::init( const RendererInitializer& initializer_ )
 	glDisable( GL_LIGHTING );
 	glDisable( GL_TEXTURE_2D );
 	glDisable( GL_BLEND );
+	glDisable( GL_STENCIL_TEST );
 	glPolygonMode( GL_FRONT, GL_FILL );
 	glDepthMask( true );
 	glDepthFunc( GL_LESS );
@@ -89,7 +90,7 @@ void MainRenderer::render( Camera& cam_ )
 	glDisable( GL_DEPTH_TEST );
 	glDisable( GL_BLEND );
 	sProg.bind();
-	sProg.findUniVar("rasterImage")->setTexture( is.fai, 0 );
+	sProg.findUniVar("rasterImage")->setTexture( pps.hdr.pass0Fai, 0 );
 	drawQuad( 0 );
 }
 

+ 8 - 6
src/Renderer/Ms.cpp

@@ -22,19 +22,21 @@ void Renderer::Ms::init()
 	if( !normalFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
 	    !diffuseFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
 	    !specularFai.createEmpty2D( r.width, r.height, internal_format, GL_RGBA ) ||
-	    !depthFai.createEmpty2D( r.width, r.height, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT ) )
+	    //!depthFai.createEmpty2D( r.width, r.height, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ) )
+	    !depthFai.createEmpty2D( r.width, r.height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT ) )
 	{
 		FATAL( "Failed to create one MS FAI. See prev error" );
 	}
 
 
 	// attach the buffers to the FBO
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, normalFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, diffuseFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, specularFai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, normalFai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, diffuseFai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, specularFai.getGlId(), 0 );
 
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
-	glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
+	//glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
+	glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0 );
 
 	// test if success
 	if( !fbo.isGood() )

+ 4 - 3
src/Renderer/Renderer.cpp

@@ -68,8 +68,8 @@ void Renderer::render( Camera& cam_ )
 
 	ms.run();
 	is.run();
-	/*pps.run();
-	dbg.run();*/
+	pps.run();
+	//dbg.run();
 
 	++framesNum;
 }
@@ -252,7 +252,8 @@ void Renderer::setViewMatrix( const Camera& cam )
 //======================================================================================================================
 // unproject                                                                                                           =
 //======================================================================================================================
-Vec3 Renderer::unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat, const int view[4] )
+Vec3 Renderer::unproject( const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat,
+                          const int view[4] )
 {
 	Mat4 invPm = projectionMat * modelViewMat;
 	invPm.invert();

+ 4 - 3
src/Renderer/Sm.cpp

@@ -27,9 +27,10 @@ void Renderer::Is::Sm::init()
 	shadowMap.texParameter( GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
 	shadowMap.texParameter( GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
 	/*
-	 * If you dont want to use the FFP for comparing the shadwomap (the above two lines) then you can make the comparision inside the
-	 * glsl shader. The GL_LEQUAL means that: shadow = ( R <= Dt ) ? 1.0 : 0.0; . The R is given by: R = _tex_coord2.z/_tex_coord2.w;
-	 * and the Dt = shadow2D(shadow_depth_map, _shadow_uv ).r (see lp_generic.frag). Hardware filters like GL_LINEAR cannot be applied.
+	 * If you dont want to use the FFP for comparing the shadwomap (the above two lines) then you can make the comparison
+	 * inside the glsl shader. The GL_LEQUAL means that: shadow = ( R <= Dt ) ? 1.0 : 0.0; . The R is given by:
+	 * R = _tex_coord2.z/_tex_coord2.w; and the Dt = shadow2D(shadow_depth_map, _shadow_uv ).r (see lp_generic.frag).
+	 * Hardware filters like GL_LINEAR cannot be applied.
 	 */
 
 	// inform the we wont write to color buffers

+ 5 - 11
src/Util/Common.cpp

@@ -4,8 +4,7 @@
 
 
 // for the colors and formating see http://www.dreamincode.net/forums/showtopic75171.htm
-static const char* terminalColors [ MT_NUM + 1 ] =
-{
+static const char* terminalColors [ MT_NUM + 1 ] = {
 	"\033[1;31;6m", // error
 	"\033[1;33;6m", // warning
 	"\033[1;31;6m", // fatal
@@ -21,11 +20,9 @@ static const char* terminalColors [ MT_NUM + 1 ] =
 ostream& msgPrefix( MsgType msgType, const char* file, int line, const char* func )
 {
 	if( app == NULL )
-		exit( 1 );
+		::exit( 1 );
 
-	//
 	// select c stream
-	//
 	ostream* cs;
 
 	switch( msgType )
@@ -46,18 +43,14 @@ ostream& msgPrefix( MsgType msgType, const char* file, int line, const char* fun
 	}
 
 
-	//
 	// print terminal color
-	//
 	if( app->isTerminalColoringEnabled() )
 	{
 		(*cs) << terminalColors[ msgType ];
 	}
 
 
-	//
 	// print message info
-	//
 	switch( msgType )
 	{
 		case MT_ERROR:
@@ -84,9 +77,7 @@ ostream& msgPrefix( MsgType msgType, const char* file, int line, const char* fun
 			break;
 	}
 
-	//
 	// print caller info
-	//
 	(*cs) << " (" << Util::cutPath( file ) << ":" << line << " " << Util::getFunctionFromPrettyFunction( func ) << "): ";
 
 	return (*cs);
@@ -98,6 +89,9 @@ ostream& msgPrefix( MsgType msgType, const char* file, int line, const char* fun
 //======================================================================================================================
 ostream& msgSuffix( ostream& cs )
 {
+	if( app == NULL )
+		::exit( 1 );
+
 	if( app->isTerminalColoringEnabled() )
 		cs << terminalColors[ MT_NUM ];