Explorar el Código

- Splitting the Pps in two passes
- Refactiring shaders

Panagiotis Christopoulos Charitos hace 15 años
padre
commit
26f6a93dd5

+ 55 - 55
build/genmakefile.py

@@ -3,12 +3,12 @@ import sys, os, fnmatch, random, re
 from threading import Thread
 
 
-#======================================================================================================================================
-# GLOBAL VARS                                                                                                                         =
-#======================================================================================================================================
+#=======================================================================================================================
+# GLOBAL VARS                                                                                                          =
+#=======================================================================================================================
 sourcePaths = []
 precompiledHeaders = []
-executableName = "unamed_project"
+executableName = "unamed-project"
 compiler = ""
 compilerFlags = ""
 precompiledHeadersFlags = ""
@@ -17,54 +17,54 @@ sourceFilesRegExpr = r".*\.[c++|cpp|cc|cxx|C|c]"
 includePaths = []
 
 
-#======================================================================================================================================
-# getCommandOutput                                                                                                                    =
-#======================================================================================================================================
-def getCommandOutput( command ):
+#=======================================================================================================================
+# getCommandOutput                                                                                                     =
+#=======================================================================================================================
+def getCommandOutput(command):
 	child = os.popen(command)
 	data = child.read()
 	err = child.close()
 	if err:
-		print( "getCommandOutput failed:\n" + command )
-		exit( 0 )
+		print("getCommandOutput failed:\n" + command)
+		exit(0)
 	return data
 
 
-#======================================================================================================================================
-# Threads                                                                                                                             =
-#======================================================================================================================================
+#=======================================================================================================================
+# Threads                                                                                                              =
+#=======================================================================================================================
 threadList = []
 
-class TargetThread( Thread ):
-	def __init__( self, tid, range ):
-		Thread.__init__( self )
+class TargetThread(Thread):
+	def __init__(self, tid, range):
+		Thread.__init__(self)
 		self.tid = tid
 		self.range = range
 		self.out_str = ""
 		
-	def run( self ):
+	def run(self):
 		for i in self.range:
 			source_file = sourceFiles[i]
-			self.out_str += getCommandOutput( compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile )
+			self.out_str += getCommandOutput(compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile)
 			self.out_str += "\t@echo Compiling " + source_file.cppFile + "...\n"
 			self.out_str += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.cppFile + " -o " + \
 			                source_file.objFile + "\n\n"
-			#print( "Im thread %d and I will make depends for %s" %(self.tid, source_file.fname) )
-			#print( "Im thread %d and my i is %d" %(self.tid, i) )
+			#print("Im thread %d and I will make depends for %s" %(self.tid, source_file.fname))
+			#print("Im thread %d and my i is %d" %(self.tid, i))
 
 
-#======================================================================================================================================
-# SourceFile                                                                                                                          =
-#======================================================================================================================================
+#=======================================================================================================================
+# SourceFile                                                                                                           =
+#=======================================================================================================================
 class SourceFile:
-	def __init__( self ):	
+	def __init__(self):	
 		self.cppFile = ""
 		self.objFile = ""
 
 
-#======================================================================================================================================
-# main                                                                                                                                =
-#======================================================================================================================================
+#=======================================================================================================================
+# main                                                                                                                 =
+#=======================================================================================================================
 
 # Read the arguments
 inputCfgFile = ""
@@ -77,12 +77,12 @@ while 1:
 
 	arg = sys.argv[i]
 	if arg == "-h" or arg == "-help" or arg == "--help":
-		print( "Makefile generator by GODlike" )
-		print( "usage: " + sys.argv[0] + " [options] [-i input] [-o output]" )
-		print( "options:" )
-		print( "-h, -help, --help  Print this text" )
-		print( "-i                 Input config file. Default: gen.cfg.py" )
-		print( "-o                 Output makefile. Default: Makefile" )
+		print("Makefile generator by GODlike")
+		print("usage: " + sys.argv[0] + " [options] [-i input] [-o output]")
+		print("options:")
+		print("-h, -help, --help  Print this text")
+		print("-i                 Input config file. Default: gen.cfg.py")
+		print("-o                 Output makefile. Default: Makefile")
 		exit(0)
 	elif arg == "-i":
 		inputCfgFile = sys.argv[i+1]
@@ -91,7 +91,7 @@ while 1:
 		outputMakefile = sys.argv[i+1]
 		i = i+1
 	else:
-		print( "Unrecognized argument " + arg )
+		print("Unrecognized argument " + arg)
 	
 
 if outputMakefile == "":
