浏览代码

- Exposing Input to python
- Optimizing SSAO

Panagiotis Christopoulos Charitos 14 年之前
父节点
当前提交
10540ca8be

+ 30 - 30
.cproject

@@ -5,35 +5,35 @@
 	<storageModule moduleId="org.eclipse.cdt.core.settings">
 		<cconfiguration id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304">
 			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304" moduleId="org.eclipse.cdt.core.settings" name="Default">
-<externalSettings/>
-<extensions>
-<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
-<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
-<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
-<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
-<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
-</extensions>
-</storageModule>
+				<externalSettings/>
+				<extensions>
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
 			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-<configuration artifactName="anki" buildProperties="" description="" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
-<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304.1771284297" name="/" resourcePath="">
-<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.cross.base.652528495" name="cdt.managedbuild.toolchain.gnu.cross.base" resourceTypeBasedDiscovery="false">
-<option id="cdt.managedbuild.option.gnu.cross.prefix.124248385" name="Prefix"/>
-<option id="cdt.managedbuild.option.gnu.cross.path.568633506" name="Path"/>
-<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.2099631" isAbstract="false" osList="all"/>
-<builder arguments="make -j 4" autoBuildTarget="all" buildPath="${workspace_loc:/anki/build/debug}" cleanBuildTarget="clean" command="nice" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304.618553305" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelizationNumber="1" superClass="org.eclipse.cdt.build.core.settings.default.builder">
-<outputEntries>
-<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="build/debug"/>
-</outputEntries>
-</builder>
-</toolChain>
-</folderInfo>
-<sourceEntries>
-<entry excluding="include|src|Collision" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
-<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
-</sourceEntries>
-</configuration>
-</storageModule>
+				<configuration artifactName="anki" buildProperties="" description="" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+					<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304.1771284297" name="/" resourcePath="">
+						<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.cross.base.652528495" name="cdt.managedbuild.toolchain.gnu.cross.base" resourceTypeBasedDiscovery="false">
+							<option id="cdt.managedbuild.option.gnu.cross.prefix.124248385" name="Prefix"/>
+							<option id="cdt.managedbuild.option.gnu.cross.path.568633506" name="Path"/>
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.2099631" isAbstract="false" osList="all"/>
+							<builder arguments="make -j 4" autoBuildTarget="all" buildPath="${workspace_loc:/anki/build/debug}" cleanBuildTarget="clean" command="nice" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.toolchain.gnu.cross.base.1593777304.618553305" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelizationNumber="1" superClass="org.eclipse.cdt.build.core.settings.default.builder">
+								<outputEntries>
+									<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="build/debug"/>
+								</outputEntries>
+							</builder>
+						</toolChain>
+					</folderInfo>
+					<sourceEntries>
+						<entry excluding="include|Collision|src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
+					</sourceEntries>
+				</configuration>
+			</storageModule>
 			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
 			<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
 			<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
@@ -289,6 +289,6 @@
 		</cconfiguration>
 	</storageModule>
 	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-<project id="anki.null.323176720" name="anki"/>
-</storageModule>
+		<project id="anki.null.323176720" name="anki"/>
+	</storageModule>
 </cproject>

文件差异内容过多而无法显示
+ 0 - 1
build/debug/Makefile


+ 24 - 23
shaders/IsLpGeneric.glsl

@@ -40,6 +40,7 @@ uniform vec3 lightSpecularCol;
 	uniform mat4 texProjectionMat;
 	#if defined(SHADOW_ENABLED)
 		uniform sampler2DShadow shadowMap;
+		uniform float shadowMapSize;
 	#endif
 #endif
 /// @}
