Răsfoiți Sursa

- Tweaking SSAO
- Adding SM levels
- Adding Line segment

Panagiotis Christopoulos Charitos 14 ani în urmă
părinte
comite
e96f9b0327

Fișier diff suprimat deoarece este prea mare
+ 0 - 1
build/debug/Makefile


Fișier diff suprimat deoarece este prea mare
+ 0 - 1
build/release/Makefile


+ 4 - 2
shaders/PpsSsao.glsl

@@ -16,7 +16,7 @@ uniform sampler2D msDepthFai; ///< for the calculation of frag pos in view space
 
 uniform sampler2D noiseMap; /// Used in getRandom
 uniform float noiseMapSize = 0.0; /// Used in getRandom
-uniform vec2 screenSize = 0.0; /// Used in getRandom
+uniform vec2 screenSize = vec2(0.0); /// Used in getRandom
 
 uniform sampler2D msNormalFai; /// Used in getNormal
 /// @}
@@ -33,7 +33,7 @@ layout(location = 0) out float fColor;
 
 /// @name Consts
 /// @{
-uniform float SAMPLE_RAD = 0.1;  /// Used in main
+uniform float SAMPLE_RAD = 0.08;  /// Used in main
 uniform float SCALE = 1.0; /// Used in doAmbientOcclusion
 uniform float INTENSITY = 3.0; /// Used in doAmbientOcclusion
 uniform float BIAS = 0.00; /// Used in doAmbientOcclusion
@@ -112,5 +112,7 @@ void main(void)
 	}
 
 	fColor = 1.0 - fColor / KERNEL_SIZE;
+
+	//fColor = fColor - fColor + rand.x;
 }
 

+ 1 - 0
src/Collision/Collision.h

@@ -5,6 +5,7 @@
 #include "Sphere.h"
 #include "Obb.h"
 #include "Ray.h"
+#include "LineSegment.h"
 
 
 #endif

+ 2 - 0
src/Collision/CollisionShape.h

@@ -1,6 +1,8 @@
 #ifndef COLLISION_SHAPE
 #define COLLISION_SHAPE
 
+#include "Accessors.h"
+
 
 class Plane;
 

+ 51 - 0
src/Collision/LineSegment.cpp

@@ -0,0 +1,51 @@
+#include <algorithm>
+#include "LineSegment.h"
+#include "Plane.h"
+
+
+//======================================================================================================================
+// getTransformed                                                                                                      =
+//======================================================================================================================
+LineSegment LineSegment::getTransformed(const Transform& transform) const
+{
+	LineSegment out;
+	out.origin = origin.getTransformed(transform);
+	out.dir = transform.getRotation() * (dir * transform.getScale());
+	return out;
+}
+
+
+//======================================================================================================================
+// testPlane                                                                                                           =
+//======================================================================================================================
+float LineSegment::testPlane(const Plane& plane) const
+{
+	const Vec3& p0 = origin;
+	Vec3 p1 = origin + dir;
+
+	float dist0 = plane.test(p0);
+	float dist1 = plane.test(p1);
+
+	if(dist0 > 0.0)
+	{
+		if(dist1 > 0.0)
+		{
+			return std::min(dist0, dist1);
+		}
+		else
+		{
+			return 0.0;
+		}
+	}
+	else
+	{
+		if(dist1 < 0.0)
+		{
+			return std::max(dist0, dist1);
+		}
+		else
+		{
+			return 0.0;
+		}
+	}
+}

+ 52 - 0
src/Collision/LineSegment.h