@@ -101,52 +101,52 @@ if inputCfgFile == "":
 
 
 # Check if cfg exists
-if not os.path.exists( inputCfgFile ):
-	print( "File " + inputCfgFile + " doesn't exist" )
+if not os.path.exists(inputCfgFile):
+	print("File " + inputCfgFile + " doesn't exist")
 	exit(0)
 
 
 # compile the cfg
 source = ""
-f = open( inputCfgFile, "r" )
+f = open(inputCfgFile, "r")
 for line in f.readlines():
 	source += line
 	
-exec( compile( source, inputCfgFile, "exec" ) )
+exec(compile(source, inputCfgFile, "exec"))
 
 
 # find the cpp files
 sourceFiles = []
-regexpr = re.compile( sourceFilesRegExpr )
+regexpr = re.compile(sourceFilesRegExpr)
 for sourceDir in sourcePaths:
-	files = os.listdir( sourceDir )
+	files = os.listdir(sourceDir)
 	for file_ in files:
-		if not regexpr.match( file_ ): continue
+		if not regexpr.match(file_): continue
 		
 		sfile = SourceFile()
 		
-		(fname_wo_ext, ext) = os.path.splitext( file_ )
+		(fname_wo_ext, ext) = os.path.splitext(file_)
 		sfile.cppFile = sourceDir + "/" + file_
 		sfile.objFile = fname_wo_ext + ".o"
 		
 		# search all the source files and resolve conflicts in .o
 		for sfile1 in sourceFiles:
 			if sfile1.objFile == sfile.objFile:
-				print( "There is a naming conflict between \"" + sfile1.cppFile + "\" and \"" + sfile.cppFile + "\" but dont worry." )
+				print("There is a naming conflict between \"" + sfile1.cppFile + "\" and \"" + sfile.cppFile + "\" but dont worry.")
 				random.seed()
 				sfile.objFile = str(random.randint(1,99)) + "." + sfile.objFile;
 	
-		sourceFiles.append( sfile )
+		sourceFiles.append(sfile)
 	
 
 # now the precompiled headers
 phFiles = []
 for header in precompiledHeaders:
 	sFile = SourceFile()
-	(fnameWoExt, ext) = os.path.splitext( header )
+	(fnameWoExt, ext) = os.path.splitext(header)
 	sFile.cppFile = header
 	sFile.objFile = os.path.basename(fnameWoExt) + ".gch"
-	phFiles.append( sFile )
+	phFiles.append(sFile)
 
 
 # build the string
@@ -188,8 +188,8 @@ masterStr += "\t@echo All Done!\n\n"
 
 
 for header in phFiles:
-  #            getCommandOutput( compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile )
-	dependStr = getCommandOutput( compiler + " -MM " + compilerFlags + " " + header.cppFile + " -MT " + header.objFile )
+  #            getCommandOutput(compiler + " -MM " + compilerFlags + " " + source_file.cppFile + " -MT " + source_file.objFile)
+	dependStr = getCommandOutput(compiler + " -MM " + compilerFlags + " " + header.cppFile + " -MT " + header.objFile)
 	masterStr += dependStr
 	masterStr += "\t@echo Pre-compiling header " + header.cppFile + "...\n"
 	masterStr += "\t@$(CXX) $(INCPATH) $(PHFLAGS) " + header.objFile + "\n\n"
@@ -197,7 +197,7 @@ for header in phFiles:
 
 # write source file target
 threadsNum = os.sysconf('SC_NPROCESSORS_ONLN')
-print( "I will invoke %d threads to make the dependencies..." % threadsNum )
+print("I will invoke %d threads to make the dependencies..." % threadsNum)
 num = len(sourceFiles);
 itemsPerThread = num // threadsNum;
 
@@ -207,9 +207,9 @@ for i in range(0, threadsNum):
 		end = num
 	else:
 		end = begin + itemsPerThread	
-	thread = TargetThread( i, range( int(begin), int(end) ) )
+	thread = TargetThread(i, range(int(begin), int(end)))
 	thread.start()
-	threadList.append( thread )
+	threadList.append(thread)
 
 for thread in threadList:
 	thread.join()
@@ -219,7 +219,7 @@ for thread in threadList:
 
 #for source_file in sourceFiles:	
 	#masterStr += source_file.fname_wo_ext + ".o: " + source_file.path + source_file.fname_wo_ext + ".cpp"
