Browse Source

Reflection tweaks

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
a1e70de115
3 changed files with 38 additions and 37 deletions
  1. 6 0
      shaders/ImageReflections.glsl
  2. 31 37
      src/renderer/Dbg.cpp
  3. 1 0
      testapp/Main.cpp

+ 6 - 0
shaders/ImageReflections.glsl

@@ -10,6 +10,8 @@
 
 
 #pragma anki include "shaders/Clusterer.glsl"
 #pragma anki include "shaders/Clusterer.glsl"
 
 
+#define ACCURATE_RAYS 0
+
 // Representation of a reflection probe
 // Representation of a reflection probe
 struct ReflectionProbe
 struct ReflectionProbe
 {
 {
@@ -48,6 +50,7 @@ layout(TEX_BINDING(IMAGE_REFLECTIONS_SET, IMAGE_REFLECTIONS_TEX_BINDING))
 // the radius squared of the probe (R2) and the frag pos in sphere space (f)
 // the radius squared of the probe (R2) and the frag pos in sphere space (f)
 vec3 computeCubemapVec(in vec3 r, in float R2, in vec3 f)
 vec3 computeCubemapVec(in vec3 r, in float R2, in vec3 f)
 {
 {
+#if ACCURATE_RAYS
 	// Compute the collision of the r to the inner part of the sphere
 	// Compute the collision of the r to the inner part of the sphere
 	// From now on we work on the sphere's space
 	// From now on we work on the sphere's space
 
 
@@ -68,6 +71,9 @@ vec3 computeCubemapVec(in vec3 r, in float R2, in vec3 f)
 	vec3 uv = u_invViewRotation * x;
 	vec3 uv = u_invViewRotation * x;
 
 
 	return uv;
 	return uv;
+#else
+	return u_invViewRotation * r;
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 31 - 37
src/renderer/Dbg.cpp

@@ -160,63 +160,57 @@ Error Dbg::run(CommandBufferPtr& cmdb)
 		Array<Vec3, 4> poly;
 		Array<Vec3, 4> poly;
 		poly[0] = Vec3(0.0, 0.0, 0.0);
 		poly[0] = Vec3(0.0, 0.0, 0.0);
 		poly[1] = Vec3(2.5, 0.0, 0.0);
 		poly[1] = Vec3(2.5, 0.0, 0.0);
-		poly[2] = Vec3(2.0, 4.9, 0.0);
-		poly[3] = Vec3(0.5, 3.9, 0.0);
 
 
-		Mat4 trf(Vec4(1.2, 14.0, 1.1, 1.0), Mat3(Euler(toRad(-120.0), toRad(35.0),
-			toRad(85.0))), 1.0);
+		Mat4 trf(Vec4(147.392776, -12.132728, 16.607138, 1.0),
+			Mat3(Euler(toRad(45.0), toRad(0.0),
+			toRad(120.0))), 1.0);
 
 
 		Array<Vec3, 4> polyw;
 		Array<Vec3, 4> polyw;
 		polyw[0] = trf.transform(poly[0]);
 		polyw[0] = trf.transform(poly[0]);
 		polyw[1] = trf.transform(poly[1]);
 		polyw[1] = trf.transform(poly[1]);
-		polyw[2] = trf.transform(poly[2]);
-		polyw[3] = trf.transform(poly[3]);
 
 
 		m_drawer->setModelMatrix(Mat4::getIdentity());
 		m_drawer->setModelMatrix(Mat4::getIdentity());
 		m_drawer->drawLine(polyw[0], polyw[1], Vec4(1.0));
 		m_drawer->drawLine(polyw[0], polyw[1], Vec4(1.0));
-		m_drawer->drawLine(polyw[1], polyw[2], Vec4(0.8));
-		m_drawer->drawLine(polyw[2], polyw[3], Vec4(0.6));
-		m_drawer->drawLine(polyw[3], polyw[0], Vec4(0.4));
 
 
 
 
+		Vec4 p0 = camFr.getViewMatrix() * polyw[0].xyz1();
+		p0.w() = 0.0;
+		Vec4 p1 = camFr.getViewMatrix() * polyw[1].xyz1();
+		p1.w() = 0.0;
 
 
-		Vec3 edge0 = polyw[2] - polyw[1];
-		Vec3 edge1 = polyw[3] - polyw[2];
+		Vec4 r = p1 - p0;
+		r.normalize();
 
 
-		Vec3 xAxis = edge0;
-		xAxis.normalize();
-		Vec3 zAxis = edge0.cross(edge1);
-		zAxis.normalize();
-		Vec3 yAxis = zAxis.cross(xAxis);
+		Vec4 a = camFr.getProjectionMatrix() * p0.xyz1();
+		a /= a.w();
 
 
-		Mat3 rot;
-		rot.setColumns(xAxis.xyz(), yAxis.xyz(), zAxis.xyz());
 
 
-		Mat3 invRot = rot.getInverse();
-
-		Array<Vec3, 8> polyl;
-		for(U i = 0; i < 4; ++i)
+		Vec4 i;
+		if(r.z() > 0)
 		{
 		{
-			polyl[i] = invRot * polyw[i];
+			//Plane near(Vec4(0, 0, -1, 0), camFr.getFrustum().getNear() + 0.001);
+			//Bool in = near.intersectRay(p0, r * 100000.0, i);
+			i.z() = -camFr.getFrustum().getNear();
+			F32 t = (i.z() - p0.z()) / r.z();
+			i.x() = p0.x() + t * r.x();
+			i.y() = p0.y() + t * r.y();
+
+			i = camFr.getProjectionMatrix() * i.xyz1();
+			i /= i.w();
 		}
 		}
-
-		m_drawer->drawLine(polyl[0], polyl[1], Vec4(1.0));
-		m_drawer->drawLine(polyl[1], polyl[2], Vec4(0.8));
-		m_drawer->drawLine(polyl[2], polyl[3], Vec4(0.6));
-		m_drawer->drawLine(polyl[3], polyl[0], Vec4(0.4));
-
-
-		for(U i = 4; i < 8; ++i)
+		else
 		{
 		{
-			polyl[i] = polyl[i - 4] + Vec3(0.0, 0.0, 10.0);
+			i = camFr.getProjectionMatrix() * (r * 100000.0).xyz1();
+			i /= i.w();
 		}
 		}
 
 
-		Obb obb;
-		obb.setFromPointCloud(&polyl[0], 8, sizeof(Vec3), sizeof(polyl));
-
-		obb.transform(Transform(Vec4(0.0), Mat3x4(rot), 1.0));
+		/*r *= 0.01;
+		Vec4 b = polyw[0].xyz0() + r;
+		b = camFr.getViewProjectionMatrix() * b.xyz1();
+		Vec4 d = b / b.w();*/
 
 
-		obb.accept(cd);
+		m_drawer->setViewProjectionMatrix(Mat4::getIdentity());
+		m_drawer->drawLine(Vec3(a.xy(), 0.1), Vec3(i.xy(), 0.1), Vec4(1.0, 0, 0, 1));
 	}
 	}
 #endif
 #endif
 
 

+ 1 - 0
testapp/Main.cpp

@@ -516,6 +516,7 @@ Error initSubsystems(int argc, char* argv[])
 	//config.set("ir.clusterSizeZ", 32);
 	//config.set("ir.clusterSizeZ", 32);
 	config.set("sslr.enabled", false);
 	config.set("sslr.enabled", false);
 	config.set("ir.rendererSize", 64);
 	config.set("ir.rendererSize", 64);
+	config.set("ir.clusterSizeZ", 16);
 	config.set("fullscreenDesktopResolution", true);
 	config.set("fullscreenDesktopResolution", true);
 	//config.set("clusterSizeZ", 16);
 	//config.set("clusterSizeZ", 16);
 	config.set("debugContext", false);
 	config.set("debugContext", false);