@@ -0,0 +1,52 @@
+#ifndef LINE_SEGMENT_H
+#define LINE_SEGMENT_H
+
+#include "CollisionShape.h"
+#include "Math.h"
+
+
+class LineSegment: public CollisionShape
+{
+	public:
+		/// @name Constructors
+		/// @{
+		LineSegment(): CollisionShape(CST_LINE_SEG) {}
+		LineSegment(const Vec3& origin, const Vec3& direction);
+		LineSegment(const LineSegment& b);
+		/// @}
+
+		/// @name Accessors
+		/// @{
+		GETTER_SETTER(Vec3, origin, getOrigin, setOrigin)
+		GETTER_SETTER(Vec3, dir, getDirection, setDirection)
+		/// @}
+
+		LineSegment getTransformed(const Transform& transform) const;
+
+		/// Implements CollisionShape::testPlane @see CollisionShape::testPlane
+		float testPlane(const Plane& plane) const;
+
+	private:
+		/// @name Data
+		/// @{
+		Vec3 origin; ///< P0
+		Vec3 dir; ///< P1 = origin+dir so dir = P1-origin
+		/// @}
+};
+
+
+inline LineSegment::LineSegment(const Vec3& origin_, const Vec3& direction):
+	CollisionShape(CST_LINE_SEG),
+	origin(origin_),
+	dir(direction)
+{}
+
+
+inline LineSegment::LineSegment(const LineSegment& b):
+	CollisionShape(CST_LINE_SEG),
+	origin(b.origin),
+	dir(b.dir)
+{}
+
+
+#endif

+ 3 - 11
src/Collision/Obb.h

@@ -19,17 +19,9 @@ class Obb: public CollisionShape
 
 		/// @name Accessors
 		/// @{
-		const Vec3& getCenter() const {return center;}
-		Vec3& getCenter() {return center;}
-		void setCenter(const Vec3& c) {center = c;}
-
-		const Mat3& getRotation() const {return rotation;}
-		Mat3& getRotation() {return rotation;}
-		void setCenter(const Mat3& r) {rotation = r;}
-
-		const Vec3& getExtend() const {return extends;}
-		Vec3& getExtend() {return extends;}
-		void setExtend(const Vec3& e) {extends = e;}
+		GETTER_SETTER(Vec3, center, getCenter, setCenter)
+		GETTER_SETTER(Mat3, rotation, getRotation, setRotation)
+		GETTER_SETTER(Vec3, extends, getExtend, setExtend)
 		/// @}
 
 		Obb getTransformed(const Transform& transform) const;

+ 4 - 4
src/Collision/Plane.cpp

@@ -49,16 +49,16 @@ void Plane::setFromPlaneEquation(float a, float b, float c, float d)
 //======================================================================================================================
 // getTransformed                                                                                                      =
 //======================================================================================================================
-Plane Plane::getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const
+Plane Plane::getTransformed(const Transform& trf) const
 {
 	Plane plane;
 
 	// the normal
-	plane.normal = rotate * normal;
+	plane.normal = trf.getRotation()* normal;
 
 	// the offset
-	Vec3 new_trans = rotate.getTransposed() * translate;
-	plane.offset = offset*scale + new_trans.dot(normal);
+	Vec3 newTrans = trf.getRotation().getTransposed() * trf.getOrigin();
+	plane.offset = offset * trf.getScale() + newTrans.dot(normal);
 
 	return plane;
 }

+ 1 - 1
src/Collision/Plane.h

@@ -36,7 +36,7 @@ class Plane: public CollisionShape
 		/// @}
 
 		/// Return the transformed
-		Plane getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const;
+		Plane getTransformed(const Transform& trf) const;
 
 		/// It gives the distance between a point and a plane. if returns >0 then the point lies in front of the plane,
 		/// if <0 then it is behind and if =0 then it is co-planar

+ 1 - 1
src/Core/App.cpp

@@ -214,7 +214,7 @@ void App::initRenderer()
 	initializer.pps.hdr.blurringDist = 1.0;
 	initializer.pps.hdr.blurringIterationsNum = 2;
 	initializer.pps.hdr.exposure = 4.0;
-	initializer.pps.ssao.blurringIterationsNum = 1;
+	initializer.pps.ssao.blurringIterationsNum = 2;
 	initializer.pps.ssao.enabled = true;
 	initializer.pps.ssao.renderingQuality = 0.4;
 	initializer.mainRendererQuality = 1.0;

+ 2 - 1
src/Main.cpp

