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:
authorClément Foucault <foucault.clem@gmail.com>2021-07-19 20:01:09 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-07-19 20:01:09 +0300
commit6206a30519effffdf49c97c02e858c25198fc690 (patch)
tree90b8790603848f9577caea10d73fbb8a0bb61c42 /source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl
parente3ff83a4a84b7dd2e211324a5267ecd3d5087dae (diff)
EEVEE: GBuffer: Change layout
This change the gbuffer layout to use more of the hardware to converting data back and forth. Normals are encoded as two 16 bits components and colors as R11G11B10F format. This was motivated by the need of better quality normals. The issue is that this increase the GBuffer size consequently. In order to balance this we chose to merge the refraction and Diffuse/SSS data to use the same buffer. This means we need to stochastically chose one of these layers (so noise appear). Given that Glass BSDFs are rarely mixed with Diffuse BSDFs, we think this is a good tradeoff.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl55
1 files changed, 46 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl
index 54bea96e8f6..9d5b27e6826 100644
--- a/source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/eevee_surface_deferred_frag.glsl
@@ -18,12 +18,24 @@ uniform sampler2DArray utility_tx;
utility_tx_fetch_define(utility_tx);
utility_tx_sample_define(utility_tx);
-layout(location = 0) out uvec4 out_diffuse_data; /* Diffuse BSDF, BSSSDF, Translucency. */
-layout(location = 1) out uvec2 out_reflection_data; /* Glossy BSDF. */
-layout(location = 2) out uvec4 out_refraction_data; /* Refraction BSDF. */
-layout(location = 3) out uvec4 out_volume_data; /* Volume Emission, Absorption, Scatter. */
-layout(location = 4) out vec4 out_emission_data; /* Emission. */
-layout(location = 5) out vec4 out_transparency_data; /* Transparent BSDF, Holdout. */
+/* Diffuse or Transmission Color. */
+layout(location = 0) out vec3 out_transmit_color;
+/* RG: Normal (negative if Tranmission), B: SSS ID, A: Min-Thickness */
+layout(location = 1) out vec4 out_transmit_normal;
+/* RGB: SSS RGB Radius.
+ * or
+ * R: Transmission IOR, G: Transmission Roughness, B: Unused. */
+layout(location = 2) out vec3 out_transmit_data;
+/* Reflection Color. */
+layout(location = 3) out vec3 out_reflection_color;
+/* RG: Normal, B: Roughness X, A: Roughness Y. */
+layout(location = 4) out vec4 out_reflection_normal;
+/* Volume Emission, Absorption, Scatter, Phase. */
+layout(location = 5) out uvec4 out_volume_data;
+/* Emission. */
+layout(location = 6) out vec3 out_emission_data;
+/* Transparent BSDF, Holdout. */
+layout(location = 7) out vec4 out_transparency_data;
void main(void)
{
@@ -32,9 +44,14 @@ void main(void)
float noise_offset = sampling_rng_1D_get(sampling, SAMPLING_CLOSURE);
float noise = utility_tx_fetch(gl_FragCoord.xy, UTIL_BLUE_NOISE_LAYER).r;
g_data.closure_rand = fract(noise + noise_offset);
+ /* TODO(fclem) other RNG. */
+ g_data.transmit_rand = fract(g_data.closure_rand * 6.1803398875);
nodetree_surface();
+ /* TODO(fclem) Textured minimal thickness. */
+ // nodetree_thickness();
+
float alpha = saturate(1.0 - avg(g_transparency_data.transmittance));
if (alpha > 0.0) {
@@ -48,9 +65,29 @@ void main(void)
g_refraction_data.ior = safe_rcp(g_refraction_data.ior);
}
- out_diffuse_data = gbuffer_store_diffuse_data(g_diffuse_data);
- out_reflection_data = gbuffer_store_reflection_data(g_reflection_data);
- out_refraction_data = gbuffer_store_refraction_data(g_refraction_data);
+ if (g_data.transmit_rand == 0.0) {
+ out_transmit_color = g_refraction_data.color;
+ out_transmit_normal.xy = -gbuffer_encode_normal(g_refraction_data.N);
+ out_transmit_normal.z = 1.0;
+ // out_transmit_normal.w = g_data.thickness;
+ out_transmit_data.x = g_refraction_data.ior;
+ out_transmit_data.y = g_refraction_data.roughness;
+ }
+ else {
+ /* Output diffuse / SSS in transmit data. */
+ out_transmit_color = g_diffuse_data.color;
+ out_transmit_normal.xy = gbuffer_encode_normal(g_diffuse_data.N);
+ out_transmit_normal.z = fract(float(g_diffuse_data.sss_id) / 1024.0);
+ // out_transmit_normal.w = g_data.thickness;
+ out_transmit_data = g_diffuse_data.sss_radius;
+ }
+
+ {
+ out_reflection_color = g_reflection_data.color;
+ out_reflection_normal.xy = gbuffer_encode_normal(g_reflection_data.N);
+ out_reflection_normal.z = g_reflection_data.roughness;
+ }
+
out_volume_data = gbuffer_store_volume_data(g_volume_data);
out_emission_data = gbuffer_store_emission_data(g_emission_data);
out_transparency_data = gbuffer_store_transparency_data(g_transparency_data);