-	#masterStr += getCommandOutput( compiler + " -M " + compilerFlags + " " + source_file.path + "/" + source_file.fname )
+	#masterStr += getCommandOutput(compiler + " -M " + compilerFlags + " " + source_file.path + "/" + source_file.fname)
 	#masterStr += "\t@echo Compiling " + source_file.fname + "...\n"
 	#masterStr += "\t@$(CXX) $(INCPATH) $(CFLAGS) " + source_file.path + "/" + source_file.fname + "\n\n"
 
@@ -232,6 +232,6 @@ masterStr += "\trm -f $(EXECUTABLE)\n\n"
 
 
 # write file
-f = open( outputMakefile, "w" )
-f.write( masterStr )
-print( "File \"" + outputMakefile + "\" created!" )
+f = open(outputMakefile, "w")
+f.write(masterStr)
+print("File \"" + outputMakefile + "\" created!")

+ 2 - 0
docs/readme

@@ -261,4 +261,6 @@ ToDo list
 - Enable depth test before skybox rendering to see what happens -> Forgot to
   disable the test
 - Re-enable the stencil tex in Ms.cpp
+- See if the restrictions in FBOs (all FAIs same size) still apply
+- Remove the EXT from some GL funcs
 

+ 1 - 1
shaders/IsAp.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 0 - 191
shaders/Pps.glsl

