Răsfoiți Sursa

Working on the new renderer

Panagiotis Christopoulos Charitos 15 ani în urmă
părinte
comite
fbb251554c

+ 4 - 4
src/Renderer/PpsSsao.cpp

@@ -125,18 +125,18 @@ void init()
 	// init shaders
 	ssaoSProg.customLoad( "shaders/PpsSsao.glsl" );
 
-	// load noise map and disable temporaly the texture compression and enable mipmaping
+	// load noise map and disable temporaly the texture compression and enable mipmapping
 	bool texCompr = R::textureCompression;
-	bool mipmaping = R::mipmaping;
+	bool mipmaping = R::mipmapping;
 	R::textureCompression = false;
-	R::mipmaping = true;
+	R::mipmapping = true;
 	noiseMap = Rsrc::textures.load( "gfx/noise3.tga" );
 	noiseMap->texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
 	noiseMap->texParameter( GL_TEXTURE_WRAP_T, GL_REPEAT );
 	//noise_map->texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
 	//noise_map->texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
 	R::textureCompression = texCompr;
-	R::mipmaping = mipmaping;
+	R::mipmapping = mipmaping;
 
 	// blur FBO
 	initBlurFbos();

+ 11 - 3
src/Renderer/Renderer.cpp

@@ -38,7 +38,7 @@ float quadVertCoords [][2] = { {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0} };
 string std_shader_preproc_defines;
 
 // texture
-bool mipmaping = true;
+bool mipmapping = true;
 int maxAnisotropy = 8;
 int maxTextureUnits = -1;
 bool textureCompression = false;
@@ -168,8 +168,14 @@ void init()
 	// execute this after the cvars are set and before the other inits (be cause these inits contain shader loads)
 	buildStdShaderPreProcStr();
 
-	// init deferred stages
-	// WARNING: the order of the inits is crucial!!!!!
+	//
+	// init deferred stages. WARNING: the order of the inits is crucial!!!!!
+	//
+
+	// disable mipmapping
+	bool mipmapping_ = mipmapping;
+	mipmapping = false;
+
 	R::Ms::init();
 	R::Is::init();
 	R::Bs::init();
@@ -177,6 +183,8 @@ void init()
 	R::Bs::init2();
 	R::Dbg::init();
 
+	mipmapping = mipmapping_;
+
 	// misc
 	shdr_final = Rsrc::shaders.load( "shaders/final.glsl" );
 

+ 1 - 1
src/Renderer/Renderer.h

@@ -29,7 +29,7 @@ extern int  maxColorAtachments; ///< Max color attachments a FBO can accept
 // texture stuff
 extern bool textureCompression; ///< Used in Texture::load to enable texture compression. Decreases video memory usage
 extern int  maxTextureUnits; ///< Used in Texture::bind so we wont bind in a nonexistent texture unit. Readonly
-extern bool mipmaping; ///< Used in Texture::load. Enables mipmaping increases video memory usage
+extern bool mipmapping; ///< Used in Texture::load. Enables mipmapping increases video memory usage
 extern int  maxAnisotropy; ///< Max texture anisotropy. Used in Texture::load
 
 // misc

+ 222 - 60
src/Renderer2/Renderer.hpp

@@ -7,6 +7,7 @@
 class Camera;
 class PointLight;
 class SpotLight;
