Browse Source

Nothing special

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
f5c0e88c5a

+ 2 - 2
shaders/PpsHdr.glsl

@@ -10,6 +10,7 @@
 #pragma anki fragShaderBegins
 
 uniform sampler2D fai; ///< Its the IS FAI
+uniform float exposure;
 
 varying vec2 vTexCoords;
 
@@ -18,9 +19,8 @@ void main()
 {
 	vec3 _color_ = texture2D(fai, vTexCoords).rgb;
 	float _luminance_ = dot(vec3(0.30, 0.59, 0.11), _color_); // AKA luminance
-	const float _exposure_ = 4.0;
 	const float _brightMax_ = 4.0;
-	float _yd_ = _exposure_ * (_exposure_/_brightMax_ + 1.0) / (_exposure_ + 1.0) * _luminance_;
+	float _yd_ = exposure * (exposure/_brightMax_ + 1.0) / (exposure + 1.0) * _luminance_;
 	_color_ *= _yd_;
 	gl_FragData[0].rgb = _color_;
 }

+ 5 - 4
shaders/PpsSsao.glsl

@@ -13,12 +13,12 @@ uniform sampler2D noiseMap;
 uniform sampler2D msNormalFai;
 
 varying vec2 vTexCoords;
-const float totStrength = 1.7;
+const float totStrength = 1.3;
 const float strength = 0.07;
 const float offset = 18.0;
 const float falloff = 0.000002;
 const float rad = 0.006;
-const int SAMPLES = 10; // 10 is good
+const int SAMPLES = 16; // 10 is good
 const float invSamples = 1.0/float(SAMPLES);
 
 const float MAX_SSAO_DISTANCE = 40.0;
