Cycles: Rework component layering in Principled BSDF #110864

Merged
Lukas Stockner merged 10 commits from LukasStockner/blender:layering-principled into main 2023-08-10 23:53:44 +02:00
Member

Overall, this PR reworks the component layering in the Principled BSDF in order to ensure that energy is preserved and conserved.

This includes:

  • Implementing support for the OSL layer() function
  • Implementing albedo estimation for some of the closures (for layering purposes)
    • The specular layer that the Principled BSDF uses has a proper tabulated albedo lookup, the others are still approximations
  • Removing the custom "Principled Diffuse" and replacing it with the classic lambertian Diffuse, since the layering logic takes care of energy now

Note that this changes the look of the Principled BSDF noticeably in some cases, but that's needed, since the cases where it looks different are the ones that strongly violate energy conservation (mostly grazing reflections with strong Specular).

Overall, this PR reworks the component layering in the Principled BSDF in order to ensure that energy is preserved and conserved. This includes: - Implementing support for the OSL `layer()` function - Implementing albedo estimation for some of the closures (for layering purposes) - The specular layer that the Principled BSDF uses has a proper tabulated albedo lookup, the others are still approximations - Removing the custom "Principled Diffuse" and replacing it with the classic lambertian Diffuse, since the layering logic takes care of energy now Note that this changes the look of the Principled BSDF noticeably in some cases, but that's needed, since the cases where it looks different are the ones that strongly violate energy conservation (mostly grazing reflections with strong Specular).
Lukas Stockner added the
Interest
Render & Cycles
label 2023-08-07 01:29:08 +02:00

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR110864) when ready.
Brecht Van Lommel reviewed 2023-08-08 18:33:58 +02:00
Brecht Van Lommel left a comment
Owner

I have not checked every line in detail, but the overall approach looks great to me.

Some images and timings would be nice.

I have not checked every line in detail, but the overall approach looks great to me. Some images and timings would be nice.
@ -71,2 +71,4 @@
float3 weight_stack[16];
ccl_private const OSLClosure *closure_stack[16];
int layer_stack_level = -1;
float3 layer_albedo;

Typically better for the GPU compiler to initialize this.

Typically better for the GPU compiler to initialize this.
brecht marked this conversation as resolved
Author
Member

Some images and timings would be nice.


Scene Old New New with exposure adjusted
Diorama diorama_old.png 1m25s diorama_new.png 1m24s /
3.5 Splash splash35_old.png 2m48s splash35_new.png 2m49s splash35_new_exposure0.2.png 2m49s, exposure +0.2
2.81 Splash splash281_old.png 55s splash281_new.png 56s splash281_new_exposure0.2.png 56s, exposure +0.2
> Some images and timings would be nice. ------ | Scene | Old | New | New with exposure adjusted | | - | - | - | - | | Diorama | ![diorama_old.png](/attachments/cb3c3f11-27ba-488b-a896-a0b10b933ae4) 1m25s | ![diorama_new.png](/attachments/ab54ab65-f250-4bd9-b309-ee8ac1826f31) 1m24s | / | | 3.5 Splash | ![splash35_old.png](/attachments/9e1e6ede-4b2e-4e11-983f-b94bd1f296c2) 2m48s | ![splash35_new.png](/attachments/8e38e468-2b44-486a-9636-c97a1ccc0273) 2m49s | ![splash35_new_exposure0.2.png](/attachments/c332889c-500e-4041-a2d1-06bcd2167e03) 2m49s, exposure +0.2 | | 2.81 Splash | ![splash281_old.png](/attachments/1a0a84f7-dea6-4386-860d-3b85323d6d2e) 55s | ![splash281_new.png](/attachments/ed2dc8a8-edae-492c-83cb-e9a007096446) 56s | ![splash281_new_exposure0.2.png](/attachments/d6530f6e-6c42-4e8f-b682-6b38b4130e9a) 56s, exposure +0.2 |
Brecht Van Lommel requested changes 2023-08-09 15:14:17 +02:00
Brecht Van Lommel left a comment
Owner

Render time and look differences seem within an acceptable range.

In the regression tests, render passes specular direct seems wrong, there is a checker texture visible in that pass.

Render time and look differences seem within an acceptable range. In the regression tests, `render passes specular direct` seems wrong, there is a checker texture visible in that pass.
@ -114,0 +141,4 @@
/* We just finished processing the top layers of a Layer closure, so adjust the weight to
* account for the layering. */
weight *= saturatef(1.0f - reduce_max(layer_albedo / weight));
/* TODO: Skip if weight zero */

Is this still intended to be resolved?

Is this still intended to be resolved?
Author
Member

Yep, resolved now. I had tried to find a way to not repeat the stack popping code, but didn't come up with anything.

Yep, resolved now. I had tried to find a way to not repeat the stack popping code, but didn't come up with anything.
brecht marked this conversation as resolved
Author
Member

In the regression tests, render passes specular direct seems wrong, there is a checker texture visible in that pass.

I've improved the color pass now by extending and improving the precomputed tables that are used to lookup the expected Fresnel effect depending on roughness, instead of just using the smooth surface approximation.

With this change, the checkerboard is completely gone when using the material in a "sphere in front of white background" setup.

However, in the test scene it's still slightly visible. This is expected - bounce rays at grazing angles are occluded by the back wall, while more vertical rays aren't. And since the Fresnel effect depends on angle, the effective mix between F0 (checkerboard) and F90 (white) changes, and so the precomputed value no longer fits perfectly.

In case you're wondering how this worked before the change (as I did): The material has Specular set to zero, and the old formulation of the Principled BSDF had a weird quirk where the Specular input affected the Fresnel curve that was used for metals. By setting it to zero, Fresnel was effectively disabled. If you increase Specular, you also get the checkerboard in old builds.

> In the regression tests, render passes specular direct seems wrong, there is a checker texture visible in that pass. I've improved the color pass now by extending and improving the precomputed tables that are used to lookup the expected Fresnel effect depending on roughness, instead of just using the smooth surface approximation. With this change, the checkerboard is completely gone when using the material in a "sphere in front of white background" setup. However, in the test scene it's still slightly visible. This is expected - bounce rays at grazing angles are occluded by the back wall, while more vertical rays aren't. And since the Fresnel effect depends on angle, the effective mix between F0 (checkerboard) and F90 (white) changes, and so the precomputed value no longer fits perfectly. In case you're wondering how this worked before the change (as I did): The material has Specular set to zero, and the old formulation of the Principled BSDF had a weird quirk where the Specular input affected the Fresnel curve that was used for metals. By setting it to zero, Fresnel was effectively disabled. If you increase Specular, you also get the checkerboard in old builds.
Brecht Van Lommel approved these changes 2023-08-10 18:36:32 +02:00
Brecht Van Lommel left a comment
Owner

Thanks, looks good to me now.

Thanks, looks good to me now.
Lukas Stockner force-pushed layering-principled from 86100d921b to 6a3c2f62c5 2023-08-10 23:51:07 +02:00 Compare
Lukas Stockner merged commit 2ac0b36e4e into main 2023-08-10 23:53:44 +02:00
Lukas Stockner deleted branch layering-principled 2023-08-10 23:53:46 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110864
No description provided.