@@ -1,191 +0,0 @@
-#pragma anki vertShaderBegins
-
-#pragma anki include "shaders/simple_vert.glsl"
-
-#pragma anki fragShaderBegins
-
-#pragma anki include "shaders/photoshop_filters.glsl"
-#pragma anki include "shaders/median_filter.glsl"
-
-uniform sampler2D isFai;
-uniform sampler2D ppsSsaoFai;
-uniform sampler2D msNormalFai;
-uniform sampler2D ppsHdrFai;
-uniform sampler2D ppsLscattFai;
-
-varying vec2 texCoords;
-
-
-/*
-=======================================================================================================================================
-GrayScale                                                                                                                             =
-=======================================================================================================================================
-*/
-vec3 GrayScale( in vec3 _col )
-{
-	float _grey = (_col.r + _col.g + _col.b) * 0.333333333; // aka: / 3.0
-	return vec3(_grey);
-}
-
-
-/*
-=======================================================================================================================================
-Saturation                                                                                                                            =
-=======================================================================================================================================
-*/
-vec3 Saturation( in vec3 _col, in float _satur_factor )
-{
-	const vec3 lumCoeff = vec3 ( 0.2125, 0.7154, 0.0721);
-
-	vec3 intensity = vec3( dot(_col, lumCoeff) );
-	return mix( intensity, _col, _satur_factor );
-}
-
-
-/*
-=======================================================================================================================================
-EdgeAA                                                                                                                                =
-=======================================================================================================================================
-*/
-#if defined(_EDGEAA_)
-
-vec3 EdgeAA()
-{
-	ivec2 texSize = textureSize(msNormalFai,0);
-	vec2 pixelsize = vec2( 1.0/(float(texSize.x)), 1.0/(float(texSize.y)) );
-	const vec2 kernel[8] = vec2[]( vec2(-1.0,1.0), vec2(1.0,-1.0), vec2(-1.0,-1.0), vec2(1.0,1.0), vec2(-1.0,0.0), vec2(1.0,0.0), vec2(0.0,-1.0), vec2(0.0,1.0) );
-	const float weight = 1.0;
-
-	vec3 tex = texture2D( msNormalFai, texCoords ).rgb;
-	float factor = -0.5;
-
-	for( int i=0; i<4; i++ )
-	{
-		vec3 t = texture2D( msNormalFai, texCoords + kernel[i]*pixelsize ).rgb;
-		t -= tex;
-		factor += dot(t, t);
-	}
-
-	factor = min(1.0, factor) * weight;
-
-	//return vec3(factor);
-	//if( factor < 0.01 ) return texture2D( isFai, texCoords ).rgb;
-
-	vec3 color = vec3(0.0);
-
-	for( int i=0; i<8; i++ )
-	{
-		color += texture2D( isFai, texCoords + kernel[i]*pixelsize*factor ).rgb;
-	}
-
-	color += 2.0 * texture2D( isFai, texCoords ).rgb;
-
-	return color*(1.0/9.0);
-
-//	const float aob = 1.0; // area of blur
-//
-//	vec2 kernel[8];
-//	kernel[0] = vec2(-aob,aob);
-//	kernel[1] = vec2(aob,-aob);
-//	kernel[2] = vec2(-aob,-aob);
-//	kernel[3] = vec2(aob,aob);
-//	kernel[4] = vec2(-aob,0);
-//	kernel[5] = vec2(aob,0);
-//	kernel[6] = vec2(0,-aob);
-//	kernel[7] = vec2(0,aob);
-//
-//	vec2 pixelsize = vec2( 1.0/R_W, 1.0/R_H );
-//
-//	float d = ReadLinearDepth( texCoords );
-//	float factor = 0.0;
-//
-//	const float weight = 8.0;
-//
-//	for( int i=0; i<4; i++ )
-//	{
-//		float ds = ReadLinearDepth( texCoords + kernel[i]*pixelsize );
-//
-//		factor += abs(d - ds);
-//	}
-//
-//	factor = (factor / 4)*weight;
-//
-//	//return vec3(factor);
-//
-//	/*if( factor < 0.001 )
-//	{
-//		return texture2D( isFai, texCoords ).rgb;
-//	}*/
-//
-//	vec3 color = vec3(0.0);
-//
-//	for( int i=0; i<8; i++ )
-//	{
-//		color += texture2D( isFai, texCoords + kernel[i]*pixelsize*factor ).rgb;
-//	}
-//
-//	color += 2.0 * texture2D( isFai, texCoords ).rgb;
-//
-//	return color*(1.0/10.0);
-}
-#endif
-
-
-/*
-=======================================================================================================================================
-main                                                                                                                                  =
-=======================================================================================================================================
-*/
-void main (void)
-{
-	vec3 color;
-
-	#if defined(_EDGEAA_)
-		color = EdgeAA();
-	#else
-		color = texture2D( isFai, texCoords ).rgb;
-	#endif
-
-	/*const float gamma = 0.7;
-	color.r = pow(color.r, 1.0 / gamma);
-	color.g = pow(color.g, 1.0 / gamma);
-	color.b = pow(color.b, 1.0 / gamma);*/
-
-	#if defined(_SSAO_)
-		float ssao_factor = texture2D( ppsSsaoFai, texCoords ).a;
-		color *= ssao_factor;
-	#endif
-
-	#if defined(_LSCATT_)
-		vec3 lscatt = texture2D( ppsLscattFai, texCoords ).rgb;
-		color += lscatt;
-	#endif
-
-	#if defined(_HDR_)
-		vec3 hdr = texture2D( ppsHdrFai, texCoords ).rgb;
-		color += hdr;
-	#endif
-
-	/*vec4 sample[9];
-	for(int i = 0; i < 9; i++)
-	{
-		sample[i] = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);
-	}
-	color = (sample[4] * 9.0) - (sample[0] + sample[1] + sample[2] + sample[3] + sample[5] + sample[6] + sample[7] + sample[8]);*/
-
-	color = BlendHardLight( vec3(0.6, 0.62, 0.4), color );
-
-	gl_FragData[0].rgb = color;
-
-	//gl_FragColor = vec4( color, 1.0 );
-	//gl_FragColor = vec4( GrayScale(gl_FragColor.rgb), 1.0 );
-	//gl_FragData[0] = vec4( ssao_factor );
-	//gl_FragData[0] = vec4( lscatt, 1.0 );
-	//gl_FragData[0] = vec4( bloom_factor );
-	//gl_FragColor = vec4( EdgeAA(), 1.0 );
-	//gl_FragColor = texture2D( pps_boom_fai, texCoords );
-	//gl_FragColor = texture2D( isFai, texCoords );
-	//gl_FragData[0].rgb = UnpackNormal( texture2D( msNormalFai, texCoords ).rg );
-	//gl_FragData[0] = vec4( hdr, 1.0 );
-}
-

+ 1 - 1
shaders/PpsHdr.glsl

@@ -5,7 +5,7 @@
 
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 1 - 1
shaders/PpsLscatt.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 59 - 0
shaders/PpsPostPass.glsl

