소스 검색

- Fixing a bug in MeshData
- Adding a new dir containing engine only resources
- Removing hardcoded geometries from SMO
- WIP in OrthographicCamera

Panagiotis Christopoulos Charitos 14 년 전
부모
커밋
5e8157c04f

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 1
build/debug/Makefile


BIN
engine-rsrc/cube.mesh


BIN
engine-rsrc/dummy.norm.png


BIN
engine-rsrc/dummy.png


BIN
engine-rsrc/pyramid.blend


BIN
engine-rsrc/pyramid.blend1


BIN
engine-rsrc/pyramid.mesh


BIN
engine-rsrc/shpere.blend


BIN
engine-rsrc/shpere.blend1


BIN
engine-rsrc/sphere.mesh


+ 2 - 2
shaders/IsLpGeneric.glsl

@@ -240,12 +240,12 @@ void main()
 
 
 	/*#if defined(POINT_LIGHT_ENABLED)
-		gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + vec4(1, 0, 1, 1);
+		fColor = fColor - fColor + vec3(1, 0, 1);
 	#endif*/
 	
 	//gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + vec4(1, 0, 1, 1);
 	/*#if defined(SPOT_LIGHT_ENABLED)
-	gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + vec4(texture2D(msDepthFai, vTexCoords).r);
+	fColor = fColor - fColor + vec3(1, 0, 1);
 	//gl_FragData[0] = vec4(texture2D(msDepthFai, vTexCoords).rg), 1.0);
 	#endif*/
 }

+ 1 - 1
shaders/MsMpGeneric.glsl

@@ -147,7 +147,7 @@ layout(location = 2) out vec4 fMsSpecularFai;
 	/// @param[in] tangent Extra stuff for the tangent
 	/// @param[in] map The map
 	/// @param[in] texCoords Texture coordinates
-	vec3 getNormal(in vec3 normal, in vec3 tangent, in vec3 tangentW, in sampler2D map, in vec2 texCoords)
+	vec3 getNormal(in vec3 normal, in vec3 tangent, in float tangentW, in sampler2D map, in vec2 texCoords)
 	{	
 			vec3 n = normalize(normal);
 			vec3 t = normalize(tangent);

+ 2 - 2
src/Renderer/BufferObjects/Vao.cpp

@@ -6,7 +6,7 @@
 // attachArrayBufferVbo                                                                                                =
 //======================================================================================================================
 void Vao::attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation, GLint size, GLenum type,
-		                           GLboolean normalized, GLsizei stride, const GLvoid* pointer)
+		                       GLboolean normalized, GLsizei stride, const GLvoid* pointer)
 {
 	ASSERT(isCreated());
 	if(vbo.getBufferTarget() != GL_ARRAY_BUFFER)
@@ -31,7 +31,7 @@ void Vao::attachArrayBufferVbo(const Vbo& vbo, uint attribVarLocation, GLint siz
 // attachArrayBufferVbo                                                                                                =
 //======================================================================================================================
 void Vao::attachArrayBufferVbo(const Vbo& vbo, const SProgAttribVar& attribVar, GLint size, GLenum type,
-		                           GLboolean normalized, GLsizei stride, const GLvoid* pointer)
+		                       GLboolean normalized, GLsizei stride, const GLvoid* pointer)
 {
 	attachArrayBufferVbo(vbo, attribVar.getLoc(), size, type, normalized, stride, pointer);
 }

+ 0 - 34
src/Renderer/Renderer.cpp

@@ -110,37 +110,3 @@ Vec3 Renderer::unproject(const Vec3& windowCoords, const Mat4& modelViewMat, con
 	return Vec3(final);
 }
 
-
-//======================================================================================================================
-// ortho                                                                                                               =
-//======================================================================================================================
-Mat4 Renderer::ortho(float left, float right, float bottom, float top, float near, float far)
-{
-	float difx = right - left;
-	float dify = top - bottom;
-	float difz = far - near;
-	float tx = -(right + left) / difx;
-	float ty = -(top + bottom) / dify;
-	float tz = -(far + near) / difz;
-	Mat4 m;
-
-	m(0, 0) = 2.0 / difx;
-	m(0, 1) = 0.0;
-	m(0, 2) = 0.0;
-	m(0, 3) = tx;
-	m(1, 0) = 0.0;
-	m(1, 1) = 2.0 / dify;
-	m(1, 2) = 0.0;
-	m(1, 3) = ty;
-	m(2, 0) = 0.0;
-	m(2, 1) = 0.0;
-	m(2, 2) = -2.0 / difz;
-	m(2, 3) = tz;
-	m(3, 0) = 0.0;
-	m(3, 1) = 0.0;
-	m(3, 2) = 0.0;
-	m(3, 3) = 1.0;
-
-	return m;
-}
-

+ 0 - 10
src/Renderer/Renderer.h

@@ -74,16 +74,6 @@ class Renderer
 		static Vec3 unproject(const Vec3& windowCoords, const Mat4& modelViewMat, const Mat4& projectionMat,
 		                      const int view[4]);
 
-		/// It returns an orthographic projection matrix
-		/// @param left left vertical clipping plane
-		/// @param right right vertical clipping plane
-		/// @param bottom bottom horizontal clipping plane
-		/// @param top top horizontal clipping plane
-		/// @param near nearer distance of depth clipping plane
-		/// @param far farther distance of depth clipping plane
-		/// @return A 4x4 projection matrix
-		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);}
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 4
src/Renderer/Smo.cpp


