Blender Git Commit Log

Git Commits -> Revision 7f7e683

Revision 7f7e683 by Clément Foucault (master)
February 13, 2021, 17:43 (GMT)
EEVEE: Refactor closure_lit_lib.glsl

This refactor was needed for some reasons:
- closure_lit_lib.glsl was unreadable and could not be easily extended to use new features.
- It was generating ~5K LOC for any shader. Slowing down compilation.
- Some calculations were incorrect and BSDF/Closure code had lots of workaround/hacks.

What this refactor does:
- Add some macros to define the light object loops / eval.
- Clear separation between each closures which now have separate files. Each closure implements the eval functions.
- Make principled BSDF a bit more correct in some cases (specular coloring, mix between glass and opaque).
- The BSDF term are applied outside of the eval function and on the whole lighting (was separated for lights before).
- Make light iteration last to avoid carrying more data than needed.
- Makes sure that all inputs are within correct ranges before evaluating the closures (use `safe_normalize` on normals).
- Making each BSDF isolated means that we might carry duplicated data (normals for instance) but this should be optimized by compilers.
- Makes Translucent BSDF its own closure type to avoid having to disable raytraced shadows using hacks.
- Separate transmission roughness is now working on Principled BSDF.
- Makes principled shader variations using constants. Removing a lot of duplicated code. This needed `const` keyword detection in `gpu_material_library.c`.
- SSR/SSS masking and data loading is a bit more consistent and defined outside of closure eval. The loading functions will act as accumulator if the lighting is not to be separated.
- SSR pass now do a full deferred lighting evaluation, including lights, in order to avoid interference with the closure eval code. However, it seems that the cost of having a global SSR toggle uniform is making the surface shader more expensive (which is already the case, by the way).
- Principle fully black specular tint now returns black instead of white.
- This fixed some artifact issue on my AMD computer on normal surfaces (which might have been some uninitialized variables).
- This touched the Ambient Occlusion because it needs to be evaluated for each closure. But to avoid the cost of this, we use another approach to just pass the result of the occlusion on interpolated normals and modify it using the bent normal for each Closure. This tends to reduce shadowing. I'm still looking into improving this but this is out of the scope of this patch.
- Performance might be a bit worse with this patch since it is more oriented towards code modularity. But not by a lot.

Render tests needs to be updated after this.

Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D10390

# Conflicts:
# source/blender/draw/engines/eevee/eevee_shaders.c
# source/blender/draw/engines/eevee/shaders/common_utiltex_lib.glsl
# source/blender/draw/intern/shaders/common_math_lib.glsl

Commit Details:

Full Hash: 7f7e6830991bf66e285fb54cdbae6c6618ed7afa
Parent Commit: 40aadd8
Lines Changed: +1475, -1442

6 Added Paths:

/source/blender/draw/engines/eevee/shaders/closure_eval_diffuse_lib.glsl (+85, -0) (View)
/source/blender/draw/engines/eevee/shaders/closure_eval_glossy_lib.glsl (+136, -0) (View)
/source/blender/draw/engines/eevee/shaders/closure_eval_lib.glsl (+316, -0) (View)
/source/blender/draw/engines/eevee/shaders/closure_eval_refraction_lib.glsl (+128, -0) (View)
/source/blender/draw/engines/eevee/shaders/closure_eval_translucent_lib.glsl (+71, -0) (View)
/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl (+189, -0) (View)

2 Deleted Paths:

/source/blender/draw/engines/eevee/shaders/closure_lib.glsl (+0, -181)
/source/blender/draw/engines/eevee/shaders/closure_lit_lib.glsl (+0, -545)

26 Modified Paths:

/source/blender/draw/CMakeLists.txt (+6, -2) (Diff)
/source/blender/draw/engines/eevee/eevee_screen_raytrace.c (+6, -1) (Diff)
/source/blender/draw/engines/eevee/eevee_shaders.c (+12, -20) (Diff)
/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl (+17, -10) (Diff)
/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl (+11, -8) (Diff)
/source/blender/draw/engines/eevee/shaders/common_utiltex_lib.glsl (+13, -0) (Diff)
/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl (+79, -64) (Diff)
/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl (+4, -5) (Diff)
/source/blender/draw/engines/eevee/shaders/lights_lib.glsl (+19, -42) (Diff)
/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl (+6, -2) (Diff)
/source/blender/draw/engines/eevee/shaders/shadow_accum_frag.glsl (+5, -3) (Diff)
/source/blender/draw/engines/eevee/shaders/surface_frag.glsl (+7, -2) (Diff)
/source/blender/draw/engines/eevee/shaders/surface_lib.glsl (+10, -2) (Diff)
/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl (+1, -1) (Diff)
/source/blender/draw/intern/shaders/common_math_lib.glsl (+10, -0) (Diff)
/source/blender/gpu/intern/gpu_material_library.c (+4, -0) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl (+1, -1) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl (+19, -4) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl (+57, -25) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl (+31, -22) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_glossy.glsl (+23, -14) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl (+141, -433) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_refraction.glsl (+22, -7) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl (+22, -10) (Diff)
/source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl (+12, -4) (Diff)
/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c (+12, -34) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021