Eevee: Fix noise correlation in the blue noise update.
This commit is contained in:
parent
39af6c27f5
commit
84c91be0a4
|
@ -168,23 +168,21 @@ static void eevee_draw_background(void *vedata)
|
|||
int loop_ct = DRW_state_is_image_render() ? 4 : 1;
|
||||
|
||||
while (loop_ct--) {
|
||||
unsigned int primes[3] = {2, 3, 7};
|
||||
double offset[3] = {0.0, 0.0, 0.0};
|
||||
double r[3];
|
||||
|
||||
/* XXX temp for denoising render. TODO plug number of samples here */
|
||||
if (DRW_state_is_image_render()) {
|
||||
double r;
|
||||
BLI_halton_1D(2, 0.0, stl->effects->taa_current_sample - 1, &r);
|
||||
|
||||
BLI_halton_3D(primes, offset, stl->effects->taa_current_sample, r);
|
||||
/* Set jitter offset */
|
||||
/* PERF This is killing perf ! */
|
||||
EEVEE_update_util_texture((float)r);
|
||||
EEVEE_update_util_texture(r);
|
||||
}
|
||||
else if (((stl->effects->enabled_effects & EFFECT_TAA) != 0) && (stl->effects->taa_current_sample > 1)) {
|
||||
double r;
|
||||
BLI_halton_1D(2, 0.0, stl->effects->taa_current_sample - 1, &r);
|
||||
|
||||
else if ((stl->effects->enabled_effects & EFFECT_TAA) != 0) {
|
||||
BLI_halton_3D(primes, offset, stl->effects->taa_current_sample, r);
|
||||
/* Set jitter offset */
|
||||
/* PERF This is killing perf ! */
|
||||
EEVEE_update_util_texture((float)r);
|
||||
EEVEE_update_util_texture(r);
|
||||
}
|
||||
|
||||
/* Refresh Probes */
|
||||
|
|
|
@ -432,7 +432,7 @@ static void create_default_shader(int options)
|
|||
MEM_freeN(frag_str);
|
||||
}
|
||||
|
||||
void EEVEE_update_util_texture(float offset)
|
||||
void EEVEE_update_util_texture(double offsets[3])
|
||||
{
|
||||
|
||||
/* TODO: split this into 2 functions : one for init,
|
||||
|
@ -456,12 +456,9 @@ void EEVEE_update_util_texture(float offset)
|
|||
|
||||
/* Copy blue noise in 3rd layer */
|
||||
for (int i = 0; i < 64 * 64; i++) {
|
||||
float noise;
|
||||
noise = fmod(blue_noise[i][0] + offset, 1.0f);
|
||||
texels_layer[i][0] = noise;
|
||||
|
||||
noise = fmod(blue_noise[i][1] + offset, 1.0f);
|
||||
texels_layer[i][1] = noise * 0.5f + 0.5f;
|
||||
texels_layer[i][0] = fmod(blue_noise[i][0] + (float)offsets[0], 1.0f);
|
||||
texels_layer[i][1] = fmod(blue_noise[i][1] + (float)offsets[1], 1.0f);
|
||||
float noise = fmod(blue_noise[i][1] + (float)offsets[2], 1.0f);
|
||||
texels_layer[i][2] = cosf(noise * 2.0f * M_PI);
|
||||
texels_layer[i][3] = sinf(noise * 2.0f * M_PI);
|
||||
}
|
||||
|
@ -549,7 +546,8 @@ void EEVEE_materials_init(EEVEE_StorageList *stl)
|
|||
|
||||
MEM_freeN(frag_str);
|
||||
|
||||
EEVEE_update_util_texture(0.0f);
|
||||
double offsets[3] = {0.0, 0.0, 0.0};
|
||||
EEVEE_update_util_texture(offsets);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -743,7 +743,7 @@ struct GPUMaterial *EEVEE_material_mesh_depth_get(struct Scene *scene, Material
|
|||
struct GPUMaterial *EEVEE_material_hair_get(struct Scene *scene, Material *ma, int shadow_method);
|
||||
void EEVEE_materials_free(void);
|
||||
void EEVEE_draw_default_passes(EEVEE_PassList *psl);
|
||||
void EEVEE_update_util_texture(float offset);
|
||||
void EEVEE_update_util_texture(double offsets[3]);
|
||||
|
||||
/* eevee_lights.c */
|
||||
void EEVEE_lights_init(EEVEE_ViewLayerData *sldata);
|
||||
|
|
|
@ -14,7 +14,6 @@ uniform sampler2DArray utilTex;
|
|||
void setup_noise(void)
|
||||
{
|
||||
jitternoise = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0)).rg; /* Global variable */
|
||||
jitternoise.g = (jitternoise.g - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
#ifdef HAMMERSLEY_SIZE
|
||||
|
|
|
@ -203,14 +203,13 @@ float light_visibility(LightData ld, vec3 W,
|
|||
vec3 T, B;
|
||||
make_orthonormal_basis(L.xyz / L.w, T, B);
|
||||
|
||||
vec3 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0)).xzw;
|
||||
/* XXX This is a hack to not have noise correlation artifacts.
|
||||
* A better solution to have better noise is welcome. */
|
||||
rand.yz *= fast_sqrt(fract(rand.x * 7919.0)) * data.sh_contact_spread;
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
/* WATCH THIS : This still seems to have correlation artifacts for low samples. */
|
||||
rand.zw *= fast_sqrt(rand.y) * data.sh_contact_spread;
|
||||
|
||||
/* We use the full l_vector.xyz so that the spread is minimize
|
||||
* if the shading point is further away from the light source */
|
||||
vec3 ray_dir = L.xyz + T * rand.y + B * rand.z;
|
||||
vec3 ray_dir = L.xyz + T * rand.z + B * rand.w;
|
||||
ray_dir = transform_direction(ViewMatrix, ray_dir);
|
||||
ray_dir = normalize(ray_dir);
|
||||
vec3 ray_origin = viewPosition + viewNormal * data.sh_contact_offset;
|
||||
|
@ -311,14 +310,13 @@ vec3 light_translucent(LightData ld, vec3 W, vec3 N, vec4 l_vector, float scale)
|
|||
vec3 T, B;
|
||||
make_orthonormal_basis(L.xyz / L.w, T, B);
|
||||
|
||||
vec3 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0)).xzw;
|
||||
/* XXX This is a hack to not have noise correlation artifacts.
|
||||
* A better solution to have better noise is welcome. */
|
||||
rand.yz *= fast_sqrt(fract(rand.x * 7919.0)) * data.sh_blur;
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
/* WATCH THIS : This still seems to have correlation artifacts for low samples. */
|
||||
rand.zw *= fast_sqrt(rand.y) * data.sh_blur;
|
||||
|
||||
/* We use the full l_vector.xyz so that the spread is minimize
|
||||
* if the shading point is further away from the light source */
|
||||
W = W + T * rand.y + B * rand.z;
|
||||
W = W + T * rand.z + B * rand.w;
|
||||
|
||||
if (ld.l_type == SUN) {
|
||||
ShadowCascadeData scd = shadows_cascade_data[int(data.sh_data_start)];
|
||||
|
|
|
@ -402,7 +402,7 @@ void CLOSURE_NAME(
|
|||
/* ---------------------------- */
|
||||
#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.zw, bent_normal);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue