Page MenuHome

EEVEE: Refactor closure_lit_lib.glsl
ClosedPublic

Authored by Clément Foucault (fclem) on Feb 10 2021, 9:47 PM.

Details

Summary

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.

Diff Detail

Repository
rB Blender

Event Timeline

Clément Foucault (fclem) requested review of this revision.Feb 10 2021, 9:47 PM
Clément Foucault (fclem) created this revision.

When running on an intel 10th gen iGPU:
Blender splash screen 2.91

EEVEE_shaders_volumes_integration_sh_get
| Warning: 'image format' : redundant image format layout qualifier
| Error: 'closure_load_ssr_data' : no matching overloaded function found (using implicit conversion)

GPU_material_compile
 | Error: 'closure_load_ssr_data' : no matching overloaded function found (using implicit conversion)

issue of the closure_load_ssr_data is the -1 in subsurface scattering, translucent and diffuse. the parameter used to be an int and is now a float.

source/blender/gpu/shaders/material/gpu_shader_material_diffuse.glsl
22
source/blender/gpu/shaders/material/gpu_shader_material_subsurface_scattering.glsl
34
source/blender/gpu/shaders/material/gpu_shader_material_translucent.glsl
14–15
  • Fix implicit cast error
This revision was not accepted when it landed; it landed in state Needs Review.Feb 13 2021, 8:53 PM
This revision was automatically updated to reflect the committed changes.