Просмотр исходного кода

Breaking the renderer stages into non-nested classes. This will make the Renderer class more clear and will ease the boost::python interfaces

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

Разница между файлами не показана из-за своего большого размера
+ 515 - 296
build/debug/Makefile


+ 10 - 6
shaders/GaussianBlurGeneric.glsl

@@ -1,6 +1,7 @@
 /**
  * @file
- * Generic shader program for Gausian blur
+ * Generic shader program for Gausian blur inspired by Daniel Rákos' article
+ * (http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/)
  * Switches: VPASS or HPASS, COL_RGBA or COL_RGB or COL_R
  */
 
@@ -9,11 +10,13 @@
 #pragma anki attribute position 0
 attribute vec2 position;
 
+
 void main()
 {
 	gl_Position = vec4(position * 2.0 - 1.0, 0.0, 1.0);
 }
 
+
 #pragma anki fragShaderBegins
 
 
@@ -30,7 +33,7 @@ void main()
 
 
 uniform sampler2D img; ///< Input FAI
-uniform vec2 imgSize = vec2(200.0, 200.0);
+uniform vec2 imgSize = vec2(0.0, 0.0);
 uniform float blurringDist = 1.0;
 
 varying vec2 texCoords;
@@ -48,7 +51,7 @@ varying vec2 texCoords;
 #endif
 
 /*
- * Determin tex fetch
+ * Determine tex fetch
  */
 #if defined(COL_RGBA)
 	#define TEX_FETCH rgba
@@ -59,11 +62,12 @@ varying vec2 texCoords;
 #endif
 
 
+const float _offset_[3] = float[](0.0, 1.3846153846, 3.2307692308);
+const float _weight_[3] = float[](0.2255859375, 0.314208984375, 0.06982421875);
+
+
 void main()
 {
-	const float _offset_[3] = float[](0.0, 1.3846153846, 3.2307692308);
-	const float _weight_[3] = float[](0.2255859375, 0.314208984375, 0.06982421875);
-
 	COL_TYPE _col_ = texture2D(img, gl_FragCoord.xy / imgSize).TEX_FETCH * _weight_[0];
 
 	for(int i=1; i<3; i++)

+ 8 - 8
src/Physics/DebugDrawer.h

@@ -35,13 +35,13 @@ class DebugDrawer: public btIDebugDraw
 
 inline void DebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
 {
-	Renderer::Dbg::drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
+	Dbg::drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
 }
 
 
 inline void DebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
 {
-	Renderer::Dbg::drawSphere(radius, Transform(toAnki(transform)), Vec4(toAnki(color), 1.0));
+	Dbg::drawSphere(radius, Transform(toAnki(transform)), Vec4(toAnki(color), 1.0));
 }
 
 
@@ -54,9 +54,9 @@ inline void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, con
 	trf(0, 3) = (max.getX() + min.getX()) / 2.0;
 	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
 	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
-	Renderer::Dbg::setModelMat(trf);
-	Renderer::Dbg::setColor(Vec4(toAnki(color), 1.0));
-	Renderer::Dbg::drawCube(1.0);
+	Dbg::setModelMat(trf);
+	Dbg::setColor(Vec4(toAnki(color), 1.0));
+	Dbg::drawCube(1.0);
 }
 
 
@@ -71,9 +71,9 @@ inline void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, con
 	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
 	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
 	trf = Mat4::combineTransformations(Mat4(toAnki(trans)), trf);
-	Renderer::Dbg::setModelMat(trf);
-	Renderer::Dbg::setColor(Vec4(toAnki(color), 1.0));
-	Renderer::Dbg::drawCube(1.0);
+	Dbg::setModelMat(trf);
+	Dbg::setColor(Vec4(toAnki(color), 1.0));
+	Dbg::drawCube(1.0);
 }
 
 

+ 9 - 8
src/Renderer/Bs.cpp

@@ -1,3 +1,4 @@
+#include "Bs.h"
 #include "Renderer.h"
 #include "App.h"
 #include "Scene.h"
@@ -7,7 +8,7 @@
 //======================================================================================================================
 // createFbo                                                                                                           =
 //======================================================================================================================