@@ -26,14 +26,15 @@ const float MAX_SSAO_DISTANCE = 40.0;
 void main(void)
 {
 	// these are the random vectors inside a unit sphere
-	//vec3 pSphere[16] = vec3[](vec3(0.53812504, 0.18565957, -0.43192),vec3(0.13790712, 0.24864247, 0.44301823),vec3(0.33715037, 0.56794053, -0.005789503),vec3(-0.6999805, -0.04511441, -0.0019965635),vec3(0.06896307, -0.15983082, -0.85477847),vec3(0.056099437, 0.006954967, -0.1843352),vec3(-0.014653638, 0.14027752, 0.0762037),vec3(0.010019933, -0.1924225, -0.034443386),vec3(-0.35775623, -0.5301969, -0.43581226),vec3(-0.3169221, 0.106360726, 0.015860917),vec3(0.010350345, -0.58698344, 0.0046293875),vec3(-0.08972908, -0.49408212, 0.3287904),vec3(0.7119986, -0.0154690035, -0.09183723),vec3(-0.053382345, 0.059675813, -0.5411899),vec3(0.035267662, -0.063188605, 0.54602677),vec3(-0.47761092, 0.2847911, -0.0271716));
+	const vec3 pSphere[16] = vec3[](vec3(0.53812504, 0.18565957, -0.43192),vec3(0.13790712, 0.24864247, 0.44301823),vec3(0.33715037, 0.56794053, -0.005789503),vec3(-0.6999805, -0.04511441, -0.0019965635),vec3(0.06896307, -0.15983082, -0.85477847),vec3(0.056099437, 0.006954967, -0.1843352),vec3(-0.014653638, 0.14027752, 0.0762037),vec3(0.010019933, -0.1924225, -0.034443386),vec3(-0.35775623, -0.5301969, -0.43581226),vec3(-0.3169221, 0.106360726, 0.015860917),vec3(0.010350345, -0.58698344, 0.0046293875),vec3(-0.08972908, -0.49408212, 0.3287904),vec3(0.7119986, -0.0154690035, -0.09183723),vec3(-0.053382345, 0.059675813, -0.5411899),vec3(0.035267662, -0.063188605, 0.54602677),vec3(-0.47761092, 0.2847911, -0.0271716));
 	//const vec3 pSphere[8] = vec3[](vec3(0.24710192, 0.6445882, 0.033550154),vec3(0.00991752, -0.21947019, 0.7196721),vec3(0.25109035, -0.1787317, -0.011580509),vec3(-0.08781511, 0.44514698, 0.56647956),vec3(-0.011737816, -0.0643377, 0.16030222),vec3(0.035941467, 0.04990871, -0.46533614),vec3(-0.058801126, 0.7347013, -0.25399926),vec3(-0.24799341, -0.022052078, -0.13399573));
 	//const vec3 pSphere[12] = vec3[](vec3(-0.13657719, 0.30651027, 0.16118456),vec3(-0.14714938, 0.33245975, -0.113095455),vec3(0.030659059, 0.27887347, -0.7332209),vec3(0.009913514, -0.89884496, 0.07381549),vec3(0.040318526, 0.40091, 0.6847858),vec3(0.22311053, -0.3039437, -0.19340435),vec3(0.36235332, 0.21894878, -0.05407306),vec3(-0.15198798, -0.38409665, -0.46785462),vec3(-0.013492276, -0.5345803, 0.11307949),vec3(-0.4972847, 0.037064247, -0.4381323),vec3(-0.024175806, -0.008928787, 0.17719103),vec3(0.694014, -0.122672155, 0.33098832));
-	const vec3 pSphere[10] = vec3[](vec3(-0.010735935, 0.01647018, 0.0062425877),vec3(-0.06533369, 0.3647007, -0.13746321),vec3(-0.6539235, -0.016726388, -0.53000957),vec3(0.40958285, 0.0052428036, -0.5591124),vec3(-0.1465366, 0.09899267, 0.15571679),vec3(-0.44122112, -0.5458797, 0.04912532),vec3(0.03755566, -0.10961345, -0.33040273),vec3(0.019100213, 0.29652783, 0.066237666),vec3(0.8765323, 0.011236004, 0.28265962),vec3(0.29264435, -0.40794238, 0.15964167));
+	//const vec3 pSphere[10] = vec3[](vec3(-0.010735935, 0.01647018, 0.0062425877),vec3(-0.06533369, 0.3647007, -0.13746321),vec3(-0.6539235, -0.016726388, -0.53000957),vec3(0.40958285, 0.0052428036, -0.5591124),vec3(-0.1465366, 0.09899267, 0.15571679),vec3(-0.44122112, -0.5458797, 0.04912532),vec3(0.03755566, -0.10961345, -0.33040273),vec3(0.019100213, 0.29652783, 0.066237666),vec3(0.8765323, 0.011236004, 0.28265962),vec3(0.29264435, -0.40794238, 0.15964167));
 	// grab a normal for reflecting the sample rays later on
 
 
 	float currentPixelDepth = ReadFromTexAndLinearizeDepth( msDepthFai, vTexCoords, camerarange.x, camerarange.y );
+
 	/*if( currentPixelDepth * camerarange.y > MAX_SSAO_DISTANCE )
 	{
 		gl_FragColor.a = 1.0;

+ 1 - 0
src/Core/App.cpp

@@ -82,6 +82,7 @@ App::App(int argc, char* argv[], Object* parent):
 	mainRenderer = new MainRenderer(this);
 	scene = new Scene(this);
 	stdinListener = new StdinListener(this);
+	stdinListener->start();
 
 	// other
 	activeCam = NULL;

+ 9 - 0
src/Core/StdinListener.cpp

@@ -37,3 +37,12 @@ string StdinListener::getLine()
 	}
 	return ret;
 }
+
+
+//======================================================================================================================
+// start                                                                                                               =
+//======================================================================================================================
+void StdinListener::start()
+{
+	thrd = thread(&StdinListener::workingFunc, this);
+}

+ 5 - 8
src/Core/StdinListener.h

@@ -15,22 +15,19 @@
 class StdinListener: public Object
 {
 	public:
-		StdinListener(Object* parent = NULL);
+		StdinListener(Object* parent = NULL): Object(parent) {}
 		~StdinListener() {}
-		void workingFunc(); ///< The thread function
 		string getLine();
+		void start();
 
 	private:
 		queue<string> q;
 		mutex mtx;
+		thread thrd;
 
-		StdinListener(const StdinListener&): Object(NULL) {} ///< Non copyable
+		StdinListener(const StdinListener&); ///< Non copyable
+		void workingFunc(); ///< The thread function
 };
 
 
-inline StdinListener::StdinListener(Object* parent):
-	Object(parent)
-{}
-
-
 #endif

+ 4 - 4
src/Main.cpp

@@ -131,11 +131,12 @@ void init()
 	initializer.is.sm.resolution = 512;
 	initializer.pps.hdr.enabled = true;
 	initializer.pps.hdr.renderingQuality = 0.25;
-	initializer.pps.hdr.blurringDist = 0.0;
+	initializer.pps.hdr.blurringDist = 1.0;
 	initializer.pps.hdr.blurringIterations = 2;
+	initializer.pps.hdr.exposure = 4.0;
 	initializer.pps.ssao.blurringIterations = 2;
 	initializer.pps.ssao.enabled = true;
-	initializer.pps.ssao.renderingQuality = 0.25;
+	initializer.pps.ssao.renderingQuality = 0.5;
 	initializer.mainRendererQuality = 1.0;
 	app->getMainRenderer().init(initializer);
 	Ui::init();
@@ -356,6 +357,7 @@ void mainLoop()
 	INFO("Exiting main loop (" << App::getTicks()-ticks << ")");
 }
 
+#include <boost/unordered_map.hpp>
 
 //======================================================================================================================
 // main                                                                                                                =
@@ -363,8 +365,6 @@ void mainLoop()
 int main(int argc, char* argv[])
 {
 	new App(argc, argv);
-	thread thr(&StdinListener::workingFunc, &app->getStdinLintener());
-
 	init();
 
 	mainLoop();

+ 6 - 7
src/Renderer/Hdr.cpp

@@ -49,6 +49,7 @@ void Hdr::init(const RendererInitializer& initializer)
 	renderingQuality = initializer.pps.hdr.renderingQuality;
 	blurringDist = initializer.pps.hdr.blurringDist;
 	blurringIterations = initializer.pps.hdr.blurringIterations;
+	exposure = initializer.pps.hdr.exposure;
 
 	initFbo(toneFbo, toneFai);
 	initFbo(hblurFbo, hblurFai);
@@ -59,19 +60,16 @@ void Hdr::init(const RendererInitializer& initializer)
 
 	// init shaders
 	toneSProg.loadRsrc("shaders/PpsHdr.glsl");
-	toneProgFaiUniVar = toneSProg->findUniVar("fai");
 
 	const char* SHADER_FILENAME = "shaders/GaussianBlurGeneric.glsl";
 
 	string pps = "#define HPASS\n#define COL_RGB\n";
 	string prefix = "HorizontalRgb";
 	hblurSProg.loadRsrc(ShaderProg::createSrcCodeToCache(SHADER_FILENAME, pps.c_str(), prefix.c_str()).c_str());
-	hblurSProgFaiUniVar = hblurSProg->findUniVar("img");
 
 	pps = "#define VPASS\n#define COL_RGB\n";
 	prefix = "VerticalRgb";
 	vblurSProg.loadRsrc(ShaderProg::createSrcCodeToCache(SHADER_FILENAME, pps.c_str(), prefix.c_str()).c_str());
-	vblurSProgFaiUniVar = vblurSProg->findUniVar("img");
 }
 
 #include "App.h"
@@ -91,7 +89,8 @@ void Hdr::run()
 	// pass 0
 	toneFbo.bind();
 	toneSProg->bind();
-	toneProgFaiUniVar->setTexture(r.pps.prePassFai, 0);
+	toneSProg->findUniVar("exposure")->setFloat(exposure);
+	toneSProg->findUniVar("fai")->setTexture(r.pps.prePassFai, 0);
 	Renderer::drawQuad(0);
 
 
@@ -105,11 +104,11 @@ void Hdr::run()
 		hblurSProg->bind();
 		if(i == 0)
 		{
-			hblurSProgFaiUniVar->setTexture(toneFai, 0);
+			hblurSProg->findUniVar("img")->setTexture(toneFai, 0);
 		}
 		else
 		{
-			hblurSProgFaiUniVar->setTexture(fai, 0);
+			hblurSProg->findUniVar("img")->setTexture(fai, 0);
 		}
 		hblurSProg->findUniVar("imgDimension")->setFloat(w);
 		hblurSProg->findUniVar("blurringDist")->setFloat(blurringDist / w);
@@ -118,7 +117,7 @@ void Hdr::run()
 		// vpass
 		vblurFbo.bind();
 		vblurSProg->bind();
-		vblurSProgFaiUniVar->setTexture(hblurFai, 0);
+		vblurSProg->findUniVar("img")->setTexture(hblurFai, 0);
 		vblurSProg->findUniVar("imgDimension")->setFloat(h);
 		vblurSProg->findUniVar("blurringDist")->setFloat(blurringDist / h);
 		Renderer::drawQuad(0);

+ 3 - 4
src/Renderer/Hdr.h

@@ -31,6 +31,8 @@ class Hdr: private RenderingStage
 		void setBlurringDist(float f) {blurringDist = f;}
 		uint getBlurringIterations() {return blurringIterations;}
 		void setBlurringIterations(uint i) {blurringIterations = i;}
+		float getExposure() const {return exposure;}
+		void setExposure(float f) {exposure = f;}
 		bool isEnabled() const {return enabled;}
 		float getRenderingQuality() const {return renderingQuality;}
 		/**@}*/
@@ -42,12 +44,9 @@ class Hdr: private RenderingStage
 		RsrcPtr<ShaderProg> toneSProg;
 		RsrcPtr<ShaderProg> hblurSProg;
 		RsrcPtr<ShaderProg> vblurSProg;
-		const ShaderProg::UniVar* toneProgFaiUniVar;
-		const ShaderProg::UniVar* hblurSProgFaiUniVar;
-		const ShaderProg::UniVar* vblurSProgFaiUniVar;
 		float blurringDist;
 		uint blurringIterations;
-		float overExposure; ///< @todo
+		float exposure; ///< @todo
 		bool enabled;
 		float renderingQuality;
 

+ 8 - 9
src/Renderer/Is.cpp

@@ -10,9 +10,9 @@
 
 
 //======================================================================================================================
-// CalcViewVector                                                                                                      =
+// calcViewVectors                                                                                                     =
 //======================================================================================================================
-void Is::calcViewVector()
+void Is::calcViewVectors()
 {
 	const Camera& cam = r.getCamera();
 
@@ -20,9 +20,8 @@ void Is::calcViewVector()
 	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}};