@@ -0,0 +1,59 @@
+#pragma anki vertShaderBegins
+
+#pragma anki include "shaders/SimpleVert.glsl"
+
+#pragma anki fragShaderBegins
+
+#pragma anki include "shaders/photoshop_filters.glsl"
+#pragma anki include "shaders/median_filter.glsl"
+
+uniform sampler2D ppsPrePassFai;
+uniform sampler2D ppsHdrFai;
+
+varying vec2 texCoords;
+
+
+//======================================================================================================================
+// GrayScale                                                                                                           =
+//======================================================================================================================
+vec3 grayScale(in vec3 col)
+{
+	float grey = (col.r + col.g + col.b) * 0.333333333; // aka: / 3.0
+	return vec3(grey);
+}
+
+
+//======================================================================================================================
+// saturation                                                                                                          =
+//======================================================================================================================
+vec3 saturation(in vec3 col, in float factor)
+{
+	const vec3 lumCoeff = vec3(0.2125, 0.7154, 0.0721);
+
+	vec3 intensity = vec3(dot(col, lumCoeff));
+	return mix(intensity, col, factor);
+}
+
+
+//======================================================================================================================
+// main                                                                                                                =
+//======================================================================================================================
+void main(void)
+{
+	vec3 color = texture2D(ppsPrePassFai, texCoords).rgb;
+
+	/*const float gamma = 0.7;
+	color.r = pow(color.r, 1.0 / gamma);
+	color.g = pow(color.g, 1.0 / gamma);
+	color.b = pow(color.b, 1.0 / gamma);*/
+
+	#if defined(HDR_ENABLED)
+		vec3 hdr = texture2D(ppsHdrFai, texCoords).rgb;
+		color += hdr;
+	#endif
+
+	color = BlendHardLight(vec3(0.6, 0.62, 0.4), color);
+
+	gl_FragData[0].rgb = color;
+}
+

+ 27 - 0
shaders/PpsPrePass.glsl

@@ -0,0 +1,27 @@
+#pragma anki vertShaderBegins
+
+#pragma anki include "shaders/SimpleVert.glsl"
+
+#pragma anki fragShaderBegins
+
+uniform sampler2D isFai;
+uniform sampler2D ppsSsaoFai;
+
+varying vec2 texCoords;
+
+
+//======================================================================================================================
+// main                                                                                                                =
+//======================================================================================================================
+void main(void)
+{
+	vec3 color = texture2D(isFai, texCoords).rgb;
+
+	#if defined(SSAO_ENABLED)
+		float ssaoFactor = texture2D(ppsSsaoFai, texCoords).a;
+		color *= ssaoFactor;
+	#endif
+
+	gl_FragData[0].rgb = color;
+}
+

+ 1 - 1
shaders/PpsSsao.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 1 - 1
shaders/PpsSsaoBlur.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 0 - 0
shaders/simple_vert.glsl → shaders/SimpleVert.glsl


+ 1 - 2
shaders/bs_refract.glsl

@@ -1,7 +1,6 @@
-//
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 1 - 1
shaders/final.glsl

@@ -1,6 +1,6 @@
 #pragma anki vertShaderBegins
 
-#pragma anki include "shaders/simple_vert.glsl"
+#pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki fragShaderBegins
 

+ 8 - 4
src/Renderer/Bs.cpp

@@ -1,4 +1,7 @@
 #include "Renderer.h"
+#include "App.h"
+#include "Scene.h"
+#include "MeshNode.h"
 
 
 //======================================================================================================================
@@ -11,10 +14,10 @@ void Renderer::Bs::createFbo()
 
 	fbo.setNumOfColorAttachements(1);
 
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.fai.getGlId(), 0); /// @todo the FAI will change
+	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.prePassFai.getGlId(), 0);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	if(!fbo.isGood()) FATAL( "Cannot create deferred shading blending stage FBO" );
+	if(!fbo.isGood()) FATAL("Cannot create deferred shading blending stage FBO");
 
 	fbo.unbind();
 }
@@ -32,7 +35,7 @@ void Renderer::Bs::createRefractFbo()
 
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, refractFai.getGlId(), 0);
 
-	if(!fbo.isGood()) FATAL( "Cannot create deferred shading blending stage FBO" );
+	if(!fbo.isGood()) FATAL("Cannot create deferred shading blending stage FBO");
 
 	fbo.unbind();
 }
@@ -66,7 +69,8 @@ void Renderer::Bs::run()
 		r.setupMaterial(*meshNode->material, *meshNode, *r.cam);
 
 		// refracts
-		if(meshNode->material->stdUniVars[Material::SUV_PPS_FAI])
+		if(meshNode->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI] ||
+		   meshNode->material->stdUniVars[Material::SUV_PPS_POST_PASS_FAI])
 		{
 
 		}

+ 1 - 1
src/Renderer/Dbg.cpp

@@ -187,7 +187,7 @@ void Renderer::Dbg::init()
 	fbo.setNumOfColorAttachements(1);
 
 	// attach the textures
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.fai.getGlId(), 0);
+	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r.pps.postPassFai.getGlId(), 0);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
 	// test if success

+ 1 - 1
src/Renderer/MainRenderer.cpp

