EEVEE: ScreenSpaceReflections: Jitter starting texel

This make sure the rays are generated randomly from a fullres
texel center.

This creates more noise but increase the convergence when doing
half res tracing.
This commit is contained in:
Clément Foucault 2021-03-12 21:42:00 +01:00
parent ff07a4afb8
commit bbc5e26051
2 changed files with 18 additions and 2 deletions

View File

@ -130,6 +130,9 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
struct GPUShader *trace_shader = EEVEE_shaders_effect_reflection_trace_sh_get();
struct GPUShader *resolve_shader = EEVEE_shaders_effect_reflection_resolve_sh_get();
int hitbuf_size[3];
GPU_texture_get_mipmap_size(effects->ssr_hit_output, 0, hitbuf_size);
/** Screen space raytracing overview
*
* Following Frostbite stochastic SSR.
@ -155,6 +158,9 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
DRW_shgroup_uniform_vec2_copy(grp, "targetSize", (float[2]){hitbuf_size[0], hitbuf_size[1]});
DRW_shgroup_uniform_float_copy(
grp, "randomScale", effects->reflection_trace_full ? 0.0f : 0.5f);
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
eGPUSamplerState no_filter = GPU_SAMPLER_DEFAULT;

View File

@ -19,6 +19,8 @@
uniform sampler2D normalBuffer;
uniform sampler2D specroughBuffer;
uniform vec2 targetSize;
uniform float randomScale;
in vec4 uvcoordsvar;
@ -27,7 +29,16 @@ layout(location = 1) out float hitDepth;
void main()
{
vec2 uvs = uvcoordsvar.xy;
vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy);
/* Decorrelate from AA. */
/* TODO(fclem) we should use a more general approach for more random number dimensions. */
vec2 random_px = floor(fract(rand.xy * 2.2074408460575947536) * 1.99999) - 0.5;
rand.xy = fract(rand.xy * 3.2471795724474602596);
/* Randomly choose the pixel to start the ray from when tracing at lower resolution.
* This method also make sure we always start from the center of a fullres texel. */
vec2 uvs = (gl_FragCoord.xy + random_px * randomScale) / (targetSize * ssrUvScale);
float depth = textureLod(maxzBuffer, uvs * hizUvScale.xy, 0.0).r;
HitData data;
@ -88,7 +99,6 @@ void main()
}
}
vec4 rand = texelfetch_noise_tex(vec2(gl_FragCoord.xy));
/* Gives *perfect* reflection for very small roughness */
if (roughness < 0.04) {
rand.xzw *= 0.0;