-
-	uint viewport[4]={ 0, 0, w, h };
+	uint pixels[4][2]={{w, h}, {0, h}, {0, 0}, {w, 0}};
+	uint viewport[4]={0, 0, w, h};
 
 	for(int i=0; i<4; i++)
 	{
@@ -35,8 +34,8 @@ void Is::calcViewVector()
 		 */
 
 		Vec3 vec;
-		vec.x = (2.0*(pixels[i][0]-viewport[0]))/viewport[2] - 1.0;
-		vec.y = (2.0*(pixels[i][1]-viewport[1]))/viewport[3] - 1.0;
+		vec.x = (2.0 * (pixels[i][0] - viewport[0])) / viewport[2] - 1.0;
+		vec.y = (2.0 * (pixels[i][1] - viewport[1])) / viewport[3] - 1.0;
 		vec.z = 1.0;
 
 		viewVectors[i] = vec.getTransformed(cam.getInvProjectionMatrix());
@@ -346,7 +345,7 @@ void Is::run()
 
 	glDisable(GL_DEPTH_TEST);
 
-	// ambient passstatic float quadVertCoords [][2];
+	// ambient pass
 	ambientPass(app->getScene().getAmbientCol());
 
 	// light passes
@@ -354,7 +353,7 @@ void Is::run()
 	glBlendFunc(GL_ONE, GL_ONE);
 	glEnable(GL_STENCIL_TEST);
 
-	calcViewVector();
+	calcViewVectors();
 	calcPlanes();
 
 	// for all lights

+ 1 - 1
src/Renderer/Is.h

@@ -70,7 +70,7 @@ class Is: private RenderingStage
 		/**
 		 * Calc the view vector that we will use inside the shader to calculate the frag pos in view space
 		 */
-		void calcViewVector();
+		void calcViewVectors();
 
 		/**
 		 * Calc the planes that we will use inside the shader to calculate the frag pos in view space

+ 1 - 1
src/Renderer/Ms.cpp

@@ -31,7 +31,7 @@ void Ms::init(const RendererInitializer& initializer)
 	normalFai.setRepeat(false);
 	diffuseFai.setRepeat(false);
 	specularFai.setRepeat(false);
-	depthFai.setRepeat(true);
+	depthFai.setRepeat(false);
 
 
 	// attach the buffers to the FBO

+ 1 - 0
src/Renderer/RendererInitializer.h

@@ -42,6 +42,7 @@ struct RendererInitializer
 			float renderingQuality;
 			float blurringDist;
 			float blurringIterations;
+			float exposure;
 		} hdr;
 
 		// Ssao

+ 4 - 4
src/Renderer/Ssao.cpp

@@ -89,17 +89,17 @@ void Ssao::init(const RendererInitializer& initializer)
 	/// @todo fix this crap
 	// load noise map and disable temporally the texture compression and enable mipmapping
 	GL_OK();
-	bool texCompr = Texture::compressionEnabled;
+	/*bool texCompr = Texture::compressionEnabled;
 	bool mipmaping = Texture::mipmappingEnabled;
 	Texture::compressionEnabled = false;
-	Texture::mipmappingEnabled = true;
+	Texture::mipmappingEnabled = true;*/
 	noiseMap.loadRsrc("gfx/noise3.tga");
-	noiseMap->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
+	/*noiseMap->setTexParameter(GL_TEXTURE_WRAP_S, GL_REPEAT);
 	noiseMap->setTexParameter(GL_TEXTURE_WRAP_T, GL_REPEAT);
 	//noise_map->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	//noise_map->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	Texture::compressionEnabled = texCompr;
-	Texture::mipmappingEnabled = mipmaping;
+	Texture::mipmappingEnabled = mipmaping;*/
 	GL_OK();
 }
 