+ 9 - 16
src/Renderer/Smo.h

@@ -24,25 +24,18 @@ class Smo: public RenderingPass
 		void run(const SpotLight& light);
 
 	private:
-		/// @name UV sphere stuff
-		/// @{
-		static float sMOUvSCoords[]; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
-		Vbo spherePositionsVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
-		Vao sphereVao; ///< And a VAO
-		/// @}
-
-		/// @name Camera shape stuff
-		/// @{
-
-		struct CameraGeom
+		/// @todo
+		struct Geom
 		{
-			Vbo positionsVbo; ///< A camera shape
-			Vbo vertIndecesVbo; ///< The vertex indeces
-			Vao vao; ///< And another VAO
+			RsrcPtr<Mesh> mesh;
+			Vao vao;
 		};
 
-		boost::array<CameraGeom, Camera::CT_NUM> camGeom;
-		/// @}
+		Geom sphereGeom;
+
+		/// An array of geometry stuff. For perspective cameras the shape is a pyramid, see the blend file with the
+		/// vertex positions
+		boost::array<Geom, Camera::CT_NUM> camGeom;
 
 		RsrcPtr<ShaderProg> sProg;
 

+ 1 - 1
src/Resources/Mesh/Mesh.cpp

@@ -21,7 +21,7 @@ void Mesh::load(const char* filename)
 		// Sanity checks
 		//
 		if(meshData.getVertIndeces().size() < 1 || meshData.getVertCoords().size() < 1 ||
-			 meshData.getVertNormals().size() < 1 || meshData.getVertTangents().size() < 1)
+		   meshData.getVertNormals().size() < 1)
 		{
 			throw EXCEPTION("Empty one of the required vectors");
 		}

+ 6 - 3
src/Resources/Mesh/MeshData.cpp

@@ -148,7 +148,10 @@ void MeshData::doPostLoad()
 	}
 
 	createAllNormals();
-	createVertTangents();
+	if(texCoords.size() > 0)
+	{
+		createVertTangents();
+	}
 	createVertIndeces();
 }
 
@@ -225,7 +228,7 @@ void MeshData::createVertTangents()
 	vertTangents.resize(vertCoords.size(), Vec4(0.0)); // alloc
 	Vec<Vec3> bitagents(vertCoords.size(), Vec3(0.0));
 
-	for(uint i=0; i<tris.size(); i++)
+	for(uint i = 0; i < tris.size(); i++)
 	{
 		const Triangle& tri = tris[i];
 		const int i0 = tri.vertIds[0];
@@ -265,7 +268,7 @@ void MeshData::createVertTangents()
 		bitagents[i2] += b;
 	}
 
