Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jbakker>2020-02-20 16:53:53 +0300
committerJeroen Bakker <jeroen@blender.org>2020-02-21 13:13:43 +0300
commitbe2bc97eba499c48e3856c8e5ec4d869e28b4d04 (patch)
tree41d8d8fd5ec205e5fa00628aaf0f1603cb5e7825 /source/blender/draw/engines/eevee/shaders
parent1f8f4c8cfeaf02754f3259f9eb811ada0ed3499e (diff)
EEVEE: Render Passes
This patch adds new render passes to EEVEE. These passes include: * Emission * Diffuse Light * Diffuse Color * Glossy Light * Glossy Color * Environment * Volume Scattering * Volume Transmission * Bloom * Shadow With these passes it will be possible to use EEVEE effectively for compositing. During development we kept a close eye on how to get similar results compared to cycles render passes there are some differences that are related to how EEVEE works. For EEVEE we combined the passes to `Diffuse` and `Specular`. There are no transmittance or sss passes anymore. Cycles will be changed accordingly. Cycles volume transmittance is added to multiple surface col passes. For EEVEE we left the volume transmittance as a separate pass. Known Limitations * All materials that use alpha blending will not be rendered in the render passes. Other transparency modes are supported. * More GPU memory is required to store the render passes. When rendering a HD image with all render passes enabled at max extra 570MB GPU memory is required. Implementation Details An overview of render passes have been described in https://wiki.blender.org/wiki/Source/Render/EEVEE/RenderPasses Future Developments * In this implementation the materials are re-rendered for Diffuse/Glossy and Emission passes. We could use multi target rendering to improve the render speed. * Other passes can be added later * Don't render material based passes when only requesting AO or Shadow. * Add more passes to the system. These could include Cryptomatte, AOV's, Vector, ObjectID, MaterialID, UV. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D6331
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl34
-rw-r--r--source/blender/draw/engines/eevee/shaders/default_frag.glsl3
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl7
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl11
-rw-r--r--source/blender/draw/engines/eevee/shaders/lights_lib.glsl42
-rw-r--r--source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl77
-rw-r--r--source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl58
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_accum_frag.glsl11
8 files changed, 198 insertions, 45 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
index c4f815b5dd4..c3518198805 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -85,6 +85,37 @@ struct ShadowCascadeData {
#define sh_shadow_vec shadow_vec_id.xyz
#define sh_tex_index shadow_vec_id.w
+/* ------ Render Passes ----- */
+layout(std140) uniform renderpass_block
+{
+ bool renderPassDiffuse;
+ bool renderPassDiffuseLight;
+ bool renderPassGlossy;
+ bool renderPassGlossyLight;
+ bool renderPassEmit;
+ bool renderPassSSSColor;
+};
+
+vec3 render_pass_diffuse_mask(vec3 diffuse_color, vec3 diffuse_light)
+{
+ return renderPassDiffuse ? (renderPassDiffuseLight ? diffuse_light : diffuse_color) : vec3(0.0);
+}
+
+vec3 render_pass_sss_mask(vec3 sss_color)
+{
+ return renderPassSSSColor ? sss_color : vec3(0.0);
+}
+
+vec3 render_pass_glossy_mask(vec3 specular_color, vec3 specular_light)
+{
+ return renderPassGlossy ? (renderPassGlossyLight ? specular_light : specular_color) : vec3(0.0);
+}
+
+vec3 render_pass_emission_mask(vec3 emission_light)
+{
+ return renderPassEmit ? emission_light : vec3(0.0);
+}
+
/* ------- Convenience functions --------- */
vec3 mul(mat3 m, vec3 v)
@@ -833,11 +864,12 @@ void closure_load_sss_data(
cl.sss_radius = radius;
cl.sss_albedo = sss_albedo;
cl.flag |= CLOSURE_SSS_FLAG;
+ cl.radiance += render_pass_diffuse_mask(sss_albedo, vec3(0));
}
else
# endif
{
- cl.radiance += sss_irradiance * sss_albedo;
+ cl.radiance += render_pass_diffuse_mask(sss_albedo, sss_irradiance * sss_albedo);
}
}
diff --git a/source/blender/draw/engines/eevee/shaders/default_frag.glsl b/source/blender/draw/engines/eevee/shaders/default_frag.glsl
index a031ed193b6..1014b25033a 100644
--- a/source/blender/draw/engines/eevee/shaders/default_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/default_frag.glsl
@@ -34,7 +34,8 @@ Closure nodetree_exec(void)
eevee_closure_default(N, albedo, f0, f90, 1, roughness, 1.0, true, out_diff, out_spec, ssr_spec);
Closure cl = CLOSURE_DEFAULT;
- cl.radiance = out_spec + out_diff * albedo;
+ cl.radiance = render_pass_glossy_mask(vec3(1.0), out_spec) +
+ render_pass_diffuse_mask(albedo, out_diff * albedo);
closure_load_ssr_data(ssr_spec, roughness, N, viewCameraVec, 1, cl);
#ifdef LOOKDEV
diff --git a/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
index 299cb2094c1..18f92c0dd33 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
@@ -40,6 +40,7 @@ uniform float sampleScale;
/* Step Resolve */
uniform vec3 bloomColor;
+uniform bool bloomAddBase;
in vec4 uvcoordsvar;
@@ -201,9 +202,9 @@ vec4 step_resolve(void)
#else
vec3 blur = upsample_filter(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
#endif
- vec4 base = textureLod(baseBuffer, uvcoordsvar.xy, 0.0);
- vec3 cout = base.rgb + blur * bloomColor;
- return vec4(cout, base.a);
+ vec3 base = bloomAddBase ? textureLod(baseBuffer, uvcoordsvar.xy, 0.0).rgb : vec3(0.0);
+ vec3 cout = base + blur * bloomColor;
+ return vec4(cout, 1.0);
}
void main(void)
diff --git a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
index 1241cf0e387..e9da49c9eb9 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
@@ -20,13 +20,7 @@ uniform sampler2DArray utilTex;
# define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
#endif /* UTIL_TEX */
-#ifdef RESULT_ACCUM
-/* Render Passes Accumulation */
-layout(location = 0) out vec4 sssDirect;
-layout(location = 1) out vec4 sssColor;
-#else
layout(location = 0) out vec4 sssRadiance;
-#endif
float get_view_z_from_depth(float depth)
{
@@ -87,10 +81,7 @@ void main(void)
accum += kernel[i].rgb * mix(color, sss_irradiance, s);
}
-#ifdef RESULT_ACCUM
- sssDirect = vec4(accum, 1.0);
- sssColor = vec4(texture(sssAlbedo, uvs).rgb, 1.0);
-#elif defined(FIRST_PASS)
+#if defined(FIRST_PASS)
sssRadiance = vec4(accum, 1.0);
#else /* SECOND_PASS */
sssRadiance = vec4(accum * texture(sssAlbedo, uvs).rgb, 1.0);
diff --git a/source/blender/draw/engines/eevee/shaders/lights_lib.glsl b/source/blender/draw/engines/eevee/shaders/lights_lib.glsl
index 6427f02ed25..3b9d0a8f2bc 100644
--- a/source/blender/draw/engines/eevee/shaders/lights_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lights_lib.glsl
@@ -173,19 +173,17 @@ float light_attenuation(LightData ld, vec4 l_vector)
return vis;
}
-float light_visibility(LightData ld,
- vec3 W,
+float light_shadowing(LightData ld,
+ vec3 W,
#ifndef VOLUMETRICS
- vec3 viewPosition,
- float tracing_depth,
- vec3 true_normal,
- float rand_x,
- const bool use_contact_shadows,
+ vec3 viewPosition,
+ float tracing_depth,
+ vec3 true_normal,
+ float rand_x,
+ const bool use_contact_shadows,
#endif
- vec4 l_vector)
+ float vis)
{
- float vis = light_attenuation(ld, l_vector);
-
#if !defined(VOLUMETRICS) || defined(VOLUME_SHADOW)
/* shadowing */
if (ld.l_shadowid >= 0.0 && vis > 0.001) {
@@ -236,6 +234,30 @@ float light_visibility(LightData ld,
return vis;
}
+float light_visibility(LightData ld,
+ vec3 W,
+#ifndef VOLUMETRICS
+ vec3 viewPosition,
+ float tracing_depth,
+ vec3 true_normal,
+ float rand_x,
+ const bool use_contact_shadows,
+#endif
+ vec4 l_vector)
+{
+ float l_atten = light_attenuation(ld, l_vector);
+ return light_shadowing(ld,
+ W,
+#ifndef VOLUMETRICS
+ viewPosition,
+ tracing_depth,
+ true_normal,
+ rand_x,
+ use_contact_shadows,
+#endif
+ l_atten);
+}
+
#ifdef USE_LTC
float light_diffuse(LightData ld, vec3 N, vec3 V, vec4 l_vector)
{
diff --git a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl
index 35bfb411cb9..5214301bc03 100644
--- a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl
@@ -1,15 +1,17 @@
-#define SCE_PASS_Z (1 << 1)
-#define SCE_PASS_AO (1 << 6)
-#define SCE_PASS_NORMAL (1 << 8)
-#define SCE_PASS_MIST (1 << 14)
-#define SCE_PASS_SUBSURFACE_DIRECT (1 << 28)
-#define SCE_PASS_SUBSURFACE_COLOR (1 << 30)
+#define PASS_POST_UNDEFINED 0
+#define PASS_POST_ACCUMULATED_COLOR 1
+#define PASS_POST_ACCUMULATED_LIGHT 2
+#define PASS_POST_ACCUMULATED_VALUE 3
+#define PASS_POST_DEPTH 4
+#define PASS_POST_AO 5
+#define PASS_POST_NORMAL 6
+#define PASS_POST_TWO_LIGHT_BUFFERS 7
-#define ACCUMULATED_COLOR_PASSES (SCE_PASS_SUBSURFACE_DIRECT | SCE_PASS_SUBSURFACE_COLOR)
-#define ACCUMULATED_VALUE_PASSES (SCE_PASS_MIST)
-uniform int renderpassType;
+uniform int postProcessType;
uniform int currentSample;
uniform sampler2D inputBuffer;
+uniform sampler2D inputSecondLightBuffer;
+uniform sampler2D inputColorBuffer;
out vec4 fragColor;
@@ -17,7 +19,7 @@ void main()
{
ivec2 texel = ivec2(gl_FragCoord.xy);
- if (renderpassType == SCE_PASS_Z) {
+ if (postProcessType == PASS_POST_DEPTH) {
float depth = texelFetch(depthBuffer, texel, 0).r;
if (depth == 1.0f) {
depth = 1e10;
@@ -27,17 +29,15 @@ void main()
}
fragColor.r = depth;
}
-
- else if (renderpassType == SCE_PASS_AO) {
+ else if (postProcessType == PASS_POST_AO) {
float ao_accum = texelFetch(inputBuffer, texel, 0).r;
fragColor = vec4(vec3(min(1.0, ao_accum / currentSample)), 1.0);
}
-
- else if (renderpassType == SCE_PASS_NORMAL) {
+ else if (postProcessType == PASS_POST_NORMAL) {
float depth = texelFetch(depthBuffer, texel, 0).r;
vec2 encoded_normal = texelFetch(inputBuffer, texel, 0).rg;
- /* decode the normals only when they are valid. otherwise the result buffer will be filled with
- * NaN's */
+ /* decode the normals only when they are valid. otherwise the result buffer will be filled
+ * with NaN's */
if (depth != 1.0 && any(notEqual(encoded_normal, vec2(0.0)))) {
vec3 decoded_normal = normal_decode(texelFetch(inputBuffer, texel, 0).rg, vec3(0.0));
vec3 world_normal = mat3(ViewMatrixInverse) * decoded_normal;
@@ -47,18 +47,55 @@ void main()
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
}
-
- else if ((renderpassType & ACCUMULATED_VALUE_PASSES) != 0) {
+ else if (postProcessType == PASS_POST_ACCUMULATED_VALUE) {
float accumulated_value = texelFetch(inputBuffer, texel, 0).r;
fragColor = vec4(vec3(accumulated_value / currentSample), 1.0);
}
-
- else if ((renderpassType & ACCUMULATED_COLOR_PASSES) != 0) {
+ else if (postProcessType == PASS_POST_ACCUMULATED_COLOR) {
vec3 accumulated_color = texelFetch(inputBuffer, texel, 0).rgb;
fragColor = vec4(accumulated_color / currentSample, 1.0);
}
+ else if (postProcessType == PASS_POST_ACCUMULATED_LIGHT) {
+ vec3 accumulated_light = texelFetch(inputBuffer, texel, 0).rgb;
+ vec3 accumulated_color = texelFetch(inputColorBuffer, texel, 0).rgb;
+ /* Fix INF in the case a color component is 0.0 */
+ if (accumulated_color.r == 0.0) {
+ accumulated_color.r = 1.0;
+ accumulated_light.r = 0.0;
+ }
+ if (accumulated_color.g == 0.0) {
+ accumulated_color.g = 1.0;
+ accumulated_light.g = 0.0;
+ }
+ if (accumulated_color.b == 0.0) {
+ accumulated_color.b = 1.0;
+ accumulated_light.b = 0.0;
+ }
+ fragColor = vec4(accumulated_light / accumulated_color, 1.0);
+ }
+ else if (postProcessType == PASS_POST_TWO_LIGHT_BUFFERS) {
+ vec3 accumulated_light = texelFetch(inputBuffer, texel, 0).rgb +
+ texelFetch(inputSecondLightBuffer, texel, 0).rgb;
+ vec3 accumulated_color = texelFetch(inputColorBuffer, texel, 0).rgb;
+
+ /* Fix INF in the case a color component is 0.0 */
+ if (accumulated_color.r == 0.0) {
+ accumulated_color.r = 1.0;
+ accumulated_light.r = 0.0;
+ }
+ if (accumulated_color.g == 0.0) {
+ accumulated_color.g = 1.0;
+ accumulated_light.g = 0.0;
+ }
+ if (accumulated_color.b == 0.0) {
+ accumulated_color.b = 1.0;
+ accumulated_light.b = 0.0;
+ }
+ fragColor = vec4(accumulated_light / accumulated_color, 1.0);
+ }
else {
+ /* Output error color: Unknown how to post process this pass. */
fragColor = vec4(1.0, 0.0, 1.0, 1.0);
}
}
diff --git a/source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl
new file mode 100644
index 00000000000..fa02bee45b7
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl
@@ -0,0 +1,58 @@
+
+out vec4 fragColor;
+
+#ifndef UTIL_TEX
+# define UTIL_TEX
+uniform sampler2DArray utilTex;
+# define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+void main()
+{
+ if (laNumLight == 0) {
+ /* Early exit: No lights in scene */
+ fragColor.r = 0.0;
+ return;
+ }
+
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ float depth = texelFetch(depthBuffer, texel, 0).r;
+ if (depth == 1.0f) {
+ /* Early exit background does not receive shadows */
+ fragColor.r = 1.0;
+ return;
+ }
+
+ vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
+ vec2 uvs = saturate(gl_FragCoord.xy * texel_size);
+ vec4 rand = texelfetch_noise_tex(texel);
+
+ float accum_light = 0.0;
+ float tracing_depth = depth;
+ /* Constant bias (due to depth buffer precision) */
+ /* Magic numbers for 24bits of precision.
+ * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */
+ tracing_depth -= mix(2.4e-7, 4.8e-7, depth);
+ /* Convert to view Z. */
+ tracing_depth = get_view_z_from_depth(tracing_depth);
+
+ vec3 viewPosition = get_view_space_from_depth(uvs, depth);
+ vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition);
+
+ vec3 true_normal = normalize(cross(dFdx(viewPosition), dFdy(viewPosition)));
+
+ for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) {
+ LightData ld = lights_data[i];
+
+ vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
+ l_vector.xyz = ld.l_position - worldPosition;
+ l_vector.w = length(l_vector.xyz);
+
+ float l_vis = light_shadowing(
+ ld, worldPosition, viewPosition, tracing_depth, true_normal, rand.x, true, 1.0);
+
+ accum_light += l_vis;
+ }
+
+ fragColor.r = accum_light / float(laNumLight);
+} \ No newline at end of file
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_accum_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_accum_frag.glsl
new file mode 100644
index 00000000000..1b6a7b33f42
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_accum_frag.glsl
@@ -0,0 +1,11 @@
+
+/* This shader is used to add default values to the volume accum textures.
+ * so it looks similar (transmittance = 1, scattering = 0) */
+layout(location = 0, index = 0) out vec4 FragColor0;
+layout(location = 0, index = 1) out vec4 FragColor1;
+
+void main()
+{
+ FragColor0 = vec4(0.0);
+ FragColor1 = vec4(1.0);
+}