@@ -96,24 +97,24 @@ float getAttenuation(in float fragLightDist)
 /// @return The blurred shadow
 float pcfLow(in vec3 shadowUv)
 {
-	const float MAP_SCALE = 1.0 / SHADOWMAP_SIZE;
+	float mapScale = 1.0 / shadowMapSize;
 	const int KERNEL_SIZE = 8;
 	const vec2 KERNEL[KERNEL_SIZE] = vec2[]
 	(
-		vec2(MAP_SCALE, MAP_SCALE),
-		vec2(MAP_SCALE, -MAP_SCALE),
-		vec2(-MAP_SCALE, MAP_SCALE),
-		vec2(-MAP_SCALE, -MAP_SCALE),
-		vec2(0.0, MAP_SCALE),
-		vec2(0.0, -MAP_SCALE),
-		vec2(MAP_SCALE, 0.0),
-		vec2(-MAP_SCALE, 0.0)
+		vec2(1.0, 1.0),
+		vec2(1.0, -1.0),
+		vec2(-1.0, 1.0),
+		vec2(-1.0, -1.0),
+		vec2(0.0, 1.0),
+		vec2(0.0, -1.0),
+		vec2(1.0, 0.0),
+		vec2(-1.0, 0.0)
 	);
 	
 	float shadowCol = shadow2D(shadowMap, shadowUv).r;
-	for(int i=0; i<KERNEL_SIZE; i++)
+	for(int i = 0; i < KERNEL_SIZE; i++)
 	{
-		vec3 uv = vec3(shadowUv.xy + KERNEL[i], shadowUv.z);
+		vec3 uv = vec3(shadowUv.xy + (KERNEL[i] * mapScale), shadowUv.z);
 		shadowCol += shadow2D(shadowMap, uv).r;
 	}
 	
@@ -195,22 +196,22 @@ void main()
 	// Spot light
 	//
 	#elif defined(SPOT_LIGHT_ENABLED)
-		vec4 vTexCoords2 = texProjectionMat * vec4(fragPosVspace, 1.0);
-		vec3 vTexCoords3 = vTexCoords2.xyz / vTexCoords2.w;
-
-		if(vTexCoords2.w > 0.0 &&
-		   vTexCoords3.x > 0.0 &&
-		   vTexCoords3.x < 1.0 &&
-		   vTexCoords3.y > 0.0 &&
-		   vTexCoords3.y < 1.0 &&
-		   vTexCoords2.w < lightRadius)
+		vec4 texCoords2 = texProjectionMat * vec4(fragPosVspace, 1.0);
+		vec3 texCoords3 = texCoords2.xyz / texCoords2.w;
+
+		if(texCoords2.w > 0.0 &&
+		   texCoords3.x > 0.0 &&
+		   texCoords3.x < 1.0 &&
+		   texCoords3.y > 0.0 &&
+		   texCoords3.y < 1.0 &&
+		   texCoords2.w < lightRadius)
 		{
 			// Get shadow
 			#if defined(SHADOW_ENABLED)
 				#if defined(PCF_ENABLED)
-					float shadowCol = pcfLow(vTexCoords3);
+					float shadowCol = pcfLow(texCoords3);
 				#else
-					float shadowCol = shadow2D(shadowMap, vTexCoords3).r;
+					float shadowCol = shadow2D(shadowMap, texCoords3).r;
 				#endif
 
 				if(shadowCol == 0.0)
@@ -222,7 +223,7 @@ void main()
 			float fragLightDist;
 			vec3 color = doPhong(fragPosVspace, fragLightDist);
 
-			vec3 lightTexCol = texture2DProj(lightTex, vTexCoords2.xyz).rgb;
+			vec3 lightTexCol = texture2DProj(lightTex, texCoords2.xyz).rgb;
 			float att = getAttenuation(fragLightDist);
 
 			#if defined(SHADOW_ENABLED)

+ 22 - 12
shaders/PpsSsao.glsl

@@ -10,12 +10,13 @@
 /// @{
 uniform vec2 planes; ///< for the calculation of frag pos in view space
 uniform vec2 limitsOfNearPlane; ///< for the calculation of frag pos in view space
+uniform vec2 limitsOfNearPlane2; ///< This is an optimization see r403 for the clean one
 uniform float zNear; ///< for the calculation of frag pos in view space
 uniform sampler2D msDepthFai; ///< for the calculation of frag pos in view space
 
 uniform sampler2D noiseMap; /// Used in getRandom
-uniform float noiseMapSize = 100.0; /// Used in getRandom
-uniform vec2 screenSize; /// Used in getRandom
+uniform float noiseMapSize = 0.0; /// Used in getRandom
+uniform vec2 screenSize = 0.0; /// Used in getRandom
 
 uniform sampler2D msNormalFai; /// Used in getNormal
 /// @}
@@ -30,7 +31,6 @@ in vec2 vTexCoords;
 layout(location = 0) out float fColor;
 /// @}
 
-
 /// @name Consts
 /// @{
 uniform float SAMPLE_RAD = 0.1;  /// Used in main
@@ -63,7 +63,8 @@ vec3 getPosition(in vec2 uv)
 	vec3 fragPosVspace;
 	fragPosVspace.z = -planes.y / (planes.x + depth);
 	
-	fragPosVspace.xy = (((uv) * 2.0) - 1.0) * limitsOfNearPlane;
+	// Old: fragPosVspace.xy = (uv * 2.0 - 1.0) * limitsOfNearPlane;
+	fragPosVspace.xy = (uv * limitsOfNearPlane2) - limitsOfNearPlane;
 	
 	float sc = -fragPosVspace.z / zNear;
 	fragPosVspace.xy *= sc;
@@ -71,10 +72,11 @@ vec3 getPosition(in vec2 uv)
 	return fragPosVspace;
 }
 
+
 /// Calculate the ambient occlusion factor
-float doAmbientOcclusion(in vec2 tcoord, in vec2 uv, in vec3 original, in vec3 cnorm)
+float doAmbientOcclusion(in vec2 uv, in vec3 original, in vec3 cnorm)
 {
-	vec3 newp = getPosition(tcoord + uv);
+	vec3 newp = getPosition(uv);
 	vec3 diff = newp - original;
 	vec3 v = normalize(diff);
 	float d = length(diff) /* * SCALE*/;
@@ -86,21 +88,29 @@ float doAmbientOcclusion(in vec2 tcoord, in vec2 uv, in vec3 original, in vec3 c
 
 void main(void)
 {
-	const vec2 KERNEL[16] = vec2[](vec2(0.53812504, 0.18565957), vec2(0.13790712, 0.24864247), vec2(0.33715037, 0.56794053), vec2(-0.6999805, -0.04511441), vec2(0.06896307, -0.15983082), vec2(0.056099437, 0.006954967), vec2(-0.014653638, 0.14027752), vec2(0.010019933, -0.1924225), vec2(-0.35775623, -0.5301969), vec2(-0.3169221, 0.106360726), vec2(0.010350345, -0.58698344), vec2(-0.08972908, -0.49408212), vec2(0.7119986, -0.0154690035), vec2(-0.053382345, 0.059675813), vec2(0.035267662, -0.063188605), vec2(-0.47761092, 0.2847911));
+	const int KERNEL_SIZE = 16;
+
+	const vec2 KERNEL[KERNEL_SIZE] = vec2[](vec2(0.53812504, 0.18565957), vec2(0.13790712, 0.24864247), 
+	                                        vec2(0.33715037, 0.56794053), vec2(-0.6999805, -0.04511441),
+	                                        vec2(0.06896307, -0.15983082), vec2(0.056099437, 0.006954967),
+	                                        vec2(-0.014653638, 0.14027752), vec2(0.010019933, -0.1924225),
+	                                        vec2(-0.35775623, -0.5301969), vec2(-0.3169221, 0.106360726),
+	                                        vec2(0.010350345, -0.58698344), vec2(-0.08972908, -0.49408212),
+	                                        vec2(0.7119986, -0.0154690035), vec2(-0.053382345, 0.059675813),
+	                                        vec2(0.035267662, -0.063188605), vec2(-0.47761092, 0.2847911));
 
 	vec3 p = getPosition(vTexCoords);
 	vec3 n = getNormal(vTexCoords);
 	vec2 rand = getRandom(vTexCoords);
 
 	fColor = 0.0;
-
-	const int ITERATIONS = 16;
-	for(int j = 0; j < ITERATIONS; ++j)
+	
+	for(int j = 0; j < KERNEL_SIZE; ++j)
 	{
 		vec2 coord = reflect(KERNEL[j], rand) * SAMPLE_RAD;
-		fColor += doAmbientOcclusion(vTexCoords, coord, p, n);
+		fColor += doAmbientOcclusion(vTexCoords + coord, p, n);
 	}
 
-	fColor = 1.0 - fColor / ITERATIONS;
+	fColor = 1.0 - fColor / KERNEL_SIZE;
 }
 

+ 2 - 1
src/Core/App.cpp

@@ -207,7 +207,8 @@ void App::initRenderer()
 	initializer.is.sm.bilinearEnabled = true;
 	initializer.is.sm.enabled = true;
 	initializer.is.sm.pcfEnabled = true;
-	initializer.is.sm.resolution = 512;
+	initializer.is.sm.resolution = 1024;
+	initializer.is.sm.level0Distance = 5.0;
 	initializer.pps.hdr.enabled = true;
 	initializer.pps.hdr.renderingQuality = 0.25;
 	initializer.pps.hdr.blurringDist = 1.0;

+ 6 - 4
src/Input/Input.cpp

@@ -10,7 +10,7 @@
 void Input::init()
 {
 	INFO("Initializing input...");
-	warpMouse = false;
+	warpMouseFlag = false;
 	hideCursor = true;
 	reset();
 	INFO("Input initialized");
@@ -87,12 +87,14 @@ void Input::handleEvents()
 				mousePosNdc.x() = (2.0 * mousePos.x()) / (float)AppSingleton::getInstance().getWindowWidth() - 1.0;
 				mousePosNdc.y() = 1.0 - (2.0 * mousePos.y()) / (float)AppSingleton::getInstance().getWindowHeight();
 
-				if(warpMouse)
+				if(warpMouseFlag)
 				{
-					// the SDL_WarpMouse pushes an event in the event queue. This check is so we wont process the event of the...
-					// ...SDL_WarpMouse function
+					// the SDL_WarpMouse pushes an event in the event queue. This check is so we wont process...
+					// ...the event of the SDL_WarpMouse function
 					if(mousePosNdc == Vec2(0.0))
+					{
 						break;
+					}
 
 					SDL_WarpMouse(AppSingleton::getInstance().getWindowWidth() / 2,
 					              AppSingleton::getInstance().getWindowHeight() / 2);

+ 10 - 3
src/Input/Input.h

@@ -5,6 +5,7 @@
 #include <boost/array.hpp>
 #include "Math.h"
 #include "Singleton.h"
+#include "Accessors.h"
 
 
 /// Handle the SDL input
@@ -12,17 +13,21 @@ class Input
 {
 	public:
 		Input() {init();}
-		void reset();
-		void handleEvents();
 
+		/// @name Acessors
+		/// @{
 		short getKey(uint i) const {return keys[i];}
 		short getMouseBtn(uint i) const {return mouseBtns[i];}
+		GETTER_SETTER_BY_VAL(bool, warpMouseFlag, warpMouse, setWarpMouse)
+		/// @}
+
+		void reset();
+		void handleEvents();
 
 		// mouse stuff
 		Vec2 mousePosNdc; ///< The coords are in the NDC space
 		Vec2 mousePos;     ///< The coords are in the window space. (0, 0) is in the upper left corner
 		Vec2 mouseVelocity;
-		bool warpMouse;
 		bool hideCursor;
 
 	private:
@@ -38,6 +43,8 @@ class Input
 		boost::array<short, 8> mouseBtns; ///< Mouse btns. Supporting 3 btns & wheel. @see keys
 		/// @}
 
+		bool warpMouseFlag;
+
 		void init();
 };
 

+ 2 - 2
src/Main.cpp

@@ -262,7 +262,7 @@ void mainLoopExtra()
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_4)) mover = point_lights[1];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_5)) mover = spot_lights[1];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = imp;
-	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
+	//if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
 
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_A)) mover->moveLocalX(-dist);
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_D)) mover->moveLocalX(dist);
@@ -270,7 +270,7 @@ void mainLoopExtra()
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_SPACE)) mover->moveLocalY(-dist);
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_W)) mover->moveLocalZ(-dist);
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_S)) mover->moveLocalZ(dist);
-	if(!InputSingleton::getInstance().warpMouse)
+	if(!InputSingleton::getInstance().warpMouse())
 	{
 		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_UP)) mover->rotateLocalX(ang);
 		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_DOWN)) mover->rotateLocalX(-ang);

