diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/draw/engines/eevee/shaders/prepass_frag.glsl | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/prepass_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/prepass_frag.glsl | 120 |
1 files changed, 59 insertions, 61 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl index bbc49fea6ba..e7b31b94f81 100644 --- a/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl @@ -2,12 +2,14 @@ #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 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 hash3d(vec3 a) +{ + return hash(vec2(hash(a.xy), a.z)); } uniform float hashAlphaOffset; @@ -15,46 +17,42 @@ uniform float hashAlphaScale = 1.0; /* Roughly in pixel */ 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 / (hashAlphaScale * 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; - - /* Avoids threshold == 0. */ - threshold = clamp(threshold, 1.0e-6, 1.0); - - /* Jitter the threshold for TAA accumulation. */ - return fract(threshold + hashAlphaOffset); + /* Find the discretized derivatives of our coordinates. */ + float max_deriv = max(length(dFdx(co)), length(dFdy(co))); + float pix_scale = 1.0 / (hashAlphaScale * 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; + + /* Avoids threshold == 0. */ + threshold = clamp(threshold, 1.0e-6, 1.0); + + /* Jitter the threshold for TAA accumulation. */ + return fract(threshold + hashAlphaOffset); } #endif @@ -65,24 +63,24 @@ uniform float alphaThreshold; void main() { - /* For now do nothing. - * In the future, output object motion blur. */ + /* For now do nothing. + * In the future, output object motion blur. */ #if defined(USE_ALPHA_HASH) || defined(USE_ALPHA_CLIP) -#define NODETREE_EXEC - - Closure cl = nodetree_exec(); - -#if defined(USE_ALPHA_HASH) - /* Hashed Alpha Testing */ - if (cl.opacity < hashed_alpha_threshold(worldPosition)) { - discard; - } -#elif defined(USE_ALPHA_CLIP) - /* Alpha clip */ - if (cl.opacity <= alphaThreshold) { - discard; - } -#endif +# define NODETREE_EXEC + + Closure cl = nodetree_exec(); + +# if defined(USE_ALPHA_HASH) + /* Hashed Alpha Testing */ + if (cl.opacity < hashed_alpha_threshold(worldPosition)) { + discard; + } +# elif defined(USE_ALPHA_CLIP) + /* Alpha clip */ + if (cl.opacity <= alphaThreshold) { + discard; + } +# endif #endif } |