+ 1 - 1
src/Resources/Core/RsrcPtr.h

@@ -35,7 +35,7 @@ class RsrcPtr
 		/**
 		 * Non copyable
 		 */
-		RsrcPtr(const RsrcPtr& a) {}
+		RsrcPtr(const RsrcPtr& a);
 
 		/**
 		 * Unloads the resource @see loadRsrc

+ 6 - 4
src/Resources/ShaderProg.h

@@ -82,8 +82,10 @@ class ShaderProg: public Resource
 		};
 		
 	private:
-		typedef unordered_map<string,UniVar*>::const_iterator NameToUniVarIterator; ///< Uniform variable name to variable iterator
-		typedef unordered_map<string,AttribVar*>::const_iterator NameToAttribVarIterator; ///< Attribute variable name to variable iterator
+		/// Uniform variable name to variable iterator
+		typedef unordered_map<string, UniVar*>::const_iterator NameToUniVarIterator;
+		/// Attribute variable name to variable iterator
+		typedef unordered_map<string, AttribVar*>::const_iterator NameToAttribVarIterator;
 
 	//====================================================================================================================
 	// Public                                                                                                            =
@@ -158,8 +160,8 @@ class ShaderProg: public Resource
 		static string stdSourceCode;
 		Vec<UniVar> uniVars; ///< All the uniform variables
 		Vec<AttribVar> attribVars; ///< All the attribute variables
-		unordered_map<string,UniVar*> uniNameToVar;  ///< A UnorderedMap for quick variable searching
-		unordered_map<string,AttribVar*> attribNameToVar; ///< @see uniNameToVar
+		unordered_map<string, UniVar*> uniNameToVar;  ///< A UnorderedMap for quick variable searching
+		unordered_map<string, AttribVar*> attribNameToVar; ///< @see uniNameToVar
 
 		/**
 		 * After the linking of the shader prog is done gather all the vars in custom containers

+ 1 - 0
src/Scripting/Renderer/Hdr.bpi.h

@@ -2,4 +2,5 @@
 class_<Hdr, noncopyable>("Hdr", no_init)
 	.add_property("blurringIterations", &Hdr::getBlurringIterations, &Hdr::setBlurringIterations)
 	.add_property("blurringDist", &Hdr::getBlurringDist, &Hdr::setBlurringDist)
+	.add_property("exposure", &Hdr::getExposure, &Hdr::setExposure)
 ;