+ 0 - 1
src/Renderer/Drawers/SceneDrawer.cpp

@@ -84,7 +84,6 @@ void SceneDrawer::setupShaderProg(const MaterialRuntime& mtlr, const Transform&
 {
 	uint textureUnit = 0;
 
-	//const Material& mtl = mtlr.getMaterial();
 	mtlr.getMaterial().getShaderProg().bind();
 
 	//

+ 9 - 8
src/Renderer/Is.cpp

@@ -26,7 +26,6 @@ Is::Is(Renderer& r_):
 {}
 
 
-
 //======================================================================================================================
 // calcViewVectors                                                                                                     =
 //======================================================================================================================
@@ -148,17 +147,16 @@ void Is::init(const RendererInitializer& initializer)
 	// spot light no shadow
 	spotLightNoShadowSProg.loadRsrc(ShaderProg::createSrcCodeToCache("shaders/IsLpGeneric.glsl",
 	                                                                 "#define SPOT_LIGHT_ENABLED\n",
-	                                                                 "SpotNoShadow").c_str());
+	                                                                 "Spot_NoShadow").c_str());
 
 	// spot light w/t shadow
-	std::string pps = std::string("\n#define SPOT_LIGHT_ENABLED\n#define SHADOW_ENABLED\n") +
-	                              "#define SHADOWMAP_SIZE " + boost::lexical_cast<std::string>(sm.getResolution()) +
-	                              "\n";
-	std::string prefix = "SpotShadowSmSize" + boost::lexical_cast<std::string>(sm.getResolution());
+	std::string pps = std::string("#define SPOT_LIGHT_ENABLED\n"
+	                              "#define SHADOW_ENABLED\n");
+	std::string prefix = "Spot_Shadow";
 	if(sm.isPcfEnabled())
 	{
 		pps += "#define PCF_ENABLED\n";
-		prefix += "Pcf";
+		prefix += "_Pcf";
 	}
 	spotLightShadowSProg.loadRsrc(ShaderProg::createSrcCodeToCache("shaders/IsLpGeneric.glsl", pps.c_str(),
 	                                                               prefix.c_str()).c_str());