-void Renderer::Bs::createFbo()
+void Bs::createFbo()
 {
 	fbo.create();
 	fbo.bind();
@@ -27,7 +28,7 @@ void Renderer::Bs::createFbo()
 //======================================================================================================================
 // createRefractFbo                                                                                                    =
 //======================================================================================================================
-void Renderer::Bs::createRefractFbo()
+void Bs::createRefractFbo()
 {
 	refractFbo.create();
 	refractFbo.bind();
@@ -47,10 +48,10 @@ void Renderer::Bs::createRefractFbo()
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Bs::init()
+void Bs::init(const RendererInitializer& /*initializer*/)
 {
 	createFbo();
-	refractFai.createEmpty2D(r.width, r.height, GL_RGBA8, GL_RGBA, GL_FLOAT);
+	refractFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGBA8, GL_RGBA, GL_FLOAT);
 	createRefractFbo();
 
 	refractSProg.loadRsrc("shaders/BsRefract.glsl");
@@ -60,9 +61,9 @@ void Renderer::Bs::init()
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Bs::run()
+void Bs::run()
 {
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	glDepthMask(false);
 
@@ -90,7 +91,7 @@ void Renderer::Bs::run()
 			glStencilFunc(GL_ALWAYS, 0x1, 0x1);
 			glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
 
-			r.setupMaterial(*meshNode->mesh->material, *meshNode, *r.cam);
+			r.setupMaterial(*meshNode->mesh->material, *meshNode, r.getCamera());
 			glDisable(GL_BLEND); // a hack
 			meshNode->render();
 
@@ -122,7 +123,7 @@ void Renderer::Bs::run()
 		else
 		{
 			fbo.bind();
-			r.setupMaterial(*meshNode->mesh->material, *meshNode, *r.cam);
+			r.setupMaterial(*meshNode->mesh->material, *meshNode, r.getCamera());
 			meshNode->render();
 		}
 	}

+ 33 - 0
src/Renderer/Bs.h

@@ -0,0 +1,33 @@
+#ifndef BS_H
+#define BS_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "ShaderProg.h"
+#include "RsrcPtr.h"
+#include "Texture.h"
+
+
+/**
+ * Blending stage
+ */
+class Bs: public RenderingStage
+{
+	public:
+		Bs(Renderer& r_): RenderingStage(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+	private:
+		Fbo fbo;
+		Fbo refractFbo;
+		RsrcPtr<ShaderProg> refractSProg;
+		Texture refractFai;
+
+		void createFbo();
+		void createRefractFbo();
+};
+
+
+#endif

+ 21 - 22
src/Renderer/Dbg.cpp

@@ -1,30 +1,26 @@
-/**
- * @file
- *
- * Debugging stage
- */
-
+#include "Dbg.h"
 #include "Renderer.h"
 #include "App.h"
 #include "Scene.h"
 #include "SkelNode.h"
 #include "Camera.h"
 #include "LightProps.h"
+#include "RendererInitializer.h"
 
 
 //======================================================================================================================
 // Statics                                                                                                             =
 //======================================================================================================================
-RsrcPtr<ShaderProg> Renderer::Dbg::sProg;
-Mat4 Renderer::Dbg::viewProjectionMat;
-const ShaderProg::UniVar* Renderer::Dbg::colorUniVar;
-const ShaderProg::UniVar* Renderer::Dbg::modelViewProjectionMat;
+RsrcPtr<ShaderProg> Dbg::sProg;
+Mat4 Dbg::viewProjectionMat;
+const ShaderProg::UniVar* Dbg::colorUniVar;
+const ShaderProg::UniVar* Dbg::modelViewProjectionMat;
 
 
 //======================================================================================================================
 // Constructor                                                                                                         =
 //======================================================================================================================
-Renderer::Dbg::Dbg(Renderer& r_):
+Dbg::Dbg(Renderer& r_):
 	RenderingStage(r_),
 	showAxisEnabled(false),
 	showLightsEnabled(true),
@@ -37,7 +33,7 @@ Renderer::Dbg::Dbg(Renderer& r_):
 //======================================================================================================================
 // drawLine                                                                                                            =
 //======================================================================================================================
-void Renderer::Dbg::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
+void Dbg::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
 {
 	float posBuff [] = {from.x, from.y, from.z, to.x, to.y, to.z};
 
@@ -54,7 +50,7 @@ void Renderer::Dbg::drawLine(const Vec3& from, const Vec3& to, const Vec4& color
 //======================================================================================================================
 // renderGrid                                                                                                          =
 //======================================================================================================================
-void Renderer::Dbg::renderGrid()
+void Dbg::renderGrid()
 {
 	float col0[] = { 0.5, 0.5, 0.5 };
 	float col1[] = { 0.0, 0.0, 1.0 };
@@ -97,7 +93,7 @@ void Renderer::Dbg::renderGrid()
 //======================================================================================================================
 // drawSphere                                                                                                        =
 //======================================================================================================================
-void Renderer::Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity)
+void Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity)
 {
 	setColor(col);
 
@@ -173,7 +169,7 @@ void Renderer::Dbg::drawSphere(float radius, const Transform& trf, const Vec4& c
 //======================================================================================================================
 // renderCube                                                                                                          =
 //======================================================================================================================
-void Renderer::Dbg::drawCube(float size)
+void Dbg::drawCube(float size)
 {
 	Vec3 maxPos = Vec3(0.5 * size);
 	Vec3 minPos = Vec3(-0.5 * size);
@@ -201,8 +197,10 @@ void Renderer::Dbg::drawCube(float size)
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Dbg::init()
+void Dbg::init(const RendererInitializer& initializer)
 {
+	enabled = initializer.dbg.enabled;
+
 	// create FBO Captain Blood
 	fbo.create();
 	fbo.bind();
@@ -235,18 +233,19 @@ void Renderer::Dbg::init()
 //======================================================================================================================
 // runStage                                                                                                            =
 //======================================================================================================================
-void Renderer::Dbg::run()
+void Dbg::run()
 {
-	if(!enabled) return;
+	if(!enabled)
+		return;
 
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
 	fbo.bind();
 	sProg->bind();
 	viewProjectionMat = cam.getProjectionMatrix() * cam.getViewMatrix();
 
 	// OGL stuff
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 	glEnable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
 
@@ -285,7 +284,7 @@ void Renderer::Dbg::run()
 //======================================================================================================================
 // setColor                                                                                                            =
 //======================================================================================================================
-void Renderer::Dbg::setColor(const Vec4& color)
+void Dbg::setColor(const Vec4& color)
 {
 	colorUniVar->setVec4(&color);
 }
@@ -294,7 +293,7 @@ void Renderer::Dbg::setColor(const Vec4& color)
 //======================================================================================================================
 // setModelMat                                                                                                         =
 //======================================================================================================================
-void Renderer::Dbg::setModelMat(const Mat4& modelMat)
+void Dbg::setModelMat(const Mat4& modelMat)
 {
 	Mat4 pmv = viewProjectionMat * modelMat;
 	modelViewProjectionMat->setMat4(&pmv);

+ 52 - 0
src/Renderer/Dbg.h

@@ -0,0 +1,52 @@
+#ifndef DBG_H
+#define DBG_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "ShaderProg.h"
+#include "RsrcPtr.h"
+#include "Math.h"
+
+
+/**
+ * Debugging stage
+ */
+class Dbg: public RenderingStage
+{
+	public:
+		Dbg(Renderer& r_);
+		void renderGrid();
+		void init(const RendererInitializer& initializer);
+		void run();
+		static void drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity = 8);
+		static void drawCube(float size = 1.0);
+		static void setColor(const Vec4& color);
+		static void setModelMat(const Mat4& modelMat);
+		static void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
+
+		/**
+		 * @name Setters & getters
+		 */
+		/**@{*/
+		bool isEnabled() const {return enabled;}
+		void enable() {enabled = true;}
+		bool isShowSkeletonsEnabled() const {return showSkeletonsEnabled;}
+		/// @todo add others
+		/**@}*/
+
+	private:
+		bool enabled;
+		bool showAxisEnabled;
+		bool showLightsEnabled;
+		bool showSkeletonsEnabled;
+		bool showCamerasEnabled;
+		Fbo fbo;
+		static RsrcPtr<ShaderProg> sProg;
+		static const ShaderProg::UniVar* colorUniVar;
+		static const ShaderProg::UniVar* modelViewProjectionMat;
+		static Mat4 viewProjectionMat;
+};
+
+
+#endif

+ 10 - 11
src/Renderer/Ez.cpp

@@ -1,21 +1,20 @@
-/**
- * @file
- *
- * Material stage EarlyZ pass
- */
-
+#include "Ez.h"
 #include "Renderer.h"
 #include "App.h"
 #include "MeshNode.h"
 #include "Scene.h"
+#include "RendererInitializer.h"
 
 
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Ms::Ez::init()
+void Ez::init(const RendererInitializer& initializer)
 {
-	DEBUG_ERR(!enabled);
+	enabled = initializer.ms.ez.enabled;
+
+	if(!enabled)
+		return;
 
 	//
 	// init FBO
@@ -37,13 +36,13 @@ void Renderer::Ms::Ez::init()
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Ms::Ez::run()
+void Ez::run()
 {
 	DEBUG_ERR(!enabled);
 
 	fbo.bind();
 
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 	glEnable(GL_DEPTH_TEST);
@@ -57,7 +56,7 @@ void Renderer::Ms::Ez::run()
 
 		DEBUG_ERR(meshNode->mesh->material->dpMtl.get() == NULL);
 
-		r.setupMaterial(*meshNode->mesh->material->dpMtl, *meshNode, *r.cam);
+		r.setupMaterial(*meshNode->mesh->material->dpMtl, *meshNode, r.getCamera());
 		meshNode->renderDepth();
 	}
 

+ 26 - 0
src/Renderer/Ez.h

@@ -0,0 +1,26 @@
+#ifndef EZ_H
+#define EZ_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+
+
+/**
+ * Material stage EarlyZ pass
+ */
+class Ez: public RenderingStage
+{
+	public:
+		Ez(Renderer& r_): RenderingStage(r_) {}
+		bool isEnabled() const {return enabled;}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+	private:
+		Fbo fbo; ///< Writes to MS depth FAI
+		bool enabled;
+};
+
+
+#endif

+ 16 - 15
src/Renderer/Hdr.cpp

@@ -1,20 +1,16 @@
-/**
- * @file
- *
- * Post-processing stage high dynamic range lighting pass
- */
-
 #include <boost/lexical_cast.hpp>
+#include "Hdr.h"
 #include "Renderer.h"
+#include "RendererInitializer.h"
 
 
 //======================================================================================================================
 // initFbos                                                                                                            =
 //======================================================================================================================
-void Renderer::Pps::Hdr::initFbos(Fbo& fbo, Texture& fai, int internalFormat)
+void Hdr::initFbos(Fbo& fbo, Texture& fai, int internalFormat)
 {
-	int width = renderingQuality * r.width;
-	int height = renderingQuality * r.height;
+	int width = renderingQuality * r.getWidth();
+	int height = renderingQuality * r.getHeight();
 
 	// create FBO
 	fbo.create();
@@ -43,10 +39,15 @@ void Renderer::Pps::Hdr::initFbos(Fbo& fbo, Texture& fai, int internalFormat)
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Pps::Hdr::init()
+void Hdr::init(const RendererInitializer& initializer)
 {
-	//int width = renderingQuality * r.width;
-	//int height = renderingQuality * r.height;
+	enabled = initializer.pps.hdr.enabled;
+
+	if(!enabled)
+		return;
+
+	renderingQuality = initializer.pps.hdr.renderingQuality;
+	blurringDist = initializer.pps.hdr.blurringDist;
 
 	initFbos(toneFbo, pass0Fai, GL_RGB);
 	initFbos(pass1Fbo, pass1Fai, GL_RGB);
@@ -77,10 +78,10 @@ void Renderer::Pps::Hdr::init()
 //======================================================================================================================
 // runPass                                                                                                             =
 //======================================================================================================================
-void Renderer::Pps::Hdr::run()
+void Hdr::run()
 {
-	int w = renderingQuality * r.width;
-	int h = renderingQuality * r.height;
+	int w = renderingQuality * r.getWidth();
+	int h = renderingQuality * r.getHeight();
 	Renderer::setViewport(0, 0, w, h);
 
 	glDisable(GL_BLEND);

+ 54 - 0
src/Renderer/Hdr.h

@@ -0,0 +1,54 @@
+#ifndef HDR_H
+#define HDR_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Texture.h"
+#include "RsrcPtr.h"
+#include "ShaderProg.h"
+
+
+/**
+ * High dynamic range lighting pass
+ */
+class Hdr: private RenderingStage
+{
+	public:
+		Texture pass0Fai; ///< Vertical blur pass FAI
+		Texture pass1Fai; ///< pass0Fai with the horizontal blur FAI
+		Texture fai; ///< The final FAI
+
+		Hdr(Renderer& r_): RenderingStage(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+		/**
+		 * Setters & getters
+		 */
+		/**@{*/
+		float& getBlurringDist() {return blurringDist;}
+		void setBlurringDist(float f) {blurringDist = f;}
+		bool isEnabled() const {return enabled;}
+		float getRenderingQuality() const {return renderingQuality;}
+		/**@}*/
+
+	private:
+		Fbo toneFbo;
+		Fbo pass1Fbo;
+		Fbo pass2Fbo;
+		RsrcPtr<ShaderProg> toneSProg;
+		RsrcPtr<ShaderProg> pass1SProg;
+		RsrcPtr<ShaderProg> pass2SProg;
+		const ShaderProg::UniVar* toneProgFaiUniVar;
+		const ShaderProg::UniVar* pass1SProgFaiUniVar;
+		const ShaderProg::UniVar* pass2SProgFaiUniVar;
+		float blurringDist;
+		bool enabled;
+		float renderingQuality;
+
+		void initFbos(Fbo& fbo, Texture& fai, int internalFormat);
+};
+
+
+#endif

+ 27 - 35
src/Renderer/Is.cpp

@@ -1,10 +1,5 @@
-/**
- * @file
- *
- * Illumination stage
- */
-
 #include <boost/lexical_cast.hpp>
+#include "Is.h"
 #include "Renderer.h"
 #include "Camera.h"
 #include "Light.h"
@@ -17,12 +12,12 @@
 //======================================================================================================================
 // CalcViewVector                                                                                                      =
 //======================================================================================================================
-void Renderer::Is::calcViewVector()
+void Is::calcViewVector()
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
-	const uint& w = r.width;
-	const uint& h = r.height;
+	const uint& w = r.getWidth();
+	const uint& h = r.getHeight();
 
 	// From right up and CC wise to right down, Just like we render the quad
 	uint pixels[4][2]={{w,h}, {0,h}, {0, 0}, {w, 0}};
@@ -53,9 +48,9 @@ void Renderer::Is::calcViewVector()
 //======================================================================================================================
 // calcPlanes                                                                                                          =
 //======================================================================================================================
-void Renderer::Is::calcPlanes()
+void Is::calcPlanes()
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
 	planes.x = cam.getZFar() / (cam.getZNear() - cam.getZFar());
 	planes.y = (cam.getZFar() * cam.getZNear()) / (cam.getZNear() -cam.getZFar());
@@ -65,7 +60,7 @@ void Renderer::Is::calcPlanes()
 //======================================================================================================================
 // initFbo                                                                                                             =
 //======================================================================================================================
-void Renderer::Is::initFbo()
+void Is::initFbo()
 {
 	// create FBO
 	fbo.create();
@@ -74,14 +69,14 @@ void Renderer::Is::initFbo()
 	// init the stencil render buffer
 	glGenRenderbuffers(1, &stencilRb);
 	glBindRenderbuffer(GL_RENDERBUFFER, stencilRb);
-	glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.width, r.height);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.getWidth(), r.getHeight());
 	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRb);
 
 	// inform in what buffers we draw
 	fbo.setNumOfColorAttachements(1);
 
 	// create the txtrs
-	if(!fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT))
+	if(!fai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGB, GL_RGB, GL_FLOAT))
 		FATAL("Cannot create deferred shading illumination stage FAI");
 
 	// attach
@@ -100,7 +95,7 @@ void Renderer::Is::initFbo()
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Is::init()
+void Is::init(const RendererInitializer& initializer)
 {
 	// load the shaders
 	ambientPassSProg.loadRsrc("shaders/IsAp.glsl");
@@ -140,9 +135,9 @@ void Renderer::Is::init()
 
 	// spot light w/t shadow
 	string pps = string("\n#define SPOT_LIGHT_ENABLED\n#define SHADOW_ENABLED\n") +
-	                    "#define SHADOWMAP_SIZE " + lexical_cast<string>(sm.resolution) + "\n";
-	string prefix = "SpotShadowSms" + lexical_cast<string>(sm.resolution);
-	if(sm.pcfEnabled)
+	                    "#define SHADOWMAP_SIZE " + lexical_cast<string>(sm.getResolution()) + "\n";
+	string prefix = "SpotShadowSms" + lexical_cast<string>(sm.getResolution());
+	if(sm.isPcfEnabled())
 	{
 		pps += "#define PCF_ENABLED\n";
 		prefix += "Pcf";
@@ -165,17 +160,14 @@ void Renderer::Is::init()
 
 	// init the rest
 	initFbo();
-	smo.init();
-
-	if(sm.enabled)
-		sm.init();
+	smo.init(initializer);
 }
 
 
 //======================================================================================================================
 // ambientPass                                                                                                         =
 //======================================================================================================================
-void Renderer::Is::ambientPass(const Vec3& color)
+void Is::ambientPass(const Vec3& color)
 {
 	glDisable(GL_BLEND);
 
@@ -194,9 +186,9 @@ void Renderer::Is::ambientPass(const Vec3& color)
 //======================================================================================================================
 // pointLightPass                                                                                                      =
 //======================================================================================================================
-void Renderer::Is::pointLightPass(const PointLight& light)
+void Is::pointLightPass(const PointLight& light)
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
 	// frustum test
 	bsphere_t sphere(light.getWorldTransform().getOrigin(), light.getRadius());
@@ -239,15 +231,15 @@ void Renderer::Is::pointLightPass(const PointLight& light)
 //======================================================================================================================
 // spotLightPass                                                                                                       =
 //======================================================================================================================
-void Renderer::Is::spotLightPass(const SpotLight& light)
+void Is::spotLightPass(const SpotLight& light)
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
 	// frustum test
 	if(!cam.insideFrustum(light.camera)) return;
 
 	// shadow mapping
-	if(light.castsShadow && sm.enabled)
+	if(light.castsShadow && sm.isEnabled())
 	{
 		sm.run(light.camera);
 
@@ -258,7 +250,7 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 		glEnable(GL_BLEND);
 		glBlendFunc(GL_ONE, GL_ONE);
 		glDisable(GL_DEPTH_TEST);
-		Renderer::setViewport(0, 0, r.width, r.height);
+		Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 	}
 
 	// stencil optimization
@@ -277,7 +269,7 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 	const ShaderProg* shdr; // because of the huge name
 	const UniVars* uniVars;
 
-	if(light.castsShadow && sm.enabled)
+	if(light.castsShadow && sm.isEnabled())
 	{
 		shdr = spotLightShadowSProg.get();
 		uniVars = &spotLightShadowSProgUniVars;
@@ -316,7 +308,7 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 	uniVars->texProjectionMat->setMat4(&texProjectionMat);
 
 	// the shadowmap
-	if(light.castsShadow && sm.enabled)
+	if(light.castsShadow && sm.isEnabled())
 	{
 		uniVars->shadowMap->setTexture(sm.shadowMap, 5);
 	}
@@ -338,20 +330,20 @@ void Renderer::Is::spotLightPass(const SpotLight& light)
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Is::run()
+void Is::run()
 {
 	// FBO
 	fbo.bind();
 
 	// OGL stuff
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
 
 	glDisable(GL_DEPTH_TEST);
 
-	// ambient pass
+	// ambient passstatic float quadVertCoords [][2];
 	ambientPass(app->getScene().getAmbientCol());
 
 	// light passes

+ 86 - 0
src/Renderer/Is.h

@@ -0,0 +1,86 @@
+#ifndef IS_H
+#define IS_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Sm.h"
+#include "Smo.h"
+#include "Texture.h"
+
+
+class PointLight;
+class SpotLight;
+
+
+/**
+ * Illumination stage
+ */
+class Is: private RenderingStage
+{
+	private:
+		/// Illumination stage light pass uniform variables (opt)
+		struct UniVars
+		{
+			const ShaderProg::UniVar* msNormalFai;
+			const ShaderProg::UniVar* msDiffuseFai;
+			const ShaderProg::UniVar* msSpecularFai;
+			const ShaderProg::UniVar* msDepthFai;
+			const ShaderProg::UniVar* planes;
+			const ShaderProg::UniVar* lightPos;
+			const ShaderProg::UniVar* lightRadius;
+			const ShaderProg::UniVar* lightDiffuseCol;
+			const ShaderProg::UniVar* lightSpecularCol;
+			const ShaderProg::UniVar* lightTex;
+			const ShaderProg::UniVar* texProjectionMat;
+			const ShaderProg::UniVar* shadowMap;
+		};
+
+	public:
+		Sm sm;
+		Smo smo;
+		Texture fai;
+
+		Is(Renderer& r_): RenderingStage(r_), sm(r_), smo(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+	private:
+		Fbo fbo; ///< This FBO writes to the Is::fai
+		uint stencilRb; ///< Illumination stage stencil buffer
+		RsrcPtr<ShaderProg> ambientPassSProg; ///< Illumination stage ambient pass shader program
+		RsrcPtr<ShaderProg> pointLightSProg; ///< Illumination stage point light shader program
+		RsrcPtr<ShaderProg> spotLightNoShadowSProg; ///< Illumination stage spot light w/o shadow shader program
+		RsrcPtr<ShaderProg> spotLightShadowSProg; ///< Illumination stage spot light w/ shadow shader program
+
+		/**
+		 * @name Ptrs to uniform variables
+		 */
+		/**@{*/
+		const ShaderProg::UniVar* ambientColUniVar;
+		const ShaderProg::UniVar* sceneColMapUniVar;
+		UniVars pointLightSProgUniVars;
+		UniVars spotLightNoShadowSProgUniVars;
+		UniVars spotLightShadowSProgUniVars;
+		/**@}*/
+
+		Vec3 viewVectors[4];
+		Vec2 planes;
+
+		/**
+		 * Calc the view vector that we will use inside the shader to calculate the frag pos in view space
+		 */
+		void calcViewVector();
+
+		/**
+		 * Calc the planes that we will use inside the shader to calculate the frag pos in view space
+		 */
+		void calcPlanes();
+		void ambientPass(const Vec3& color);
+		void pointLightPass(const PointLight& light);
+		void spotLightPass(const SpotLight& light);
+		void initFbo();
+};
+
+
+#endif

+ 15 - 15
src/Renderer/Ms.cpp

@@ -1,3 +1,4 @@
+#include "Ms.h"
 #include "Renderer.h"
 #include "App.h"
 #include "Scene.h"
@@ -8,7 +9,7 @@
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Ms::init()
+void Ms::init(const RendererInitializer& initializer)
 {
 	// create FBO
 	fbo.create();
@@ -18,11 +19,11 @@ void Renderer::Ms::init()
 	fbo.setNumOfColorAttachements(3);
 
 	// create the FAIs
-	if(!normalFai.createEmpty2D(r.width, r.height, GL_RG16F, GL_RG, GL_FLOAT) ||
-	   !diffuseFai.createEmpty2D(r.width, r.height, GL_RGB16F, GL_RGB, GL_FLOAT) ||
-	   !specularFai.createEmpty2D(r.width, r.height, GL_RGBA16F, GL_RGBA, GL_FLOAT) ||
-	   !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, false))
+	if(!normalFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RG16F, GL_RG, GL_FLOAT) ||
+	   !diffuseFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGB16F, GL_RGB, GL_FLOAT) ||
+	   !specularFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGBA16F, GL_RGBA, GL_FLOAT) ||
+	   !depthFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8))
+	   //!depthFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false))
 	{
 		FATAL("Failed to create one MS FAI. See prev error");
 	}
@@ -49,39 +50,38 @@ void Renderer::Ms::init()
 	// unbind
 	fbo.unbind();
 
-	if(ez.enabled)
-		ez.init();
+	ez.init(initializer);
 }
 
 
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Ms::run()
+void Ms::run()
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
-	if(ez.enabled)
+	if(ez.isEnabled())
 	{
 		ez.run();
 	}
 
 	fbo.bind();
 
-	if(!ez.enabled)
+	if(!ez.isEnabled())
 	{
 		glClear(GL_DEPTH_BUFFER_BIT);
 	}
 
 	r.setProjectionViewMatrices(cam); ///< @todo remove this
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	//glEnable(GL_DEPTH_TEST);
 	app->getScene().skybox.Render(cam.getViewMatrix().getRotationPart());
 	//glDepthFunc(GL_LEQUAL);
 
 	// if ez then change the default depth test and disable depth writing
-	if(ez.enabled)
+	if(ez.isEnabled())
 	{
 		glDepthMask(false);
 		glDepthFunc(GL_EQUAL);
@@ -105,7 +105,7 @@ void Renderer::Ms::run()
 	glPolygonMode(GL_FRONT, GL_FILL); // the rendering above fucks the polygon mode
 
 	// restore depth
-	if(ez.enabled)
+	if(ez.isEnabled())
 	{
 		glDepthMask(true);
 		glDepthFunc(GL_LESS);

+ 33 - 0
src/Renderer/Ms.h

@@ -0,0 +1,33 @@
+#ifndef MS_H
+#define MS_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Ez.h"
+#include "Texture.h"
+
+
+class RendererInitializer;
+
+
+/**
+ * Material stage
+ */
+class Ms: public RenderingStage
+{
+	public:
+		Ez ez;
+		Texture normalFai;
+		Texture diffuseFai;
+		Texture specularFai;
+		Texture depthFai;
+
+		Ms(Renderer& r_): RenderingStage(r_), ez(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+	private:
+		Fbo fbo;
+};
+
+#endif

+ 20 - 28
src/Renderer/Pps.cpp

@@ -1,23 +1,18 @@
-/**
- * @file
- *
- * Post-processing stage
- */
-
+#include "Pps.h"
 #include "Renderer.h"
 
 
 //======================================================================================================================
 // initPassFbo                                                                                                         =
 //======================================================================================================================
-void Renderer::Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
+void Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
 {
 	fbo.create();
 	fbo.bind();
 
 	fbo.setNumOfColorAttachements(1);
 
-	fai.createEmpty2D(r.width, r.height, GL_RGB, GL_RGB, GL_FLOAT);
+	fai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGB, GL_RGB, GL_FLOAT);
 	fai.setRepeat(false);
 
 	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
@@ -32,12 +27,12 @@ void Renderer::Pps::initPassFbo(Fbo& fbo, Texture& fai, const char* msg)
 //======================================================================================================================
 // initPrePassSProg                                                                                                    =
 //======================================================================================================================
-void Renderer::Pps::initPrePassSProg()
+void Pps::initPrePassSProg()
 {
 	string pps = "";
 	string prefix = "";
 
-	if(ssao.enabled)
+	if(ssao.isEnabled())
 	{
 		pps += "#define SSAO_ENABLED\n";
 		prefix += "Ssao";
@@ -47,7 +42,7 @@ void Renderer::Pps::initPrePassSProg()
 	                                                       prefix.c_str()).c_str());
 	prePassSProg->bind();
 
-	if(ssao.enabled)
+	if(ssao.isEnabled())
 	{
 		prePassSProgUniVars.ppsSsaoFai = prePassSProg->findUniVar("ppsSsaoFai");
 	}
@@ -59,12 +54,12 @@ void Renderer::Pps::initPrePassSProg()
 //======================================================================================================================
 // initPostPassSProg                                                                                                   =
 //======================================================================================================================
-void Renderer::Pps::initPostPassSProg()
+void Pps::initPostPassSProg()
 {
 	string pps = "";
 	string prefix = "";
 
-	if(hdr.enabled)
+	if(hdr.isEnabled())
 	{
 		pps += "#define HDR_ENABLED\n";
 		prefix += "Hdr";
@@ -74,7 +69,7 @@ void Renderer::Pps::initPostPassSProg()
 	                                                        prefix.c_str()).c_str());
 	postPassSProg->bind();
 
-	if(hdr.enabled)
+	if(hdr.isEnabled())
 		postPassSProgUniVars.ppsHdrFai = postPassSProg->findUniVar("ppsHdrFai");
 
 	postPassSProgUniVars.ppsPrePassFai = postPassSProg->findUniVar("ppsPrePassFai");
@@ -84,13 +79,10 @@ void Renderer::Pps::initPostPassSProg()
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Pps::init()
+void Pps::init(const RendererInitializer& initializer)
 {
-	if(ssao.enabled)
-		ssao.init();
-
-	if(hdr.enabled)
-		hdr.init();
+	ssao.init(initializer);
+	hdr.init(initializer);
 
 	initPassFbo(prePassFbo, prePassFai, "Cannot create pre-pass post-processing stage FBO");
 	initPassFbo(postPassFbo, postPassFai, "Cannot create post-pass post-processing stage FBO");
@@ -103,21 +95,21 @@ void Renderer::Pps::init()
 //======================================================================================================================
 // runPrePass                                                                                                          =
 //======================================================================================================================
-void Renderer::Pps::runPrePass()
+void Pps::runPrePass()
 {
-	if(ssao.enabled)
+	if(ssao.isEnabled())
 		ssao.run();
 
 	prePassFbo.bind();
 
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	prePassSProg->bind();
 	prePassSProgUniVars.isFai->setTexture(r.is.fai, 0);
 
-	if(ssao.enabled)
+	if(ssao.isEnabled())
 	{
 		prePassSProgUniVars.ppsSsaoFai->setTexture(ssao.fai, 1);
 	}
@@ -133,21 +125,21 @@ void Renderer::Pps::runPrePass()
 //======================================================================================================================
 // runPostPass                                                                                                         =
 //======================================================================================================================
-void Renderer::Pps::runPostPass()
+void Pps::runPostPass()
 {
-	if(hdr.enabled)
+	if(hdr.isEnabled())
 		hdr.run();
 
 	postPassFbo.bind();
 
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
-	Renderer::setViewport(0, 0, r.width, r.height);
+	Renderer::setViewport(0, 0, r.getWidth(), r.getHeight());
 
 	postPassSProg->bind();
 	postPassSProgUniVars.ppsPrePassFai->setTexture(prePassFai, 0);
 
-	if(hdr.enabled)
+	if(hdr.isEnabled())
 	{
 		postPassSProgUniVars.ppsHdrFai->setTexture(hdr.fai, 1);
 	}

+ 52 - 0
src/Renderer/Pps.h

@@ -0,0 +1,52 @@
+#ifndef PPS_H
+#define PPS_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Hdr.h"
+#include "Ssao.h"
+
+
+/**
+ * Post-processing stage
+ *
+ * This stage is divided into 2 two parts. The first happens before blending stage and the second after.
+ */
+class Pps: private RenderingStage
+{
+	public:
+		struct UniVars
+		{
+			const ShaderProg::UniVar* isFai;
+			const ShaderProg::UniVar* ppsPrePassFai;
+			const ShaderProg::UniVar* ppsSsaoFai;
+			const ShaderProg::UniVar* ppsHdrFai;
+		};
+
+	public:
+		Hdr hdr;
+		Ssao ssao;
+		Texture prePassFai;
+		Texture postPassFai;
+
+		Pps(Renderer& r_): RenderingStage(r_), hdr(r_), ssao(r_) {}
+		void init(const RendererInitializer& initializer);
+		void runPrePass();
+		void runPostPass();
+
+	private:
+		Fbo prePassFbo;
+		Fbo postPassFbo;
+		RsrcPtr<ShaderProg> prePassSProg;
+		RsrcPtr<ShaderProg> postPassSProg;
+		UniVars prePassSProgUniVars;
+		UniVars postPassSProgUniVars;
+
+		void initPassFbo(Fbo& fbo, Texture& fai, const char* msg);
+		void initPrePassSProg();
+		void initPostPassSProg();
+};
+
+
+#endif

+ 5 - 17
src/Renderer/Renderer.cpp

@@ -34,18 +34,6 @@ Renderer::Renderer(Object* parent):
 void Renderer::init(const RendererInitializer& initializer)
 {
 	// set from the initializer
-	ms.ez.enabled = initializer.ms.ez.enabled;
-	is.sm.enabled = initializer.is.sm.enabled;
-	is.sm.pcfEnabled = initializer.is.sm.pcfEnabled;
-	is.sm.bilinearEnabled = initializer.is.sm.bilinearEnabled;
-	is.sm.resolution = initializer.is.sm.resolution;
-	pps.hdr.enabled = initializer.pps.hdr.enabled;
-	pps.hdr.renderingQuality = initializer.pps.hdr.renderingQuality;
-	pps.hdr.blurringDist = initializer.pps.hdr.blurringDist;
-	pps.ssao.enabled = initializer.pps.ssao.enabled;
-	pps.ssao.renderingQuality = initializer.pps.ssao.renderingQuality;
-	pps.ssao.bluringQuality = initializer.pps.ssao.bluringQuality;
-	dbg.enabled = initializer.dbg.enabled;
 	width = initializer.width;
 	height = initializer.height;
 
@@ -59,11 +47,11 @@ void Renderer::init(const RendererInitializer& initializer)
 	}
 
 	// init the stages. Careful with the order!!!!!!!!!!
-	ms.init();
-	is.init();
-	pps.init();
-	bs.init();
-	dbg.init();
+	ms.init(initializer);
+	is.init(initializer);
+	pps.init(initializer);
+	bs.init(initializer);
+	dbg.init(initializer);
 }
 
 

+ 34 - 377
src/Renderer/Renderer.h

@@ -9,16 +9,18 @@
 #include "Vbo.h"
 #include "RsrcPtr.h"
 #include "Object.h"
+#include "Ms.h"
+#include "Is.h"
+#include "Pps.h"
+#include "Bs.h"
+#include "Dbg.h"
 
 
 class Camera;
-class PointLight;
-class SpotLight;
 class RendererInitializer;
 class SceneNode;
 
 
-
 /**
  * Offscreen renderer
  *
@@ -26,375 +28,6 @@ class SceneNode;
  */
 class Renderer: public Object
 {
-	//====================================================================================================================
-	// nested                                                                                                            =
-	//====================================================================================================================
-	public:
-		/**
-		 * Rendering stage
-		 */
-		class RenderingStage
-		{
-			protected:
-				Renderer& r; ///< Just so that the stage can know the father class
-
-			public:
-				RenderingStage(Renderer& r_): r(r_) {}
-		};
-
-		/**
-		 * Material stage
-		 */
-		class Ms: private RenderingStage
-		{
-			friend class Renderer;
-
-			public:
-				/**
-				 * EarlyZ pass
-				 */
-				class Ez: public RenderingStage
-				{
-					friend class Renderer;
-					friend class Ms;
-
-					public:
-						Ez(Renderer& r_): RenderingStage(r_) {}
-						bool isEnabled() const {return enabled;}
-
-					private:
-						Fbo fbo;
-						bool enabled;
-
-						void init();
-						void run();
-				};
-
-			public:
-				Ez ez;
-
-				Ms(Renderer& r_): RenderingStage(r_), ez(r_) {}
-
-			private:
-				Texture normalFai;
-				Texture diffuseFai;
-				Texture specularFai;
-				Texture depthFai;
-				Fbo fbo;
-
-				void init();
-				void run();
-		}; // end Ms
-
-		/**
-		 * Illumination stage
-		 */
-		class Is: private RenderingStage
-		{
-			friend class Renderer;
-			friend class MainRenderer;
-
-			public:
-				/**
-				 * Shadowmapping pass
-				 */
-				class Sm: private RenderingStage
-				{
-					friend class Is;
-					friend class Renderer;
-
-					PROPERTY_R(bool, enabled, isEnabled) ///< If false then disable
-					PROPERTY_R(bool, pcfEnabled, isPcfEnabled) ///< Enable Percentage Closer Filtering
-					PROPERTY_R(bool, bilinearEnabled, isBilinearEnabled) ///< Shadowmap bilinear filtering. Better quality
-					PROPERTY_R(int, resolution, getResolution) ///< Shadowmap resolution. The higher the better but slower
-
-					public:
-						Sm(Renderer& r_): RenderingStage(r_) {}
-
-					private:
-						Fbo fbo; ///< Illumination stage shadowmapping FBO
-						Texture shadowMap;
-
-						void init();
-
-						/**
-						 * Render the scene only with depth and store the result in the shadowMap
-						 * @param cam The light camera
-						 */
-						void run(const Camera& cam);
-				}; // end Sm
-
-				/**
-				 * Stencil masking optimizations
-				 */
-				class Smo: public RenderingStage
-				{
-					friend class Is;
-					friend class Renderer;
-
-					public:
-						Smo(Renderer& r_): RenderingStage(r_) {}
-
-					private:
-						static float sMOUvSCoords[]; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
-						static Vbo sMOUvSVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
-						RsrcPtr<ShaderProg> sProg;
-						const ShaderProg::UniVar* modelViewProjectionMatUniVar; ///< Opt
-
-						void init();
-						void run(const PointLight& light);
-						void run(const SpotLight& light);
-				}; // end Smo
-
-			private:
-				/// Illumination stage light pass uniform variables (opt)
-				struct UniVars
-				{
-					const ShaderProg::UniVar* msNormalFai;
-					const ShaderProg::UniVar* msDiffuseFai;
-					const ShaderProg::UniVar* msSpecularFai;
-					const ShaderProg::UniVar* msDepthFai;
-					const ShaderProg::UniVar* planes;
-					const ShaderProg::UniVar* lightPos;
-					const ShaderProg::UniVar* lightRadius;
-					const ShaderProg::UniVar* lightDiffuseCol;
-					const ShaderProg::UniVar* lightSpecularCol;
-					const ShaderProg::UniVar* lightTex;
-					const ShaderProg::UniVar* texProjectionMat;
-					const ShaderProg::UniVar* shadowMap;
-				};
-
-			public:
-				Sm sm;
-				Smo smo;
-
-				Is(Renderer& r_): RenderingStage(r_), sm(r_), smo(r_) {}
-
-			private:
-				Texture fai;
-				Fbo fbo; ///< This FBO writes to the Is::fai
-				uint stencilRb; ///< Illumination stage stencil buffer
-				RsrcPtr<ShaderProg> ambientPassSProg; ///< Illumination stage ambient pass shader program
-				RsrcPtr<ShaderProg> pointLightSProg; ///< Illumination stage point light shader program
-				RsrcPtr<ShaderProg> spotLightNoShadowSProg; ///< Illumination stage spot light w/o shadow shader program
-				RsrcPtr<ShaderProg> spotLightShadowSProg; ///< Illumination stage spot light w/ shadow shader program
-
-				/**
-				 * @name Ptrs to uniform variables
-				 */
-				//*@{*/
-				const ShaderProg::UniVar* ambientColUniVar;
-				const ShaderProg::UniVar* sceneColMapUniVar;
-				UniVars pointLightSProgUniVars;
-				UniVars spotLightNoShadowSProgUniVars;
-				UniVars spotLightShadowSProgUniVars;
-				//*@}*/
-
-				Vec3 viewVectors[4];
-				Vec2 planes;
-
-				/**
-				 * Calc the view vector that we will use inside the shader to calculate the frag pos in view space
-				 */
-				void calcViewVector();
-
-				/**
-				 * Calc the planes that we will use inside the shader to calculate the frag pos in view space
-				 */
-				void calcPlanes();
-				void ambientPass(const Vec3& color);
-				void pointLightPass(const PointLight& light);
-				void spotLightPass(const SpotLight& light);
-				void initFbo();
-				void init();
-				void run();
-		}; // end Is
-
-		/**
-		 * Post-processing stage
-		 *
-		 * This stage is divided into 2 two parts. The first happens before blending stage and the second after.
-		 */
-		class Pps: private RenderingStage
-		{
-			friend class Renderer;
-			friend class MainRenderer;
-
-			public:
-				/**
-				 * High dynamic range lighting pass
-				 */
-				class Hdr: private RenderingStage
-				{
-					friend class Pps;
-					friend class Renderer;
-
-					PROPERTY_R(bool, enabled, isEnabled)
-					PROPERTY_R(float, renderingQuality, getRenderingQuality)
-
-					public:
-						Texture pass0Fai; ///< Vertical blur pass FAI
-						Texture pass1Fai; ///< pass0Fai with the horizontal blur FAI
-						Texture fai; ///< The final FAI
-						float getBlurringDist() const {return blurringDist;}
-						void setBlurringDist(float f) {blurringDist = f;}
-
-						Hdr(Renderer& r_): RenderingStage(r_) {}
-
-					private:
-						Fbo toneFbo;
-						Fbo pass1Fbo;
-						Fbo pass2Fbo;
-						RsrcPtr<ShaderProg> toneSProg;
-						RsrcPtr<ShaderProg> pass1SProg;
-						RsrcPtr<ShaderProg> pass2SProg;
-						const ShaderProg::UniVar* toneProgFaiUniVar;
-						const ShaderProg::UniVar* pass1SProgFaiUniVar;
-						const ShaderProg::UniVar* pass2SProgFaiUniVar;
-						float blurringDist;
-
-						void initFbos(Fbo& fbo, Texture& fai, int internalFormat);
-						void init();
-						void run();
-				}; // end Hrd
-
-				/**
-				 * Screen space ambient occlusion pass
-				 *
-				 * Three passes:
-				 * - Calc ssao factor
-				 * - Blur vertically
-				 * - Blur horizontally
-				 */
-				class Ssao: private RenderingStage
-				{
-					friend class Pps;
-					friend class Renderer;
-
-					PROPERTY_R(bool, enabled, isEnabled)
-					PROPERTY_R(float, renderingQuality, getRenderingQuality)
-					PROPERTY_R(float, bluringQuality, getBluringQuality)
-
-					private:
-						Fbo pass0Fbo;
-						Fbo pass1Fbo;
-						Fbo pass2Fbo;
-						uint width, height, bwidth, bheight;
-						RsrcPtr<Texture> noiseMap;
-						RsrcPtr<ShaderProg> ssaoSProg;
-						RsrcPtr<ShaderProg> blurSProg;
-						RsrcPtr<ShaderProg> blurSProg2;
-						const ShaderProg::UniVar* camerarangeUniVar;
-						const ShaderProg::UniVar* msDepthFaiUniVar;
-						const ShaderProg::UniVar* noiseMapUniVar;
-						const ShaderProg::UniVar* msNormalFaiUniVar;
-						const ShaderProg::UniVar* blurSProgFaiUniVar;
-						const ShaderProg::UniVar* blurSProg2FaiUniVar;
-
-						void initBlurFbo(Fbo& fbo, Texture& fai);
-						void init();
-						void run();
-
-					public:
-						Texture pass0Fai;
-						Texture pass1Fai;
-						Texture fai;  //< The final FAI
-
-						Ssao(Renderer& r_): RenderingStage(r_) {}
-				}; // end Ssao
-
-				struct UniVars
-				{
-					const ShaderProg::UniVar* isFai;
-					const ShaderProg::UniVar* ppsPrePassFai;
-					const ShaderProg::UniVar* ppsSsaoFai;
-					const ShaderProg::UniVar* ppsHdrFai;
-				};
-
-			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;
-				RsrcPtr<ShaderProg> prePassSProg;
-				RsrcPtr<ShaderProg> postPassSProg;
-				UniVars prePassSProgUniVars;
-				UniVars postPassSProgUniVars;
-
-				void initPassFbo(Fbo& fbo, Texture& fai, const char* msg);
-				void initPrePassSProg();
-				void initPostPassSProg();
-				void init();
-				void runPrePass();
-				void runPostPass();
-		}; // end Pps
-
-		/**
-		 * Blending stage
-		 */
-		class Bs: public RenderingStage
-		{
-			friend class Renderer;
-			friend class MainRenderer;
-
-			public:
-				Bs(Renderer& r_): RenderingStage(r_) {}
-
-			private:
-				Fbo fbo;
-				Fbo refractFbo;
-				RsrcPtr<ShaderProg> refractSProg;
-				Texture refractFai;
-
-				void createFbo();
-				void createRefractFbo();
-				void init();
-				void run();
-		}; // end Bs
-
-		/**
-		 * Debugging stage
-		 */
-		class Dbg: public RenderingStage
-		{
-			friend class Renderer;
-
-			PROPERTY_R(bool, enabled, isEnabled)
-			PROPERTY_RW(bool, showAxisEnabled, setShowAxis, isShowAxisEnabled)
-			PROPERTY_RW(bool, showLightsEnabled, setShowLights, isShowLightsEnabled)
-			PROPERTY_RW(bool, showSkeletonsEnabled, setShowSkeletons, isShowSkeletonsEnabled)
-			PROPERTY_RW(bool, showCamerasEnabled, setShowCameras, isShowCamerasEnabled)
-
-			public:
-				Dbg(Renderer& r_);
-				void renderGrid();
-				static void drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity = 8);
-				static void drawCube(float size = 1.0);
-
-				static void setColor(const Vec4& color);
-				static void setModelMat(const Mat4& modelMat);
-				static void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
-
-			private:
-				Fbo fbo;
-				static RsrcPtr<ShaderProg> sProg;
-				static const ShaderProg::UniVar* colorUniVar;
-				static const ShaderProg::UniVar* modelViewProjectionMat;
-				static Mat4 viewProjectionMat;
-
-				void init();
-				void run();
-		}; // end Dbg
-
 	//====================================================================================================================
 	// Properties                                                                                                        =
 	//====================================================================================================================
@@ -417,8 +50,17 @@ class Renderer: public Object
 		Dbg dbg; ///< Debugging rendering stage
 		/**@}*/
 
+		static float quadVertCoords [][2];
+
 		Renderer(Object* parent);
 
+		/**
+		 * @name Setters & getters
+		 */
+		/**@{*/
+		const Camera& getCamera() const {return *cam;}
+		/**@}*/
+
 		/**
 		 * Init the renderer given an initialization class
 		 * @param initializer The initializer class
@@ -461,6 +103,26 @@ class Renderer: public Object
 		 */
 		static Mat4 ortho(float left, float right, float bottom, float top, float near, float far);
 
+		/**
+		 * OpenGL wrapper
+		 */
+		static void setViewport(uint x, uint y, uint w, uint h) {glViewport(x, y, w, h);}
+
+		/**
+		 * @todo write cmnts
+		 * @param mtl
+		 * @param sceneNode
+		 * @param cam
+		 */
+		void setupMaterial(const class Material& mtl, const SceneNode& sceneNode, const Camera& cam);
+
+
+		/**
+		 * @todo write cmnts
+		 * @param vertCoordsUniLoc
+		 */
+		static void drawQuad(int vertCoordsUniLoc);
+
 
 	//====================================================================================================================
 	// Protected                                                                                                         =
@@ -468,14 +130,9 @@ class Renderer: public Object
 	protected:
 		uint framesNum; ///< Frame number
 		const Camera* cam; ///< Current camera
-		static float quadVertCoords [][2];
 		static int maxColorAtachments; ///< Max color attachments a FBO can accept
 		Mat4 viewProjectionMat; ///< In case anyone needs it
 
-		static void drawQuad(int vertCoordsUniLoc);
-		void setupMaterial(const class Material& mtl, const SceneNode& sceneNode, const Camera& cam);
-		static void setViewport(uint x, uint y, uint w, uint h) { glViewport(x,y,w,h); }
-
 		// to be removed
 	public:
 		static void color3(const Vec3& v) { glColor3fv(&((Vec3&)v)[0]); } ///< OpenGL wrapper

+ 4 - 2
src/Renderer/RendererInitializer.h

@@ -1,8 +1,10 @@
-#ifndef _RENDERERINITIALIZER_H_
-#define _RENDERERINITIALIZER_H_
+#ifndef RENDERER_INITIALIZER_H
+#define RENDERER_INITIALIZER_H
 
+#include <cstring>
 #include "Common.h"
 
+
 /**
  * A struct to initialize the renderer. It contains a few extra params for the MainRenderer
  */

+ 25 - 0
src/Renderer/RenderingStage.h

@@ -0,0 +1,25 @@
+#ifndef RENDERING_STAGE_H
+#define RENDERING_STAGE_H
+
+#include "Common.h"
+
+
+class Renderer;
+class RendererInitializer;
+
+
+/**
+ * Rendering stage
+ */
+class RenderingStage
+{
+	public:
+		RenderingStage(Renderer& r_): r(r_) {}
+		virtual void init(const RendererInitializer& initializer) = 0;
+
+	protected:
+		Renderer& r; ///< Know your father
+};
+
+
+#endif

+ 18 - 9
src/Renderer/Sm.cpp

@@ -1,21 +1,27 @@
-/**
- * @file
- *
- * Illumination stage shadowmapping pass
- */
-
+#include "Sm.h"
 #include "Renderer.h"
 #include "App.h"
 #include "Scene.h"
 #include "MeshNode.h"
 #include "LightProps.h"
+#include "Camera.h"
+#include "RendererInitializer.h"
 
 
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Is::Sm::init()
+void Sm::init(const RendererInitializer& initializer)
 {
+	enabled = initializer.is.sm.enabled;
+
+	if(!enabled)
+		return;
+
+	pcfEnabled = initializer.is.sm.pcfEnabled;
+	bilinearEnabled = initializer.is.sm.bilinearEnabled;
+	resolution = initializer.is.sm.resolution;
+
 	// create FBO
 	fbo.create();
 	fbo.bind();
@@ -58,8 +64,10 @@ void Renderer::Is::Sm::init()
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Is::Sm::run(const Camera& cam)
+void Sm::run(const Camera& cam)
 {
+	DEBUG_ERR(!enabled);
+
 	// FBO
 	fbo.bind();
 
@@ -80,7 +88,8 @@ void Renderer::Is::Sm::run(const Camera& cam)
 	for(Vec<MeshNode*>::iterator it=app->getScene().meshNodes.begin(); it!=app->getScene().meshNodes.end(); it++)
 	{
 		MeshNode* meshNode = (*it);
-		if(meshNode->mesh->material->blends) continue;
+		if(meshNode->mesh->material->blends)
+			continue;
 
 		DEBUG_ERR(meshNode->mesh->material->dpMtl.get() == NULL);
 

+ 45 - 0
src/Renderer/Sm.h

@@ -0,0 +1,45 @@
+#ifndef SM_H
+#define SM_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Texture.h"
+
+
+class Camera;
+
+
+/**
+ * Shadowmapping pass
+ */
+class Sm: private RenderingStage
+{
+	public:
+		Texture shadowMap;
+
+		Sm(Renderer& r_): RenderingStage(r_) {}
+
+		void init(const RendererInitializer& initializer);
+
+		/**
+		 * Render the scene only with depth and store the result in the shadowMap
+		 * @param cam The light camera
+		 */
+		void run(const Camera& cam);
+
+		bool isEnabled() const {return enabled;}
+		bool isPcfEnabled() const {return pcfEnabled;}
+		bool isBilinearEnabled() const {return bilinearEnabled;}
+		int getResolution() const {return resolution;}
+
+	private:
+		Fbo fbo; ///< Illumination stage shadowmapping FBO
+		bool enabled; ///< If false then disable
+		bool pcfEnabled; ///< Enable Percentage Closer Filtering
+		bool bilinearEnabled; ///< Shadowmap bilinear filtering. Better quality
+		int resolution; ///< Shadowmap resolution. The higher the better but slower
+};
+
+
+#endif

Разница между файлами не показана из-за своего большого размера
+ 2 - 5
src/Renderer/Smo.cpp


+ 35 - 0
src/Renderer/Smo.h

@@ -0,0 +1,35 @@
+#ifndef SMO_H
+#define SMO_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Vbo.h"
+#include "ShaderProg.h"
+#include "RsrcPtr.h"
+
+
+class PointLight;
+class SpotLight;
+
+
+/**
+ * Stencil masking optimizations
+ */
+class Smo: public RenderingStage
+{
+	public:
+		Smo(Renderer& r_): RenderingStage(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run(const PointLight& light);
+		void run(const SpotLight& light);
+
+	private:
+		static float sMOUvSCoords[]; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
+		static Vbo sMOUvSVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
+		RsrcPtr<ShaderProg> sProg;
+		const ShaderProg::UniVar* modelViewProjectionMatUniVar; ///< Opt
+};
+
+
+#endif

+ 16 - 12
src/Renderer/Ssao.cpp

@@ -1,18 +1,14 @@
-/**
- * @file
- *
- * Post-processing stage screen space ambient occlusion pass
- */
-
 #include <boost/lexical_cast.hpp>
+#include "Ssao.h"
 #include "Renderer.h"
 #include "Camera.h"
+#include "RendererInitializer.h"
 
 
 //======================================================================================================================
 // initBlurFbos                                                                                                        =
 //======================================================================================================================
-void Renderer::Pps::Ssao::initBlurFbo(Fbo& fbo, Texture& fai)
+void Ssao::initBlurFbo(Fbo& fbo, Texture& fai)
 {
 	// create FBO
 	fbo.create();
@@ -41,10 +37,18 @@ void Renderer::Pps::Ssao::initBlurFbo(Fbo& fbo, Texture& fai)
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
-void Renderer::Pps::Ssao::init()
+void Ssao::init(const RendererInitializer& initializer)
 {
-	width = renderingQuality * r.width;
-	height = renderingQuality * r.height;
+	enabled = initializer.pps.ssao.enabled;
+
+	if(!enabled)
+		return;
+
+	renderingQuality = initializer.pps.ssao.renderingQuality;
+	bluringQuality = initializer.pps.ssao.bluringQuality;
+
+	width = renderingQuality * r.getWidth();
+	height = renderingQuality * r.getHeight();
 	bwidth = height * bluringQuality;
 	bheight = height * bluringQuality;
 
@@ -129,9 +133,9 @@ void Renderer::Pps::Ssao::init()
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Renderer::Pps::Ssao::run()
+void Ssao::run()
 {
-	const Camera& cam = *r.cam;
+	const Camera& cam = r.getCamera();
 
 	glDisable(GL_BLEND);
 	glDisable(GL_DEPTH_TEST);

+ 63 - 0
src/Renderer/Ssao.h

@@ -0,0 +1,63 @@
+#ifndef SSAO_H
+#define SSAO_H
+
+#include "Common.h"
+#include "RenderingStage.h"
+#include "Fbo.h"
+#include "Texture.h"
+#include "ShaderProg.h"
+#include "RsrcPtr.h"
+
+
+/**
+ * Screen space ambient occlusion pass
+ *
+ * Three passes:
+ * - Calc ssao factor
+ * - Blur vertically
+ * - Blur horizontally
+ */
+class Ssao: private RenderingStage
+{
+	public:
+		Texture pass0Fai;
+		Texture pass1Fai;
+		Texture fai;  ///< The final FAI
+
+		Ssao(Renderer& r_): RenderingStage(r_) {}
+		void init(const RendererInitializer& initializer);
+		void run();
+
+		/**
+		 * @name Setters & getters
+		 */
+		/**@{*/
+		bool isEnabled() const {return enabled;}
+		float getRenderingQuality() const {return renderingQuality;}
+		float getBluringQuality() const {return bluringQuality;}
+		/**@}*/
+
+	private:
+		bool enabled;
+		float renderingQuality;
+		float bluringQuality;
+		Fbo pass0Fbo;
+		Fbo pass1Fbo;
+		Fbo pass2Fbo;
+		uint width, height, bwidth, bheight;
+		RsrcPtr<Texture> noiseMap;
+		RsrcPtr<ShaderProg> ssaoSProg;
+		RsrcPtr<ShaderProg> blurSProg;
+		RsrcPtr<ShaderProg> blurSProg2;
+		const ShaderProg::UniVar* camerarangeUniVar;
+		const ShaderProg::UniVar* msDepthFaiUniVar;
+		const ShaderProg::UniVar* noiseMapUniVar;
+		const ShaderProg::UniVar* msNormalFaiUniVar;
+		const ShaderProg::UniVar* blurSProgFaiUniVar;
+		const ShaderProg::UniVar* blurSProg2FaiUniVar;
+
+		void initBlurFbo(Fbo& fbo, Texture& fai);
+};
+
+
+#endif

+ 4 - 0
src/Resources/Material.h

@@ -24,6 +24,10 @@
 class Material: public Resource
 {
 	friend class Renderer; ///< For the setupMaterial
+	friend class Ez;
+	friend class Sm;
+	friend class Ms;
+	friend class Bs;
 	friend class Mesh;
 	friend class MeshNode;
 

+ 1 - 0
src/Resources/Texture.h

@@ -17,6 +17,7 @@
 class Texture: public Resource
 {
 	friend class Renderer; /// @todo Remove this when remove the SSAO load noise map crap
+	friend class Ssao;
 	friend class MainRenderer;
 
 	public:

+ 2 - 2
src/Scene/Camera.cpp

@@ -22,8 +22,8 @@ void Camera::setAll(float fovx_, float fovy_, float znear_, float zfar_)
 //======================================================================================================================
 void Camera::render()
 {
-	Renderer::Dbg::setColor(Vec4(1.0, 0.0, 1.0, 1.0));
-	Renderer::Dbg::setModelMat(Mat4(getWorldTransform()));
+	Dbg::setColor(Vec4(1.0, 0.0, 1.0, 1.0));
+	Dbg::setModelMat(Mat4(getWorldTransform()));
 
 	const float camLen = 1.0;
 	float tmp0 = camLen / tan((M::PI - fovX)*0.5) + 0.001;

+ 2 - 2
src/Scene/Light.cpp

@@ -37,7 +37,7 @@ void SpotLight::init(const char* filename)
 //======================================================================================================================
 void Light::render()
 {
-	Renderer::Dbg::drawSphere(0.1, getWorldTransform(), Vec4(lightProps->getDiffuseColor(), 1.0));
-	//Renderer::Dbg::drawSphere(0.1, Transform::getIdentity(), Vec4(lightProps->getDiffuseColor(), 1.0));
+	Dbg::drawSphere(0.1, getWorldTransform(), Vec4(lightProps->getDiffuseColor(), 1.0));
+	//Dbg::drawSphere(0.1, Transform::getIdentity(), Vec4(lightProps->getDiffuseColor(), 1.0));
 }
 

+ 3 - 3
src/Scene/ParticleEmitter.cpp

@@ -212,8 +212,8 @@ void ParticleEmitter::update()
 void ParticleEmitter::render()
 {
 	glPolygonMode(GL_FRONT, GL_LINE);
-	Renderer::Dbg::setColor(Vec4(1.0));
-	Renderer::Dbg::setModelMat(Mat4(getWorldTransform()));
-	Renderer::Dbg::drawCube();
+	Dbg::setColor(Vec4(1.0));
+	Dbg::setModelMat(Mat4(getWorldTransform()));
+	Dbg::drawCube();
 	glPolygonMode(GL_FRONT, GL_FILL);
 }

+ 4 - 4
src/Scene/SkelNode.cpp

@@ -32,14 +32,14 @@ void SkelNode::init(const char* filename)
 //======================================================================================================================
 void SkelNode::render()
 {
-	Renderer::Dbg::setModelMat(Mat4(getWorldTransform()));
-	Renderer::Dbg::setColor(Vec4(1.0, 0.0, 0.0, 1.0));
-	Renderer::Dbg::setModelMat(Mat4(getWorldTransform()));
+	Dbg::setModelMat(Mat4(getWorldTransform()));
+	Dbg::setColor(Vec4(1.0, 0.0, 0.0, 1.0));
+	Dbg::setModelMat(Mat4(getWorldTransform()));
 
 	Vec<Vec3> positions;
 
 	for(uint i=0; i<skeleton->bones.size(); i++)
 	{
-		Renderer::Dbg::drawLine(heads[i], tails[i], Vec4(1.0));
+		Dbg::drawLine(heads[i], tails[i], Vec4(1.0));
 	}
 }

+ 7 - 0
src/Scripting/Renderer/Renderer.bpi.h

@@ -1,4 +1,11 @@
 
+/*class_<Renderer::Pps::Hdr, noncopyable>("Hdr", no_init)
+	.def("getBlurringDist", &Renderer::Pps::Hdr::getBlurringDist, return_value_policy<reference_existing_object>())
+;*/
+
+/*class_<Renderer::Pps, noncopyable>("Pps", no_init)
+;*/
+
 class_<Renderer, noncopyable>("Renderer", no_init)
 	.def("getFramesNum", &Renderer::getFramesNum)
 ;

Некоторые файлы не были показаны из-за большого количества измененных файлов