Eevee: SSR: Enhance the halfres raytrace.

This make the halfres raytrace actually converge to an antialiased image by jittering the source pixel.
This commit is contained in:
Clément Foucault 2018-01-16 13:18:04 +01:00
parent 2221cdb517
commit 9365e966b4
3 changed files with 25 additions and 5 deletions

View File

@ -498,6 +498,7 @@ typedef struct EEVEE_EffectsInfo {
bool reflection_trace_full;
bool ssr_use_normalization;
int ssr_neighbor_ofs;
int ssr_halfres_ofs[2];
float ssr_firefly_fac;
float ssr_border_fac;
float ssr_max_roughness;

View File

@ -223,6 +223,9 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
DRW_shgroup_uniform_float(grp, "maxRoughness", &effects->ssr_max_roughness, 1);
DRW_shgroup_uniform_buffer(grp, "planarDepth", &vedata->txl->planar_depth);
DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
if (!effects->reflection_trace_full) {
DRW_shgroup_uniform_ivec2(grp, "halfresOffset", effects->ssr_halfres_ofs, 1);
}
DRW_shgroup_call_add(grp, quad, NULL);
psl->ssr_resolve = DRW_pass_create("SSR Resolve", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE);
@ -310,6 +313,24 @@ void EEVEE_reflection_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v
/* Doing a neighbor shift only after a few iteration. We wait for a prime number of cycles to avoid
* noise correlation. This reduces variance faster. */
effects->ssr_neighbor_ofs = ((sample / 5) % 8) * 4;
switch ((sample / 11) % 4) {
case 0:
effects->ssr_halfres_ofs[0] = 0;
effects->ssr_halfres_ofs[1] = 0;
break;
case 1:
effects->ssr_halfres_ofs[0] = 0;
effects->ssr_halfres_ofs[1] = 1;
break;
case 2:
effects->ssr_halfres_ofs[0] = 1;
effects->ssr_halfres_ofs[1] = 0;
break;
case 4:
effects->ssr_halfres_ofs[0] = 1;
effects->ssr_halfres_ofs[1] = 1;
break;
}
DRW_framebuffer_texture_detach(dtxl->depth);
DRW_framebuffer_texture_detach(txl->ssr_normal_input);
DRW_framebuffer_texture_detach(txl->ssr_specrough_input);

View File

@ -12,6 +12,7 @@ uniform sampler2DArray utilTex;
uniform float fireflyFactor;
uniform float maxRoughness;
uniform ivec2 halfresOffset;
ivec2 encode_hit_data(vec2 hit_pos, bool has_hit, bool is_planar)
{
@ -97,7 +98,7 @@ void main()
ivec2 fullres_texel = ivec2(gl_FragCoord.xy);
ivec2 halfres_texel = fullres_texel;
#else
ivec2 fullres_texel = ivec2(gl_FragCoord.xy) * 2;
ivec2 fullres_texel = ivec2(gl_FragCoord.xy) * 2 + halfresOffset;
ivec2 halfres_texel = ivec2(gl_FragCoord.xy);
#endif
@ -107,10 +108,7 @@ void main()
if (depth == 1.0)
discard;
vec2 uvs = gl_FragCoord.xy / vec2(textureSize(depthBuffer, 0));
#ifndef FULLRES
uvs *= 2.0;
#endif
vec2 uvs = vec2(fullres_texel) / vec2(textureSize(depthBuffer, 0));
/* Using view space */
vec3 viewPosition = get_view_space_from_depth(uvs, depth);