@@ -253,7 +251,8 @@ void Is::spotLightPass(const SpotLight& light)
 	// shadow mapping
 	if(light.castsShadow() && sm.isEnabled())
 	{
-		sm.run(light.getCamera());
+		float dist = (light.getWorldTransform().getOrigin() - cam.getWorldTransform().getOrigin()).getLength();
+		sm.run(light.getCamera(), dist);
 
 		// restore the IS FBO
 		fbo.bind();
@@ -315,6 +314,8 @@ void Is::spotLightPass(const SpotLight& light)
 	if(light.castsShadow() && sm.isEnabled())
 	{
 		shdr->findUniVar("shadowMap")->set(sm.getShadowMap(), 5);
+		float smSize = sm.getShadowMap().getWidth();
+		shdr->findUniVar("shadowMapSize")->set(&smSize);
 	}
 
 	// render quad

+ 1 - 0
src/Renderer/RendererInitializer.h

@@ -26,6 +26,7 @@ struct RendererInitializer
 			bool pcfEnabled;
 			bool bilinearEnabled;
 			int resolution;
+			float level0Distance;
 		} sm;
 	} is;
 

+ 52 - 14
src/Renderer/Sm.cpp

@@ -16,27 +16,49 @@ 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;
+	level0Distance = initializer.is.sm.level0Distance;
+
+	// Init the levels
+	initLevel(resolution, level0Distance, bilinearEnabled, levels[0]);
+	for(uint i = 1; i < levels.size(); i++)
+	{
+		initLevel(levels[i - 1].resolution / 2, levels[i - 1].distance * 2.0, false, levels[i]);
+	}
+}
+
+
+//======================================================================================================================
+// initLevel                                                                                                           =
+//======================================================================================================================
+void Sm::initLevel(uint resolution, float distance, bool bilinear, Level& level)
+{
+	level.resolution = resolution;
+	level.distance = distance;
+	level.bilinear = bilinear;
 
 	try
 	{
 		// create FBO
-		fbo.create();
-		fbo.bind();
+		level.fbo.create();
+		level.fbo.bind();
 
 		// texture
-		Renderer::createFai(resolution, resolution, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, shadowMap);
-		if(bilinearEnabled)
+		Renderer::createFai(level.resolution, level.resolution, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,
+		                    GL_FLOAT, level.shadowMap);
+		if(level.bilinear)
 		{
-			shadowMap.setFiltering(Texture::TFT_LINEAR);
+			level.shadowMap.setFiltering(Texture::TFT_LINEAR);
 		}
 		else
 		{
-			shadowMap.setFiltering(Texture::TFT_NEAREST);
+			level.shadowMap.setFiltering(Texture::TFT_NEAREST);
 		}
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
@@ -48,16 +70,16 @@ void Sm::init(const RendererInitializer& initializer)
 		 */
 
 		// inform the we wont write to color buffers
-		fbo.setNumOfColorAttachements(0);
+		level.fbo.setNumOfColorAttachements(0);
 
 		// attach the texture
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMap.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, level.shadowMap.getGlId(), 0);
 
 		// test if success
-		fbo.checkIfGood();
+		level.fbo.checkIfGood();
 
 		// unbind
-		fbo.unbind();
+		level.fbo.unbind();
 	}
 	catch(std::exception& e)
 	{
@@ -69,18 +91,34 @@ void Sm::init(const RendererInitializer& initializer)
 //======================================================================================================================
 // run                                                                                                                 =
 //======================================================================================================================
-void Sm::run(const Camera& cam)
+void Sm::run(const Camera& cam, float distance)
 {
 	if(!enabled)
 	{
 		return;
 	}
 
+	//
+	// Determine the level
+	//
+	BOOST_FOREACH(Level& level, levels)
+	{
+		crntLevel = &level;
+		if(distance < level.distance)
+		{
+			break;
+		}
+	}
+
+	//
+	// Render
+	//
+
 	// FBO
-	fbo.bind();
+	crntLevel->fbo.bind();
 
 	// set GL
-	Renderer::setViewport(0, 0, resolution, resolution);
+	Renderer::setViewport(0, 0, crntLevel->resolution, crntLevel->resolution);
 	glClear(GL_DEPTH_BUFFER_BIT);
 
 	// disable color & blend & enable depth test
@@ -104,5 +142,5 @@ void Sm::run(const Camera& cam)
 
 
 	// FBO
-	fbo.unbind();
+	crntLevel->fbo.unbind();
 }

+ 27 - 8
src/Renderer/Sm.h

@@ -19,7 +19,7 @@ class Sm: private RenderingPass
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(Texture, shadowMap, getShadowMap)
+		GETTER_R(Texture, crntLevel->shadowMap, getShadowMap)
 		GETTER_R_BY_VAL(bool, enabled, isEnabled)
 		GETTER_R_BY_VAL(bool, pcfEnabled, isPcfEnabled)
 		GETTER_R_BY_VAL(bool, bilinearEnabled, isBilinearEnabled)
@@ -30,15 +30,34 @@ class Sm: private RenderingPass
 
 		/// Render the scene only with depth and store the result in the shadowMap
 		/// @param[in] cam The light camera
-		void run(const Camera& cam);
+		/// @param[in] distance The distance between the viewers camera and the light
+		void run(const Camera& cam, float distance);
 
 	private:
-		Fbo fbo; ///< Illumination stage shadowmapping FBO
-		Texture shadowMap;
-		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
+		/// The shadowmap levels of detail
+		/// It starts from level 0 which is the detailed one and moves to lower resolution shadowmaps. When the
+		/// distance between the viewer's camera and the light is getting bigger then a higher level will be used
+		struct Level
+		{
+			Fbo fbo; ///< Illumination stage shadowmapping FBO
+			Texture shadowMap; ///< The shadowmap for that level
+			uint resolution; ///< The shadowmap's resolution
+			bool bilinear; ///< Enable bilinar filtering in shadowmap
+			/// The maximum distance that this level applies. The distance is between the viewer's camera and the light
+			float distance;
+		};
+
+		boost::array<Level, 2> levels; ///< The levels of detail. The 0 is the detailed one
+		Level* crntLevel; ///< Current level of detail. Assigned by run
+
+		bool enabled; ///< If false then disable SM at all
+		bool pcfEnabled; ///< Enable Percentage Closer Filtering for all the levels
+		bool bilinearEnabled; ///< Shadowmap bilinear filtering for the first level. Better quality
+		int resolution; ///< Shadowmap resolution of the first level. The higher the better but slower
+		float level0Distance; ///< The distance of the first level. @see Level::distance
+
+		/// Initialize a level
+		static void initLevel(uint resolution, float maxDistance, bool bilinear, Level& level);
 };
 
 

+ 4 - 0
src/Renderer/Ssao.cpp

@@ -133,6 +133,10 @@ void Ssao::run()
 	limitsOfNearPlane.x() = limitsOfNearPlane.y() * (pcam.getFovX() / pcam.getFovY());
 	ssaoSProg->findUniVar("limitsOfNearPlane")->set(&limitsOfNearPlane);
 
+	// limitsOfNearPlane2
+	limitsOfNearPlane *= 2;
+	ssaoSProg->findUniVar("limitsOfNearPlane2")->set(&limitsOfNearPlane);
+
 	// zNear
 	float zNear = cam.getZNear();
 	ssaoSProg->findUniVar("zNear")->set(&zNear);

+ 3 - 0
src/Scripting/BoostPythonInterfaces.cpp

@@ -32,4 +32,7 @@ BOOST_PYTHON_MODULE(Anki)
 
 	CALL_WRAP(App);
 	CALL_WRAP(AppSingleton);
+
+	CALL_WRAP(Input);
+	CALL_WRAP(InputSingleton);
 }

+ 14 - 0
src/Scripting/Input/Input.bpi.cpp

@@ -0,0 +1,14 @@
+#include "ScriptingCommon.h"
+#include "Input.h"
+
+
+WRAP(Input)
+{
+	class_<Input, noncopyable>("Input", no_init)
+		.def("warpMouse", (bool (Input::*)() const)(&Input::warpMouse))
+		.def("setWarpMouse", &Input::setWarpMouse)
+	;
+}
+
+
+WRAP_SINGLETON(InputSingleton)

部分文件因为文件数量过多而无法显示