+class Texture;
 
 
 /**
@@ -27,6 +28,226 @@ class SpotLight;
  */
 class Renderer
 {
+	//===================================================================================================================================
+	// Rendering Stages                                                                                                                 =
+	//===================================================================================================================================
+	public:
+
+		/**
+		 * Rendering stage base class
+		 */
+		class RenderingStage
+		{
+			protected:
+				Renderer& r;
+			public:
+				RenderingStage( Renderer& r_ ): r(r_) {}
+		};
+
+
+		/**
+		 * Material stage
+		 */
+		class Ms: public RenderingStage
+		{
+			private:
+				Fbo fbo;
+
+				void init();
+				void run();
+
+			public:
+				Texture normalFai;
+				Texture diffuseFai;
+				Texture specularFai;
+				Texture depthFai;
+
+				Ms( Renderer& r_ ): RenderingStage(r_) {}
+		}; // end Ms
+
+
+		/**
+		 * Illumination stage
+		 */
+		class Is: public RenderingStage
+		{
+			public:
+				/**
+				 * Shadowmapping sub-stage
+				 */
+				class Sm: public RenderingStage
+				{
+					private:
+						Fbo fbo; ///< Illumination stage shadowmapping FBO
+						Texture shadowMap;
+
+						void init();
+						void run( const Camera& cam );
+
+					public:
+						bool pcfEnabled;
+						bool bilinearEnabled;
+						int  mapRez;
+
+						Sm( Renderer& r_ ): RenderingStage(r_) {}
+				};
+
+			private:
+				Fbo fbo;
+				uint stencilRb; ///< Illumination stage stencil buffer
+				ShaderProg apSProg; ///< Illumination stage ambient pass shader program
+				ShaderProg plSProg; ///< Illumination stage point light shader program
+				ShaderProg slSProg; ///< Illumination stage spot light w/o shadow shader program
+				ShaderProg slSSProg; ///< Illumination stage spot light w/ shadow shader program
+				Vec3 viewVectors[4];
+				Vec2 planes;
+				static float sMOUvSCoords []; ///< Illumination stage stencil masking optimizations UV sphere vertex coords
+				static uint  sMOUvSVboId; ///< Illumination stage stencil masking optimizations UV sphere VBO id
+
+				static void initSMOUvS(); ///< Init the illumination stage stencil masking optimizations uv sphere (eg create the @ref sMOUvSVboId VBO)
+				void renderSMOUvS( const PointLight& light ); ///< Render the illumination stage stencil masking optimizations uv sphere
+				void calcViewVector(); ///< Calc the view vector that we will use inside the shader to calculate the frag pos in view space
+				void calcPlanes(); ///< Calc the planes that we will use inside the shader to calculate the frag pos in view space
+				void setStencilMask( const PointLight& light );
+				void setStencilMask( const SpotLight& light );
+				void ambientPass( const Vec3& color );
+				void pointLightPass( const PointLight& light );
+				void spotLightPass( const SpotLight& light );
+				void initFbo();
+				void init();
+				void run();
+
+			public:
+				Texture fai;
+				Sm sm;
+
+				Is( Renderer& r_ ): RenderingStage(r_), Sm(r) {}
+		}; // end Is
+
+
+		/**
+		 * Post-processing stage
+		 */
+		class Pps: public RenderingStage
+		{
+			public:
+				/**
+				 * High dynamic range lighting
+				 */
+				class Hdr: public RenderingStage
+				{
+					private:
+						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
+						float renderingQuality;
+						uint w, h;
+						ShaderProg pass0SProg, pass1SProg, pass2SProg;
+
+						void initFbos( Fbo& fbo, Texture& fai, int internalFormat );
+						void init();
+						void run();
+
+					public:
+						Texture pass0Fai; ///< Vertical blur pass
+						Texture pass1Fai; ///< @ref pass0Fai with the horizontal blur
+						Texture fai; ///< The final FAI
+						bool enabled;
+
+						Hdr( Renderer& r_ ): RenderingStage(r_) {}
+				}; // end Hdr
+
+				/**
+				 * Screen space ambient occlusion
+				 */
+				class Ssao: public RenderingStage
+				{
+					private:
+						Fbo pass0Fbo, pass1Fbo, pass2Fbo;
+						uint w, h;
+						uint bw, bh;
+						ShaderProg ssaoSProg, blurSProg, blurSProg2;
+						Texture* noiseMap;
+
+						void initBlurFbos();
+						void init();
+						void run();
+
+					public:
+						bool enabled;
+						float renderingQuality;
+						float bluringQuality;
+						Texture pass0Fai, pass1Fai, fai;
+
+						Ssao( Renderer& r_ ): RenderingStage(r_) {}
+				}; // end Ssao
+
+				/**
+				 * Light scattering
+				 */
+				class Lscatt: public RenderingStage
+				{
+					private:
+						Fbo fbo;
+						ShaderProg sProg;
+						int msDepthFaiUniLoc;
+						int isFaiUniLoc;
+
+						void init();
+						void run();
+
+					public:
+						float renderingQuality;
+						bool enabled;
+						Texture fai;
+
+						Lscatt( Renderer& r_ ): RenderingStage(r_) {}
+				}; // end Lscatt
+
+			private:
+				Fbo fbo;
+				ShaderProg sProg;
+				struct
+				{
+					int isFai;
+					int ppsSsaoFai;
+					int msNormalFai;
+					int hdrFai;
+					int lscattFai;
+				} uniLocs;
+
+				void init();
+				void run();
+
+			public:
+				Texture fai;
+
+				Hdr hdr;
+				Ssao ssao;
+				Lscatt lscatt;
+
+				Pps( Renderer& r_ ): RenderingStage(r_), hdr(r), ssao(r), lscatt(r) {}
+		}; // end Pps
+
+
+		/**
+		 * Blending stage
+		 */
+		class Bs: public RenderingStage
+		{
+			private:
+			public:
+				Bs( Renderer& r_ ): RenderingStage(r_) {}
+		}; // end Bs
+
+
+		// define the stages
+		Ms  ms;
+		Is  is;
+		Pps pps;
+		Bs  bs;
+
+	//===================================================================================================================================
+	//                                                                                                                                  =
+	//===================================================================================================================================
 	public:
 		// quality
 		uint  width; ///< width of the rendering. Dont confuse with the window width
@@ -36,7 +257,7 @@ class Renderer
 		// texture stuff
 		bool textureCompression; ///< Used in Texture::load to enable texture compression. Decreases video memory usage
 		int  maxTextureUnits; ///< Used in Texture::bind so we wont bind in a nonexistent texture unit. Readonly
-		bool mipmaping; ///< Used in Texture::load. Enables mipmaping increases video memory usage
+		bool mipmaping; ///< Used in Texture::load. Enables mipmapping increases video memory usage
 		int  maxAnisotropy; ///< Max texture anisotropy. Used in Texture::load
 		// other
 		int   maxColorAtachments; ///< Max color attachments a FBO can accept
@@ -49,65 +270,6 @@ class Renderer
 		Mat4 modelViewProjectionMat; ///< This changes just like @ref modelViewMat
 		Mat3 normalMat; ///< The rotation part of modelViewMat
 
-	//===================================================================================================================================
-	// Material Stage                                                                                                                   =
-	//===================================================================================================================================
-	private:
-		Fbo msFbo;
-
-		void initMs();
-		void runMs();
-
-	public:
-		Texture normalMsFai;
-		Texture diffuseMsFai;
-		Texture specularMsFai;
-		Texture depthMsFai;
-
-	//===================================================================================================================================
-	// Illumination Stage                                                                                                               =
-	//===================================================================================================================================
-	private:
-		Fbo isFbo;
-		uint stencilRb; ///< Illumination stage stencil buffer
-		ShaderProg apIsSProg; ///< Illumination stage ambient pass shader program
-		ShaderProg plIsSProg; ///< Illumination stage point light shader program
-		ShaderProg slIsSProg; ///< Illumination stage spot light w/o shadow shader program
-		ShaderProg slSIsSProg; ///< Illumination stage spot light w/ shadow shader program
-		Vec3 viewVectors[4];
-		Vec2 planes;
-		static float sMOUvSCoords []; ///< Illumination stage stencil masking optimizations UV sphere vertex coords
-		static uint  sMOUvSVboId; ///< Illumination stage stencil masking optimizations UV sphere VBO id
-
-		static void initSMOUvS(); ///< Init the illumination stage stencil masking optimizations uv sphere (eg create the @ref sMOUvSVboId VBO)
-		void renderSMOUvS( const PointLight& light ); ///< Render the illumination stage stencil masking optimizations uv sphere
-		void calcViewVector(); ///< Calc the view vector that we will use inside the shader to calculate the frag pos in view space
-		void calcPlanes(); ///< Calc the planes that we will use inside the shader to calculate the frag pos in view space
-		void setStencilMask( const PointLight& light );
-		void setStencilMask( const SpotLight& light );
-		void ambientPass( const Vec3& color );
-		void pointLightPass( const PointLight& light );
-		void spotLightPass( const SpotLight& light );
-		void initIsFbo();
-		void initIs();
-		void runIs();
-
-	public:
-		Texture isFai;
-
-	//===================================================================================================================================
-	// Illumination Stage Shadowmapping                                                                                                 =
-	//===================================================================================================================================
-	private:
-		Fbo smFbo; ///< Illumination stage shadowmapping FBO
-		Texture shadowMap;
-
-		void initSm();
-
-	public:
-		bool smPcfEnabled;
-		bool smBilinearEnabled;
-		int  smResolution;
 };
 
 #endif

