Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2021-03-10 19:31:37 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-03-10 19:57:09 +0300
commit56bf4f3fb32641483aeb7870f9a6372a2867fbbc (patch)
tree79b7bca0b818fa5ddad4bdc802a1a5065af95113 /source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
parent793335f3e243f7a6f13d3d8a82c2bcb9925784bc (diff)
EEVEE: ScreenSpaceReflections: Add back support for planar reflections
We now have a new buffer to output reflection depth. This buffer is only usefull for non planar SSR but we use it to tag the planar rays. This also touch the raytrace algo for planars to avoid degenerate lines on vert sharp reflections.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl17
1 files changed, 9 insertions, 8 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
index dce50a7051e..e2aad867901 100644
--- a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
@@ -43,12 +43,12 @@ void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray)
ray.direction.zw += bias;
ray.direction -= ray.origin;
- float ray_len_sqr = len_squared(ray.direction.xyz);
/* If the line is degenerate, make it cover at least one pixel
* to not have to handle zero-pixel extent as a special case later */
- if (ray_len_sqr < 0.00001) {
- ray.direction.xy = vec2(0.0, 0.0001);
+ if (len_squared(ray.direction.xy) < 0.00001) {
+ ray.direction.xy = vec2(0.0, 0.01);
}
+ float ray_len_sqr = len_squared(ray.direction.xyz);
/* Make ray.direction cover one pixel. */
bool is_more_vertical = abs(ray.direction.x) < abs(ray.direction.y);
ray.direction /= (is_more_vertical) ? abs(ray.direction.y) : abs(ray.direction.x);
@@ -166,8 +166,6 @@ bool raytrace_planar(Ray ray, RayTraceParameters params, int planar_ref_id, out
}
ScreenSpaceRay ssray = raytrace_screenspace_ray_create(ray);
- /* Avoid no iteration. */
- ssray.max_time = max(ssray.max_time, 1.1);
/* Planar Reflections have X mirrored. */
ssray.origin.x = 1.0 - ssray.origin.x;
@@ -177,9 +175,10 @@ bool raytrace_planar(Ray ray, RayTraceParameters params, int planar_ref_id, out
float depth_sample = get_depth_from_view_z(ray.origin.z);
float delta = depth_sample - ssray.origin.z;
- /* Cross at least one pixel. */
- float t = 1.001, time = 1.001;
- bool hit = false;
+ float t = 0.0, time = 0.0;
+ /* On very sharp reflections, the ray can be perfectly aligned with the view direction
+ * making the tracing useless. Bypass tracing in this case. */
+ bool hit = (ssray.max_time < 1.0);
const float max_steps = 255.0;
for (float iter = 1.0; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
float stride = 1.0 + iter * params.trace_quality;
@@ -205,6 +204,8 @@ bool raytrace_planar(Ray ray, RayTraceParameters params, int planar_ref_id, out
time = mix(prev_time, time, saturate(prev_delta / (prev_delta - delta)));
hit_position = ssray.origin.xyz + ssray.direction.xyz * time;
+ /* Planar Reflections have X mirrored. */
+ hit_position.x = 1.0 - hit_position.x;
return hit;
}