-	for(uint i=0; i<vertTangents.size(); i++)
+	for(uint i = 0; i < vertTangents.size(); i++)
 	{
 		Vec3 t = Vec3(vertTangents[i]);
 		const Vec3& n = vertNormals[i];

+ 65 - 2
src/Scene/Cameras/OrthographicCamera.cpp

@@ -8,8 +8,71 @@ void OrthographicCamera::calcLSpaceFrustumPlanes()
 {
 	lspaceFrustumPlanes[FP_LEFT] = Plane(Vec3(1.0, 0.0, 0.0), left);
 	lspaceFrustumPlanes[FP_RIGHT] = Plane(Vec3(-1.0, 0.0, 0.0), -right);
-	lspaceFrustumPlanes[FP_NEAR] = Plane(Vec3(0.0, 0.0, -1.0), znear);
-	lspaceFrustumPlanes[FP_FAR] = Plane(Vec3(0.0, 0.0, 1.0), -zfar);
+	lspaceFrustumPlanes[FP_NEAR] = Plane(Vec3(0.0, 0.0, -1.0), zNear);
+	lspaceFrustumPlanes[FP_FAR] = Plane(Vec3(0.0, 0.0, 1.0), -zFar);
 	lspaceFrustumPlanes[FP_TOP] = Plane(Vec3(0.0, -1.0, 0.0), -top);
 	lspaceFrustumPlanes[FP_BOTTOM] = Plane(Vec3(0.0, 1.0, 0.0), bottom);
 }
+
+
+//======================================================================================================================
+// ortho                                                                                                               =
+//======================================================================================================================
+Mat4 OrthographicCamera::ortho(float left, float right, float bottom, float top, float near, float far)
+{
+	float difx = right - left;
+	float dify = top - bottom;
+	float difz = far - near;
+	float tx = -(right + left) / difx;
+	float ty = -(top + bottom) / dify;
+	float tz = -(far + near) / difz;
+	Mat4 m;
+
+	m(0, 0) = 2.0 / difx;
+	m(0, 1) = 0.0;
+	m(0, 2) = 0.0;
+	m(0, 3) = tx;
+	m(1, 0) = 0.0;
+	m(1, 1) = 2.0 / dify;
+	m(1, 2) = 0.0;
+	m(1, 3) = ty;
+	m(2, 0) = 0.0;
+	m(2, 1) = 0.0;
+	m(2, 2) = -2.0 / difz;
+	m(2, 3) = tz;
+	m(3, 0) = 0.0;
+	m(3, 1) = 0.0;
+	m(3, 2) = 0.0;
+	m(3, 3) = 1.0;
+
+	return m;
+}
+
+
+//======================================================================================================================
+// calcProjectionMatrix                                                                                                =
+//======================================================================================================================
+void OrthographicCamera::calcProjectionMatrix()
+{
+	projectionMat = ortho(left, right, bottom, top, zNear, zFar);
+	invProjectionMat = projectionMat.getInverse();
+}
+
+
+//======================================================================================================================
+// getExtremePoints                                                                                                    =
+//======================================================================================================================
+void OrthographicCamera::getExtremePoints(Vec3* pointsArr, uint& pointsNum) const
+{
+	pointsArr[0] = Vec3(right, top, -zNear);
+	pointsArr[1] = Vec3(left, top, -zNear);
+	pointsArr[2] = Vec3(left, bottom, -zNear);
+	pointsArr[3] = Vec3(right, bottom, -zNear);
+	pointsArr[4] = Vec3(right, top, -zFar);
+	pointsArr[5] = Vec3(left, top, -zFar);
+	pointsArr[6] = Vec3(left, bottom, -zFar);
+	pointsArr[7] = Vec3(right, bottom, -zFar);
+
+	pointsNum = 8;
+}
+

+ 10 - 0
src/Scene/Cameras/OrthographicCamera.h

@@ -27,6 +27,16 @@ class OrthographicCamera: public Camera
 
 		void setAll(float left, float right, float top, float bottom, float znear, float zfar);
 
+		/// It returns an orthographic projection matrix
+		/// @param left left vertical clipping plane
+		/// @param right right vertical clipping plane
+		/// @param bottom bottom horizontal clipping plane
+		/// @param top top horizontal clipping plane
+		/// @param near nearer distance of depth clipping plane
+		/// @param far farther distance of depth clipping plane
+		/// @return A 4x4 projection matrix
+		static Mat4 ortho(float left, float right, float bottom, float top, float near, float far);
+
 	private:
 		/// @name Data
 		/// @{

+ 95 - 0
src/Scene/Cameras/PerspectiveCamera.cpp

@@ -0,0 +1,95 @@
+#include "PerspectiveCamera.h"
+
+
+//======================================================================================================================
+// setAll                                                                                                              =
+//======================================================================================================================
+void PerspectiveCamera::setAll(float fovx_, float fovy_, float znear_, float zfar_)
+{
+	fovX = fovx_;
+	fovY = fovy_;
+	zNear = znear_;
+	zFar = zfar_;
+	calcProjectionMatrix();
+	calcLSpaceFrustumPlanes();
+}
+
+
+//======================================================================================================================
+// calcProjectionMatrix                                                                                                =
+//======================================================================================================================
+void PerspectiveCamera::calcProjectionMatrix()
+{
+	float f = 1.0 / tan(fovY * 0.5); // f = cot(fovY/2)
+
+	projectionMat(0, 0) = f * fovY / fovX; // = f/aspectRatio;
+	projectionMat(0, 1) = 0.0;
+	projectionMat(0, 2) = 0.0;
+	projectionMat(0, 3) = 0.0;
+	projectionMat(1, 0) = 0.0;
+	projectionMat(1, 1) = f;
+	projectionMat(1, 2) = 0.0;
+	projectionMat(1, 3) = 0.0;
+	projectionMat(2, 0) = 0.0;
+	projectionMat(2, 1) = 0.0;
+	projectionMat(2, 2) = (zFar + zNear) / ( zNear - zFar);
+	projectionMat(2, 3) = (2.0 * zFar * zNear) / (zNear - zFar);
+	projectionMat(3, 0) = 0.0;
+	projectionMat(3, 1) = 0.0;
+	projectionMat(3, 2) = -1.0;
+	projectionMat(3, 3) = 0.0;
+
+	invProjectionMat = projectionMat.getInverse();
+}
+
+
+//======================================================================================================================
+// calcLSpaceFrustumPlanes                                                                                             =
+//======================================================================================================================
+void PerspectiveCamera::calcLSpaceFrustumPlanes()
+{
+	float c, s; // cos & sine
+
+	sinCos(PI + fovX / 2, s, c);
+	// right
+	lspaceFrustumPlanes[FP_RIGHT] = Plane(Vec3(c, 0.0, s), 0.0);
+	// left
+	lspaceFrustumPlanes[FP_LEFT] = Plane(Vec3(-c, 0.0, s), 0.0);
+
+	sinCos((3 * PI - fovY) * 0.5, s, c);
+	// top
+	lspaceFrustumPlanes[FP_TOP] = Plane(Vec3(0.0, s, c), 0.0);
+	// bottom
+	lspaceFrustumPlanes[FP_BOTTOM] = Plane(Vec3(0.0, -s, c), 0.0);
+
+	// near
+	lspaceFrustumPlanes[FP_NEAR] = Plane(Vec3(0.0, 0.0, -1.0), zNear);
+	// far
+	lspaceFrustumPlanes[FP_FAR] = Plane(Vec3(0.0, 0.0, 1.0), -zFar);
+}
+
+
+//======================================================================================================================
+// getExtremePoints                                                                                                    =
+//======================================================================================================================
+void PerspectiveCamera::getExtremePoints(Vec3* points, uint& pointsNum) const
+{
+	float x = getZFar() / tan((PI - getFovX()) / 2.0);
+	float y = tan(getFovY() / 2.0) * getZFar();
+	float z = -getZFar();
+
+	// the actual points in local space
+	points[0] = Vec3(x, y, z); // top right
+	points[1] = Vec3(-x, y, z); // top left
+	points[2] = Vec3(-x, -y, z); // bottom left
+	points[3] = Vec3(x, -y, z); // bottom right
+	points[4] = getWorldTransform().getOrigin(); // eye (already in world space)
+
+	// transform them to the given camera's world space (exept the eye)
+	for(uint i = 0; i < 4; i++)
+	{
+		points[i].transform(getWorldTransform());
+	}
+
+	pointsNum = 5;
+}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.