+ 9 - 6
src/Resources/Texture.cpp

@@ -318,14 +318,14 @@ bool Texture::load( const char* filename )
 	// bind the texture
 	glGenTextures( 1, &glId );
 	bind(0);
-	if( R::mipmaping )  glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+	if( R::mipmapping ) glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
 	else                glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
 
 	glTexParameteri( type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
 	glTexParameterf( type, GL_TEXTURE_MAX_ANISOTROPY_EXT, R::maxAnisotropy );
 
-	// leave to GL_REPEAT. There is not real performace impact
+	// leave to GL_REPEAT. There is not real performance impact
 	glTexParameteri( type, GL_TEXTURE_WRAP_S, GL_REPEAT );
 	glTexParameteri( type, GL_TEXTURE_WRAP_T, GL_REPEAT );
 
@@ -339,7 +339,7 @@ bool Texture::load( const char* filename )
 		int_format = (img.bpp==32) ? GL_RGBA : GL_RGB;
 
 	glTexImage2D( type, 0, int_format, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.data );
-	if( R::mipmaping ) glGenerateMipmap(type);
+	if( R::mipmapping ) glGenerateMipmap(type);
 
 	img.unload();
 	return true;
@@ -358,15 +358,18 @@ bool Texture::createEmpty2D( float width_, float height_, int internal_format, i
 	// GL stuff
 	glGenTextures( 1, &glId );
 	bind();
-	texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-	texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+
+	if( R::mipmapping ) glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+	else                glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+
+	texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 	texParameter( GL_TEXTURE_WRAP_S, GL_CLAMP );
 	texParameter( GL_TEXTURE_WRAP_T, GL_CLAMP );
 
 	// allocate to vram
 	glTexImage2D( type, 0, internal_format, width_, height_, 0, format_, type_, NULL );
 
-	if( R::mipmaping ) glGenerateMipmap(type);
+	if( R::mipmapping ) glGenerateMipmap(type);
 
 	GLenum errid = glGetError();
 	if( errid != GL_NO_ERROR )