@@ -123,7 +123,8 @@ void init()
 
 	// camera
 	PerspectiveCamera* cam = new PerspectiveCamera(false, NULL);
-	cam->setAll(toRad(100.0), toRad(100.0) / MainRendererSingleton::getInstance().getAspectRatio(), 0.5, 200.0);
+	//cam->setAll(toRad(100.0), toRad(100.0) / MainRendererSingleton::getInstance().getAspectRatio(), 0.5, 200.0);
+	cam->setAll(MainRendererSingleton::getInstance().getAspectRatio()*toRad(60.0), toRad(60.0), 0.5, 200.0);
 	cam->moveLocalY(3.0);
 	cam->moveLocalZ(5.7);
 	cam->moveLocalX(-0.3);

+ 12 - 1
src/Renderer/Is.cpp

@@ -251,7 +251,18 @@ void Is::spotLightPass(const SpotLight& light)
 	// shadow mapping
 	if(light.castsShadow() && sm.isEnabled())
 	{
-		float dist = (light.getWorldTransform().getOrigin() - cam.getWorldTransform().getOrigin()).getLength();
+		Vec3 zAxis = light.getWorldTransform().getRotation().getColumn(2);
+		LineSegment seg(light.getWorldTransform().getOrigin(),
+		                -zAxis * light.getCamera().getZFar());
+
+		const Plane& plane = cam.getWSpaceFrustumPlane(Camera::FP_NEAR);
+
+		//float dist = (light.getWorldTransform().getOrigin() - cam.getWorldTransform().getOrigin()).getLength();
+		float dist = seg.testPlane(plane);
+		//float dist = plane.test(light.getWorldTransform().getOrigin());
+
+		//INFO(dist);
+
 		sm.run(light.getCamera(), dist);
 
 		// restore the IS FBO

+ 1 - 1
src/Renderer/Sm.cpp

@@ -29,7 +29,7 @@ void Sm::init(const RendererInitializer& initializer)
 	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(levels[i - 1].resolution / 2, levels[i - 1].distance * 2.0, bilinearEnabled, levels[i]);
 	}
 }
 

+ 1 - 1
src/Renderer/Sm.h

@@ -47,7 +47,7 @@ class Sm: private RenderingPass
 			float distance;
 		};
 
-		boost::array<Level, 2> levels; ///< The levels of detail. The 0 is the detailed one
+		boost::array<Level, 4> 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

+ 1 - 1
src/Renderer/Ssao.cpp

@@ -152,7 +152,7 @@ void Ssao::run()
 	ssaoSProg->findUniVar("noiseMapSize")->set(&noiseMapSize);
 
 	// screenSize
-	Vec2 screenSize(width, height);
+	Vec2 screenSize(width * 2, height * 2);
 	ssaoSProg->findUniVar("screenSize")->set(&screenSize);
 
 	// msNormalFai

+ 1 - 3
src/Scene/Cameras/Camera.cpp

@@ -22,9 +22,7 @@ void Camera::updateWSpaceFrustumPlanes()
 {
 	for(uint i = 0; i < FP_NUM; i++)
 	{
-		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].getTransformed(getWorldTransform().getOrigin(),
-		                                                               getWorldTransform().getRotation(),
-		                                                               getWorldTransform().getScale());
+		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].getTransformed(getWorldTransform());
 	}
 }
 

+ 2 - 0
src/Scene/Cameras/Camera.h

@@ -59,6 +59,8 @@ class Camera: public SceneNode
 		GETTER_RW(std::deque<const RenderableNode*>, bsRenderableNodes, getVisibleBsRenderableNodes)
 		GETTER_RW(Vec<const PointLight*>, pointLights, getVisiblePointLights)
 		GETTER_RW(Vec<SpotLight*>, spotLights, getVisibleSpotLights)
+
+		const Plane& getWSpaceFrustumPlane(FrustrumPlanes id) const {return wspaceFrustumPlanes[id];}
 		/// @}
 
 		void lookAtPoint(const Vec3& point);

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff