These are the modifications: -With DRW modification we reduce the number of passes we need to populate. -Rename passes for consistent naming. -Reduce complexity in code compilation -Cleanup how renderpass accumulation passes are setup, using pass instances. -Make sculpt mode compatible with shadows -Make hair passes compatible with SSS -Error shader and lookdev materials now use standalone materials. -Support default shader (world and material) using a default nodetree internally. -Change BLEND_CLIP to be emulated by gpu nodetree. Making less shader variations. -Use BLI_memblock for cache memory allocation. -Renderpasses are handled by switching a UBO ref bind. One major hack in this patch is the use of modified pointer as ghash keys. This rely on the assumption that the keys will never overlap because the number of options per key will never be bigger than the pointed struct. The use of one single nodetree to support default material is also a bit hacky since it won't support concurent usage of this nodetree. (see EEVEE_shader_default_surface_nodetree) Another change is that objects with shader errors now appear solid magenta instead of shaded magenta. This is only because of code reuse purpose but could be changed if really needed. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D7642
77 lines
1.9 KiB
GLSL
77 lines
1.9 KiB
GLSL
|
|
#ifdef USE_ALPHA_HASH
|
|
|
|
/* From the paper "Hashed Alpha Testing" by Chris Wyman and Morgan McGuire */
|
|
float hash(vec2 a)
|
|
{
|
|
return fract(1e4 * sin(17.0 * a.x + 0.1 * a.y) * (0.1 + abs(sin(13.0 * a.y + a.x))));
|
|
}
|
|
|
|
float hash3d(vec3 a)
|
|
{
|
|
return hash(vec2(hash(a.xy), a.z));
|
|
}
|
|
|
|
float hashed_alpha_threshold(vec3 co)
|
|
{
|
|
/* Find the discretized derivatives of our coordinates. */
|
|
float max_deriv = max(length(dFdx(co)), length(dFdy(co)));
|
|
float pix_scale = 1.0 / (alphaHashScale * max_deriv);
|
|
|
|
/* Find two nearest log-discretized noise scales. */
|
|
float pix_scale_log = log2(pix_scale);
|
|
vec2 pix_scales;
|
|
pix_scales.x = exp2(floor(pix_scale_log));
|
|
pix_scales.y = exp2(ceil(pix_scale_log));
|
|
|
|
/* Compute alpha thresholds at our two noise scales. */
|
|
vec2 alpha;
|
|
alpha.x = hash3d(floor(pix_scales.x * co));
|
|
alpha.y = hash3d(floor(pix_scales.y * co));
|
|
|
|
/* Factor to interpolate lerp with. */
|
|
float fac = fract(log2(pix_scale));
|
|
|
|
/* Interpolate alpha threshold from noise at two scales. */
|
|
float x = mix(alpha.x, alpha.y, fac);
|
|
|
|
/* Pass into CDF to compute uniformly distrib threshold. */
|
|
float a = min(fac, 1.0 - fac);
|
|
float one_a = 1.0 - a;
|
|
float denom = 1.0 / (2 * a * one_a);
|
|
float one_x = (1 - x);
|
|
vec3 cases = vec3((x * x) * denom, (x - 0.5 * a) / one_a, 1.0 - (one_x * one_x * denom));
|
|
|
|
/* Find our final, uniformly distributed alpha threshold. */
|
|
float threshold = (x < one_a) ? ((x < a) ? cases.x : cases.y) : cases.z;
|
|
|
|
/* Jitter the threshold for TAA accumulation. */
|
|
threshold = fract(threshold + alphaHashOffset);
|
|
|
|
/* Avoids threshold == 0. */
|
|
threshold = clamp(threshold, 1.0e-6, 1.0);
|
|
|
|
return threshold;
|
|
}
|
|
|
|
#endif
|
|
|
|
#define NODETREE_EXEC
|
|
|
|
void main()
|
|
{
|
|
#if defined(USE_ALPHA_HASH)
|
|
|
|
Closure cl = nodetree_exec();
|
|
|
|
float opacity = saturate(1.0 - avg(cl.transmittance));
|
|
|
|
# if defined(USE_ALPHA_HASH)
|
|
/* Hashed Alpha Testing */
|
|
if (opacity < hashed_alpha_threshold(worldPosition)) {
|
|
discard;
|
|
}
|
|
# endif
|
|
#endif
|
|
}
|