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>2017-07-25 20:03:07 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-07-25 23:07:35 +0300
commit4fd70c99a5a37db00ea26b8e5efa7d351e5e1e2b (patch)
treeae1290d15d970ba72597485f3bde4e043e660aae /source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
parent8c3ecc9651f9b3eaa2eddd659e6299c7f4c0588b (diff)
Eevee: SSR: Add support for planar probes.
This add the possibility to use planar probe informations to create SSR. This has 2 advantages: - Tracing is less expensive since the hit is found much quicker. - We have much less artifact due to missing information. There is still area for improvement.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl33
1 files changed, 26 insertions, 7 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
index 421079c0bfa..b4ccb1ca052 100644
--- a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
@@ -9,9 +9,22 @@
uniform mat4 PixelProjMatrix; /* View > NDC > Texel : maps view coords to texel coord */
uniform vec2 ssrParameters;
+uniform sampler2D depthBuffer;
+uniform sampler2DArray planarDepth;
+
#define ssrStride ssrParameters.x
#define ssrThickness ssrParameters.y
+float sample_depth(ivec2 hitpixel, int index)
+{
+ if (index > -1) {
+ return texelFetch(planarDepth, ivec3(hitpixel, index), 0).r;
+ }
+ else {
+ return texelFetch(depthBuffer, hitpixel, 0).r;
+ }
+}
+
void swapIfBigger(inout float a, inout float b)
{
if (a > b) {
@@ -22,7 +35,7 @@ void swapIfBigger(inout float a, inout float b)
}
/* Return the length of the ray if there is a hit, and negate it if not hit occured */
-float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_jitter)
+float raycast(int index, vec3 ray_origin, vec3 ray_dir, float ray_jitter)
{
float near = get_view_z_from_depth(0.0); /* TODO optimize */
float far = get_view_z_from_depth(1.0); /* TODO optimize */
@@ -60,7 +73,7 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
/* 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 */
- P1 += vec2((distance_squared(P0, P1) < 0.0001) ? 0.01 : 0.0);
+ P1 += vec2((distance_squared(P0, P1) < 0.001) ? 0.01 : 0.0);
vec2 delta = P1 - P0;
@@ -101,10 +114,16 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
float end = P1.x * step_sign;
/* Initial offset */
- pqk += dPQK * (0.01 + ray_jitter);
+ if (index > -1) {
+ pqk -= dPQK * ray_jitter;
+ }
+ else {
+ pqk += dPQK * (0.01 + ray_jitter);
+ }
bool hit = false;
float raw_depth;
+ float thickness = (index == -1) ? ssrThickness : 1e16;
for (float hitstep = 0.0; hitstep < MAX_STEP && !hit; hitstep++) {
/* Ray finished & no hit*/
if ((pqk.x * step_sign) > end) break;
@@ -113,7 +132,7 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
pqk += dPQK;
ivec2 hitpixel = ivec2(permute ? pqk.yx : pqk.xy);
- raw_depth = texelFetch(depth_texture, ivec2(hitpixel), 0).r;
+ raw_depth = sample_depth(hitpixel, index);
float zmin = prev_zmax;
zmax = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);
@@ -121,7 +140,7 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
swapIfBigger(zmin, zmax);
float vmax = get_view_z_from_depth(raw_depth);
- float vmin = vmax - ssrThickness;
+ float vmin = vmax - thickness;
/* Check if we are somewhere near the surface. */
/* Note: we consider hitting the screen borders (raw_depth == 0.0)
@@ -146,7 +165,7 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
pqk += dPQK;
ivec2 hitpixel = ivec2(permute ? pqk.yx : pqk.xy);
- raw_depth = texelFetch(depth_texture, hitpixel, 0).r;
+ raw_depth = sample_depth(hitpixel, index);
float zmin = prev_zmax;
zmax = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w);
@@ -154,7 +173,7 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_
swapIfBigger(zmin, zmax);
float vmax = get_view_z_from_depth(raw_depth);
- float vmin = vmax - ssrThickness;
+ float vmin = vmax - thickness;
/* Check if we are somewhere near the surface. */
if (!((zmin > vmax) || (zmax < vmin)) || (raw_depth == 0.0)) {