@@ -99,7 +99,7 @@ void MainRenderer::render(Camera& cam_)
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
 	sProg.bind();
-	sProg.findUniVar("rasterImage")->setTexture(pps.fai, 0);
+	sProg.findUniVar("rasterImage")->setTexture(pps.postPassFai, 0);
 	drawQuad(0);
 }
 

+ 74 - 47
src/Renderer/Pps.cpp

@@ -8,105 +8,132 @@
 
 
 //======================================================================================================================
-// init                                                                                                                =
+// initPassFbo                                                                                                         =
 //======================================================================================================================
-void Renderer::Pps::init()
+void Renderer::Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
 {
-	// create FBO
 	fbo.create();
 	fbo.bind();
 
-	// inform in what buffers we draw
 	fbo.setNumOfColorAttachements(1);
 
-	// create the texes
 	fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT, false);
 
-	// attach
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0);
 
-	// test if success
 	if(!fbo.isGood())
-		FATAL("Cannot create post-processing stage FBO");
+		FATAL(msg);
 
 	fbo.unbind();
+}
 
 
-	// init the shader and it's vars
+//======================================================================================================================
+// initPrePassSProg                                                                                                    =
+//======================================================================================================================
+void Renderer::Pps::initPrePassSProg()
+{
 	string pps = "";
+	if(ssao.enabled)
+		pps += "#define SSAO_ENABLED\n";
+
+	prePassSProg.customLoad("shaders/PpsPrePass.glsl", pps.c_str());
+	prePassSProg.bind();
+
 	if(ssao.enabled)
 	{
-		pps += "#define _SSAO_\n";
+		prePassSProg.uniVars.ppsSsaoFai = prePassSProg.findUniVar("ppsSsaoFai");
 	}
 
+	prePassSProg.uniVars.isFai = prePassSProg.findUniVar("isFai");
+}
+
+
+//======================================================================================================================
+// initPostPassSProg                                                                                                   =
+//======================================================================================================================
+void Renderer::Pps::initPostPassSProg()
+{
+	string pps = "";
 	if(hdr.enabled)
-	{
-		pps += "#define _HDR_\n";
-	}
+		pps += "#define HDR_ENABLED\n";
+
+	postPassSProg.customLoad("shaders/PpsPostPass.glsl", pps.c_str());
+	postPassSProg.bind();
 
-	sProg.customLoad("shaders/Pps.glsl", pps.c_str());
-	sProg.bind();
+	if(hdr.enabled)
+		postPassSProg.uniVars.ppsSsaoFai = postPassSProg.findUniVar("ppsHdrFai");
+
+	postPassSProg.uniVars.ppsPrePassFai = postPassSProg.findUniVar("ppsPrePassFai");
+}
 
-	sProg.uniVars.isFai = sProg.findUniVar("isFai");
 
+//======================================================================================================================
+// init                                                                                                                =
+//======================================================================================================================
+void Renderer::Pps::init()
+{
 	if(ssao.enabled)
-	{
 		ssao.init();
-		sProg.uniVars.ppsSsaoFai = sProg.findUniVar("ppsSsaoFai");
-	}
 
 	if(hdr.enabled)
-	{
 		hdr.init();
-		sProg.uniVars.hdrFai = sProg.findUniVar("ppsHdrFai");
-	}
 
-	/// @ todo enable lscatt
-	/*if(R::Pps::Lscatt::enabled)
-	{
-		R::Pps::Lscatt::init();
-		sProg.uniVars.lscattFai = sProg.findUniVar("ppsLscattFai")->getLoc();
-	}*/
+	initPassFbo(prePassFbo, prePassFai, "Cannot create pre-pass post-processing stage FBO");
+	initPassFbo(postPassFbo, postPassFai, "Cannot create post-pass post-processing stage FBO");
 
+	initPrePassSProg();
+	initPostPassSProg();
 }
 
 
 //======================================================================================================================
-// run                                                                                                                 =
+// runPrePass                                                                                                          =
 //======================================================================================================================
-void Renderer::Pps::run()
+void Renderer::Pps::runPrePass()
 {
 	if(ssao.enabled)
 		ssao.run();
 
+	prePassFbo.bind();
+
+	glDisable(GL_DEPTH_TEST);
+	glDisable(GL_BLEND);
+	Renderer::setViewport(0, 0, r.width, r.height);
+
+	prePassSProg.bind();
+	prePassSProg.uniVars.isFai->setTexture(r.is.fai, 0);
+
+	if(ssao.enabled)
+		prePassSProg.uniVars.ppsSsaoFai->setTexture(ssao.fai, 1);
+
+	Renderer::drawQuad(0);
+
+	Fbo::unbind();
+}
+
+
+//======================================================================================================================
+// runPostPass                                                                                                         =
+//======================================================================================================================
+void Renderer::Pps::runPostPass()
+{
 	if(hdr.enabled)
 		hdr.run();
 
-	fbo.bind();
+	postPassFbo.bind();
 
-	// set GL
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
-
 	Renderer::setViewport(0, 0, r.width, r.height);
 
-	// set shader
-	sProg.bind();
-	sProg.uniVars.isFai->setTexture(r.is.fai, 0);
+	postPassSProg.bind();
+	postPassSProg.uniVars.ppsPrePassFai->setTexture(prePassFai, 0);
 
 	if(hdr.enabled)
-	{
-		sProg.uniVars.hdrFai->setTexture(hdr.fai, 1);
-	}
+		postPassSProg.uniVars.hdrFai->setTexture(hdr.fai, 1);
 
-	if(ssao.enabled)
-	{
-		sProg.uniVars.ppsSsaoFai->setTexture(ssao.fai, 2);
-	}
-
-	// draw quad
 	Renderer::drawQuad(0);
 
-	// unbind FBO
-	fbo.unbind();
+	Fbo::unbind();
 }

+ 7 - 3
src/Renderer/Renderer.cpp

@@ -73,7 +73,8 @@ void Renderer::render(Camera& cam_)
 
 	ms.run();
 	is.run();
-	pps.run();
+	pps.runPrePass();
+	pps.runPostPass();
 	dbg.run();
 
 	++framesNum;
@@ -190,8 +191,11 @@ void Renderer::setupMaterial(const Material& mtl, const SceneNode& sceneNode, co
 	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++);
+	if(mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
+		mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI]->setTexture(pps.prePassFai, textureUnit++);
+
+	if(mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])
+		mtl.stdUniVars[Material::SUV_PPS_PRE_PASS_FAI]->setTexture(pps.postPassFai, textureUnit++);
 
 
 	//

+ 25 - 18
src/Renderer/Renderer.h

