Browse Source

Reflection work

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
0a6f964f4a
2 changed files with 12 additions and 7 deletions
  1. 11 6
      shaders/ImageReflections.glsl
  2. 1 1
      shaders/IsLp.frag.glsl

+ 11 - 6
shaders/ImageReflections.glsl

@@ -120,7 +120,7 @@ bool findCloseProxyIntersection(in vec3 p, in vec3 r, out vec3 c)
 }
 
 //==============================================================================
-void readFromProbes(in vec3 c, out vec3 color)
+void readFromProbes(in vec3 intersection, out vec3 color)
 {
 	// Iterate probes to find the cubemap
 	uint count = u_proxyCountReflectionProbeCountPad3.y;
@@ -129,22 +129,27 @@ void readFromProbes(in vec3 c, out vec3 color)
 		float R2 = u_reflectionProbes[i].positionRadiusSq.w;
 		vec3 center = u_reflectionProbes[i].positionRadiusSq.xyz;
 
-		// Check if posVSpace is inside the sphere
-		vec3 f = c - center;
-		if(dot(f, f) < R2)
+		// Check if the point is inside the sphere
+		vec3 f = intersection - center;
+		float d = dot(f, f);
+		if(d < R2)
 		{
 			// Found something
 			float cubemapIndex = u_reflectionProbes[i].cubemapIndexPad3.x;
 			vec3 probeOrigin = u_reflectionProbes[i].positionRadiusSq.xyz;
 
 			// Cubemap UV in view space
-			vec3 uv = normalize(c - probeOrigin);
+			vec3 uv = normalize(intersection - probeOrigin);
 
 			// Rotate UV to move it to world space
 			uv = u_invViewRotation * uv;
 
 			// Read!
-			color = texture(u_reflectionsTex, vec4(uv, cubemapIndex)).rgb;
+			vec3 c = texture(u_reflectionsTex, vec4(uv, cubemapIndex)).rgb;
+
+			// Combine
+			float factor = d / R2;
+			color = color * factor + c * (1.0 - factor);
 		}
 	}
 }

+ 1 - 1
shaders/IsLp.frag.glsl

@@ -192,7 +192,7 @@ void main()
 		out_color += vec3(1.0, 0.0, 0.0);
 	}
 #if IR == 1
-	out_color = out_color * 0.5 + readReflection(fragPos, normal) *0.5;
+	out_color = out_color * 0.0000 + readReflection(fragPos, normal) *1.0;
 #endif
 #endif
 }