@@ -226,6 +226,7 @@ class Renderer
 		class Pps: private RenderingStage
 		{
 			friend class Renderer;
+			friend class MainRenderer;
 
 			public:
 				/**
@@ -318,36 +319,42 @@ class Renderer
 						Ssao(Renderer& r_): RenderingStage(r_) {}
 				}; // end Ssao
 
-
-			PROPERTY_R(bool, enabled, isEnabled)
-			PROPERTY_R(float, renderingQuality, getRenderingQuality)
-
-			public:
-				Texture fai;
-				Hdr hdr;
-				Ssao ssao;
-
-				Pps(Renderer& r_): RenderingStage(r_), hdr(r_), ssao(r_) {}
-
-			private:
+				/// Custom ShaderProg
 				class PpsShaderProg: public ShaderProg
 				{
 					public:
 						struct
 						{
 							const ShaderProg::UniVar* isFai;
+							const ShaderProg::UniVar* ppsPrePassFai;
 							const ShaderProg::UniVar* ppsSsaoFai;
-							const ShaderProg::UniVar* msNormalFai;
 							const ShaderProg::UniVar* hdrFai;
-							const ShaderProg::UniVar* lscattFai;
-
 						} uniVars;
 				};
-				PpsShaderProg sProg;
-				Fbo fbo;
 
+			PROPERTY_R(bool, enabled, isEnabled)
+			PROPERTY_R(float, renderingQuality, getRenderingQuality)
+
+			public:
+				Hdr hdr;
+				Ssao ssao;
+
+				Pps(Renderer& r_): RenderingStage(r_), hdr(r_), ssao(r_) {}
+
+			private:
+				Texture prePassFai;
+				Texture postPassFai;
+				Fbo prePassFbo;
+				Fbo postPassFbo;
+				PpsShaderProg prePassSProg;
+				PpsShaderProg postPassSProg;
+
+				void initPassFbo(Fbo& fbo, Texture& fai, const char* msg);
+				void initPrePassSProg();
+				void initPostPassSProg();
 				void init();
-				void run();
+				void runPrePass();
+				void runPostPass();
 		}; // end Pps
 
 		/**

+ 26 - 25
src/Resources/Material.cpp

@@ -18,34 +18,35 @@
 //======================================================================================================================
 Material::StdVarInfo Material::stdAttribVarInfos[SAV_NUM] =
 {
-	{ "position", GL_FLOAT_VEC3 },
-	{ "tangent", GL_FLOAT_VEC4 },
-	{ "normal", GL_FLOAT_VEC3 },
-	{ "texCoords", GL_FLOAT_VEC2 },
-	{ "vertWeightBonesNum", GL_FLOAT },
-	{ "vertWeightBoneIds", GL_FLOAT_VEC4},
-	{ "vertWeightWeights", GL_FLOAT_VEC4 }
+	{"position", GL_FLOAT_VEC3},
+	{"tangent", GL_FLOAT_VEC4},
+	{"normal", GL_FLOAT_VEC3},
+	{"texCoords", GL_FLOAT_VEC2},
+	{"vertWeightBonesNum", GL_FLOAT},
+	{"vertWeightBoneIds", GL_FLOAT_VEC4},
+	{"vertWeightWeights", GL_FLOAT_VEC4}
 };
 
 Material::StdVarInfo Material::stdUniVarInfos[SUV_NUM] =
 {
-	{ "skinningRotations", GL_FLOAT_MAT3},
-	{ "skinningTranslations", GL_FLOAT_VEC3 },
-	{ "modelMat", GL_FLOAT_MAT4 },
-	{ "viewMat", GL_FLOAT_MAT4 },
-	{ "projectionMat", GL_FLOAT_MAT4 },
-	{ "modelViewMat", GL_FLOAT_MAT4 },
-	{ "ViewProjectionMat", GL_FLOAT_MAT4 },
-	{ "normalMat", GL_FLOAT_MAT3 },
-	{ "modelViewProjectionMat", GL_FLOAT_MAT4 },
-	{ "msNormalFai", GL_SAMPLER_2D },
-	{ "msDiffuseFai", GL_SAMPLER_2D },
-	{ "msSpecularFai", GL_SAMPLER_2D },
-	{ "msDepthFai", GL_SAMPLER_2D },
-	{ "isFai", GL_SAMPLER_2D },
-	{ "ppsFai", GL_SAMPLER_2D },
-	{ "rendererSize", GL_FLOAT_VEC2 },
-	{ "sceneAmbientColor", GL_FLOAT_VEC3 }
+	{"skinningRotations", GL_FLOAT_MAT3},
+	{"skinningTranslations", GL_FLOAT_VEC3},
+	{"modelMat", GL_FLOAT_MAT4},
+	{"viewMat", GL_FLOAT_MAT4},
+	{"projectionMat", GL_FLOAT_MAT4},
+	{"modelViewMat", GL_FLOAT_MAT4},
+	{"ViewProjectionMat", GL_FLOAT_MAT4},
+	{"normalMat", GL_FLOAT_MAT3},
+	{"modelViewProjectionMat", GL_FLOAT_MAT4},
+	{"msNormalFai", GL_SAMPLER_2D},
+	{"msDiffuseFai", GL_SAMPLER_2D},
+	{"msSpecularFai", GL_SAMPLER_2D},
+	{"msDepthFai", GL_SAMPLER_2D},
+	{"isFai", GL_SAMPLER_2D},
+	{"ppsPrePassFai", GL_SAMPLER_2D},
+	{"ppsPostPassFai", GL_SAMPLER_2D},
+	{"rendererSize", GL_FLOAT_VEC2},
+	{"sceneAmbientColor", GL_FLOAT_VEC3}
 };
 
 
@@ -58,7 +59,7 @@ struct BlendParam
 	const char* str;
 };
 
-static BlendParam blendingParams [] =
+static BlendParam blendingParams[] =
 {
 	{GL_ZERO, "GL_ZERO"},
 	{GL_ONE, "GL_ONE"},

+ 4 - 3
src/Resources/Material.h

@@ -48,9 +48,9 @@ class Material: public Resource
 		 * Standard uniform variables
 		 *
 		 * After changing the enum update also:
-		 * - some statics in Material.cpp
+		 * - Some statics in Material.cpp
 		 * - Renderer::setupMaterial
-		 * - the generic material shader (optional)
+		 * - The generic material shader (maybe)
 		 */
 		enum StdUniVars
 		{
@@ -71,7 +71,8 @@ class Material: public Resource
 			SUV_MS_SPECULAR_FAI,
 			SUV_MS_DEPTH_FAI,
 			SUV_IS_FAI,
-			SUV_PPS_FAI,
+			SUV_PPS_PRE_PASS_FAI,
+			SUV_PPS_POST_PASS_FAI,
 			// Other
 			SUV_RENDERER_SIZE,
 			SUV_SCENE_AMBIENT_COLOR,