Shader: Add Metallic BSDF Node #114958

Open
Alaska wants to merge 30 commits from Alaska/blender:metallic-bsdf into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Add Metallic BSDF Node to the shader editor.

This node is basically the Glossy BSDF, but with different Fresnel
options, and the anisotropy input is interpreted differently to match
the Principled BSDF's interpretation of these inputs.

This node supports the F82 and Conductor fresnel options.

  • F82 allows for the replication of Principled BSDF Metallic materials
  • The Physical Conductor fresnel allows users to input n, k (IOR and extinction) values to easily
    recreate real life metals from their corrisponding real life values.
    • A "artist friendly" Conductor Fresnel has also been added
      to allow users to work in colors instead of n, k values.

TODO:

  • Fix the MaterialX node setup for when we're using the Physical Conductor Fresnel Type. (I couldn't figure out how to detect which "Fresnel Type" was being used. So I couldn't switch between using colors and using the n, k values in MaterialX. Help would be appreciated)
  • General code review

Images:

Node with the 3 fresnel types:

F82 Tint Artisitc Conductor Physcial Conductor
F82 Node.jpg Artisitc Conductor Node.jpg Physical Conductor Node.jpg

When using the same settings, the F82 Tint mode will produce the same result as a Metallic Principled BSDF.

F82 Fresnel on Conductor BSDF Metallic Principled BSDF
F82 Conductor - Render.png Metallic Principled - Render.png

Comparing the F82 Tint mode to Conductor - Artistic, the most notable thing is that Artisitc Conductor can't produce as strong of an edge tint as F82 Tint, with many combinations producing no noticable tint (like the example image below). This generally matches the MaterialX setup for a Artistic Conductor.

F82 Fresnel Conductor - Artistic "Fresnel"
F82 Conductor - Render.png Conductor - Artistic "Fresnel" - Render.png

The Physcial Conductor fresnel option allows users to specify n, k (IOR and extinction) values for the conductor fresnel rather than defining colors and turning them into n, k values (what Artistic Conductor does). The main benefit this offers is that it allows people to take n, k values from real life materials if material accuracy is important. A list containing some n, k values can be found here: https://physicallybased.info/

Copper n, k Gold n, k Chromium n, k
Copper nk - Render.png Gold nk - Artistic "Fresnel" - Render.png Chromium nk - Artistic "Fresnel" - Render.png
Add Metallic BSDF Node to the shader editor. This node is basically the Glossy BSDF, but with different Fresnel options, and the anisotropy input is interpreted differently to match the Principled BSDF's interpretation of these inputs. This node supports the F82 and Conductor fresnel options. - F82 allows for the replication of Principled BSDF Metallic materials - The Physical Conductor fresnel allows users to input `n, k` (IOR and extinction) values to easily recreate real life metals from their corrisponding real life values. - A "artist friendly" Conductor Fresnel has also been added to allow users to work in colors instead of `n, k` values. TODO: - [ ] Fix the MaterialX node setup for when we're using the `Physical Conductor Fresnel Type`. (I couldn't figure out how to detect which "Fresnel Type" was being used. So I couldn't switch between using colors and using the n, k values in MaterialX. Help would be appreciated) - [ ] General code review --- Images: Node with the 3 fresnel types: |F82 Tint|Artisitc Conductor|Physcial Conductor| |-|-|-| |![F82 Node.jpg](/attachments/5e35890d-888f-4f5e-b015-78260e984657)|![Artisitc Conductor Node.jpg](/attachments/2087c528-ae48-4569-ba67-900667863654)|![Physical Conductor Node.jpg](/attachments/62d38110-1cf7-435e-9f8a-f1c3831eae8c)| When using the same settings, the `F82 Tint` mode will produce the same result as a Metallic Principled BSDF. |F82 Fresnel on Conductor BSDF|Metallic Principled BSDF| |-|-| |![F82 Conductor - Render.png](/attachments/bc91d63f-bb06-42b7-ba00-0622e04374fe)|![Metallic Principled - Render.png](/attachments/9582fd4f-79b5-41b0-a6bd-8bb02a3b9c6c)| Comparing the `F82 Tint` mode to `Conductor - Artistic`, the most notable thing is that `Artisitc Conductor` can't produce as strong of an edge tint as `F82 Tint`, with many combinations producing no noticable tint (like the example image below). This generally matches the MaterialX setup for a Artistic Conductor. |F82 Fresnel|Conductor - Artistic "Fresnel"| |-|-| |![F82 Conductor - Render.png](/attachments/bc91d63f-bb06-42b7-ba00-0622e04374fe)|![Conductor - Artistic "Fresnel" - Render.png](/attachments/64fc665f-9dfd-4a62-894f-76213977ba5b)| The `Physcial Conductor` fresnel option allows users to specify `n, k` (IOR and extinction) values for the conductor fresnel rather than defining colors and turning them into `n, k` values (what `Artistic Conductor` does). The main benefit this offers is that it allows people to take `n, k` values from real life materials if material accuracy is important. A list containing some `n, k` values can be found here: https://physicallybased.info/ |Copper `n, k`| Gold `n, k`|Chromium `n, k`| |-|-|-| |![Copper nk - Render.png](/attachments/678befa2-e4df-4eda-9511-a89ba539c13f)|![Gold nk - Artistic "Fresnel" - Render.png](/attachments/117481ec-e128-425d-8c94-6634aa97f203)|![Chromium nk - Artistic "Fresnel" - Render.png](/attachments/c14fbf75-696e-49ee-bac4-cef7a5dac792)|
Alaska added the
Module
Render & Cycles
label 2023-11-16 05:24:10 +01:00
Alaska added 6 commits 2023-11-16 05:24:22 +01:00
- Node appears in shader editor
- Material renders in EEVEE

TODO: Work on Cycles
- Node appears in shader editor
- Material renders in EEVEE

TODO: Work on Cycles
The material now (incorrectly) renders in Cycles in both SVM and OSL

TODO:
 - Add support for Tint to SVM
 - Use seperate "Conductor BSDF" case instead of reusing glossy closures.
 - Update SVM and OSL to be based on the Principled BSDF Metallic instead of the Glossy BSDF
Alaska requested review from Brecht Van Lommel 2023-11-16 05:24:29 +01:00
Alaska requested review from Lukas Stockner 2023-11-16 05:24:37 +01:00
Author
Member

Intially when I mentioned adding this to Blender, it was going to be called the "Metallic BSDF". But I renamed it to the "Conductor BSDF" in line with MaterialX.

Please let me know if you want the name changed.

Intially when I mentioned adding this to Blender, it was going to be called the "Metallic BSDF". But I renamed it to the "Conductor BSDF" in line with MaterialX. Please let me know if you want the name changed.
First-time contributor

What is the difference between this and Glossy BSDF?

What is the difference between this and Glossy BSDF?
Author
Member

What is the difference between this and Glossy BSDF?

  • The Conductor BSDF has support for the F82 tint like the Principled BSDF.
  • Anisotropy is interpreted differently from the Glossy BSDF.
  • Fewer Microfacet Distributions are supported.
> What is the difference between this and Glossy BSDF? - The Conductor BSDF has support for the F82 tint like the Principled BSDF. - Anisotropy is interpreted differently from the Glossy BSDF. - Fewer Microfacet Distributions are supported.
Member

Generally this is good to have, but I think we should a) support the full range of Microfacet distributions and b) have an enum for switching between F82 Fresnel and the proper conductive Fresnel (which currently is only available through OSL), potentially also the Artist-Friendly Base/Edge Color reparametrization since enough other tools use it and it's quite straightforward to add without a new closure.

Generally this is good to have, but I think we should a) support the full range of Microfacet distributions and b) have an enum for switching between F82 Fresnel and the proper conductive Fresnel (which currently is only available through OSL), potentially also the Artist-Friendly Base/Edge Color reparametrization since enough other tools use it and it's quite straightforward to add without a new closure.
Author
Member

b) have an enum for switching between F82 Fresnel and the proper conductive Fresnel (which currently is only available through OSL)

Is the OSL "proper conductive Fresnel" osl_closure_conductor_bsdf_setup() in /intern/cycles/kernel/osl/closures_setup.h or is it something else?

potentially also the Artist-Friendly Base/Edge Color reparametrization since enough other tools use it and it's quite straightforward to add without a new closure.

Sorry, it's not clear to me what you mean by this. Do you mean add an option to switch between a Base/Edge color input, and a n, k input? For both the F82 Fresnel and the Conductive Fresnel?

> b) have an enum for switching between F82 Fresnel and the proper conductive Fresnel (which currently is only available through OSL) Is the OSL "proper conductive Fresnel" `osl_closure_conductor_bsdf_setup()` in `/intern/cycles/kernel/osl/closures_setup.h` or is it something else? > potentially also the Artist-Friendly Base/Edge Color reparametrization since enough other tools use it and it's quite straightforward to add without a new closure. Sorry, it's not clear to me what you mean by this. Do you mean add an option to switch between a Base/Edge color input, and a `n, k` input? For both the F82 Fresnel and the Conductive Fresnel?
Alaska added 2 commits 2023-11-19 05:06:15 +01:00
Alaska added 3 commits 2023-11-20 12:25:38 +01:00
Notable changes from previous revision of Conductor BSDF:
 - There are three "Fresnel Types" that can be selected on the node.
   -  Conductor Fresnel - Artistic (Default)
      - Uses `bsdf_microfacet_setup_fresnel_conductor()` in Cycles. Takes a Color `Base` and `Tint` input with automatic code to turn it into `n, k` values (fresnel_conductor uses `n, k` values).
   - F82 Tint Fresnel (Old default)
      - Uses `bsdf_microfacet_setup_fresnel_f82_tint()` in Cycles. Takes a Color "Base" and "Tint" input. This option should match the a metallic Principled BSDF material.
   - Conductor Fresnel
      - Uses `bsdf_microfacet_setup_fresnel_conductor()` in Cycles. Takes in `n, k` values.
- Various functions have been added to support the new `Conductor Fresnel - Artistic`.
   - For example, I've added `conductor_ior_from_color` and `conductor_extinction_from_color` fucntions to get `n, k` values from color `Base` and `Tint` inputs.
     - Formula is taken from the paper `"Artist Friendly Metallic Fresnel", Ole Gulbrandsen, 2014`.
     - These are the same formulas used by MaterialX in the `artistic_ior` node.
- General other changes (E.G. Change names of certain inputs, adjust default values, etc.)

TODO:
1. Fix the MaterialX node setup for when we're using the "Conductor Fresnel Type".
2. Adjust names and the descriptions of inputs to explain things. (Feedback from developers would be appreciated).
3. Check with Cycles developers to see if the names of the newly added functions are alright.
4. Wait for general code review. See if any other changes are wanted.
Add a code comment
Author
Member

I just wanted to add the commit message of one of the recent commits to explain recent changes.


Notable changes from previous revision of Conductor BSDF:

  • There are three "Fresnel Types" that can be selected on the node.

    • Conductor Fresnel - Artistic (Default)
      • Uses bsdf_microfacet_setup_fresnel_conductor() in Cycles. Takes a Color Base and Tint input making it "artist friendly" compared to the Conductor Fresnel option (see below). Automatic code is run to turn these colors into n, k values for fresnel_conductor (which uses n, k values).
      • EEVEE behaves the same as F82 Tint. This causes rendering differences between EEVEE and Cycles.
    • F82 Tint Fresnel (Old default)
      • Uses bsdf_microfacet_setup_fresnel_f82_tint() in Cycles. Takes a Color "Base" and "Tint" input. This option should match a metallic Principled BSDF material.
    • Conductor Fresnel
      • Uses bsdf_microfacet_setup_fresnel_conductor() in Cycles. Takes n, k values as inputs.
      • EEVEE takes the n, k values and turns them into Base and F82 tint colors and uses them in the F82 tint formula. This causes rendering differences between EEVEE and Cycles.
  • Various functions have been added to support the new Conductor Fresnel - Artistic.

    • For example, I've added conductor_ior_from_color and conductor_extinction_from_color functions to get n, k values from color Base and Tint inputs.
      • Formula is taken from the paper "Artist Friendly Metallic Fresnel", Ole Gulbrandsen, 2014.
      • These are the same formulas used by MaterialX in the artistic_ior node.
  • General other changes (E.G. Change names of certain inputs, adjust default values, etc.)

I just wanted to add the commit message of one of the recent commits to explain recent changes. --- Notable changes from previous revision of Conductor BSDF: - There are three "Fresnel Types" that can be selected on the node. - Conductor Fresnel - Artistic (Default) - Uses `bsdf_microfacet_setup_fresnel_conductor()` in Cycles. Takes a Color `Base` and `Tint` input making it "artist friendly" compared to the `Conductor Fresnel` option (see below). Automatic code is run to turn these colors into `n, k` values for `fresnel_conductor` (which uses `n, k` values). - EEVEE behaves the same as F82 Tint. This causes rendering differences between EEVEE and Cycles. - F82 Tint Fresnel (Old default) - Uses `bsdf_microfacet_setup_fresnel_f82_tint()` in Cycles. Takes a Color "Base" and "Tint" input. This option should match a metallic Principled BSDF material. - Conductor Fresnel - Uses `bsdf_microfacet_setup_fresnel_conductor()` in Cycles. Takes `n, k` values as inputs. - EEVEE takes the n, k values and turns them into `Base` and `F82 tint` colors and uses them in the F82 tint formula. This causes rendering differences between EEVEE and Cycles. - Various functions have been added to support the new `Conductor Fresnel - Artistic`. - For example, I've added `conductor_ior_from_color` and `conductor_extinction_from_color` functions to get `n, k` values from color `Base` and `Tint` inputs. - Formula is taken from the paper `"Artist Friendly Metallic Fresnel", Ole Gulbrandsen, 2014`. - These are the same formulas used by MaterialX in the `artistic_ior` node. - General other changes (E.G. Change names of certain inputs, adjust default values, etc.)

@LukasStockner, can you review this one?

@LukasStockner, can you review this one?
Alaska added 1 commit 2024-01-11 01:17:09 +01:00
Lukas Stockner self-assigned this 2024-01-22 03:05:27 +01:00
Alaska added 1 commit 2024-02-23 12:18:51 +01:00
Alaska added 1 commit 2024-02-23 12:20:58 +01:00
Author
Member

@LukasStockner and @brecht , is there interest in adding a Conductor BSDF node? If so, should I rebase this against main?

@LukasStockner and @brecht , is there interest in adding a Conductor BSDF node? If so, should I rebase this against main?

I think it generally should still be the goal to have these components of the Principled BSDF available as individual nodes. So I think yes.

I think it generally should still be the goal to have these components of the Principled BSDF available as individual nodes. So I think yes.
Member

Agreed, this is definitely good to have (also for physically-based metallic thin film in the future). Sorry for letting this one slip through the cracks, I'll do a proper review soon.

Agreed, this is definitely good to have (also for physically-based metallic thin film in the future). Sorry for letting this one slip through the cracks, I'll do a proper review soon.
Alaska added 2 commits 2024-06-25 06:17:46 +02:00
Author
Member

I've merged main into this pull request and I've shifted the TODOs into the pull request message. The TODOs are there because I'm not sure how to resolve them, or how best to approach them.

I've merged main into this pull request and I've shifted the TODOs into the pull request message. The TODOs are there because I'm not sure how to resolve them, or how best to approach them.
Alaska added this to the Render & Cycles project 2024-06-25 11:29:42 +02:00
Alaska removed review request for Brecht Van Lommel 2024-06-28 19:51:02 +02:00
Alaska requested review from Sergey Sharybin 2024-06-28 19:51:03 +02:00
Alaska requested review from Weizhen Huang 2024-06-28 19:51:03 +02:00
Lukas Stockner requested changes 2024-07-04 20:18:58 +02:00
@ -470,0 +478,4 @@
sd, sizeof(MicrofacetBsdf), rgb_to_spectrum(make_float3(mix_weight)));
if (!(bsdf == NULL)) {
uint base_ior_offest, edge_tint_k_offset, rotation_offset, tangent_offset;
Member

Typo: offest.

Typo: `offest`.
Alaska marked this conversation as resolved
@ -0,0 +4,4 @@
vec4 fresnel_conductor(float cosi, const vec3 eta, const vec3 k)
{
const vec4 cosiv4 = vec4(cosi);
Member

I'd rather perform this computation in vec3 and then do

vec3 F0 = base_color.rgb;
vec3 F82 = edge_tint.rgb;
if (use_complex_ior != 0.0) {
  /* Compute incidence at 0 and 82 degrees from conductor Fresnel. */
  F0 = fresnel_conductor(1.0, ior, extinction);
  F82 = fresnel_conductor(1.0 / 7.0, ior, extinction);
}
brdf_f82_tint_lut(saturate(F0), saturate(F82), ...
I'd rather perform this computation in `vec3` and then do ``` vec3 F0 = base_color.rgb; vec3 F82 = edge_tint.rgb; if (use_complex_ior != 0.0) { /* Compute incidence at 0 and 82 degrees from conductor Fresnel. */ F0 = fresnel_conductor(1.0, ior, extinction); F82 = fresnel_conductor(1.0 / 7.0, ior, extinction); } brdf_f82_tint_lut(saturate(F0), saturate(F82), ... ```
Alaska marked this conversation as resolved
@ -4045,6 +4045,29 @@ static const EnumPropertyItem node_ycc_items[] = {
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem node_conductor_distrobution_items[] = {
Member

Typo: distrobution.

Typo: `distrobution`.
Alaska marked this conversation as resolved
@ -4048,0 +4048,4 @@
static const EnumPropertyItem node_conductor_distrobution_items[] = {
{SHD_GLOSSY_BECKMANN, "BECKMANN", 0, "Beckmann", ""},
{SHD_GLOSSY_GGX, "GGX", 0, "GGX", ""},
{SHD_GLOSSY_MULTI_GGX,
Member

Do we want to keep the Multi/Single GGX distinction here? I kept it in for compatibility, but since this is a new node, I'd prefer just having a single GGX option that enables it.

Do we want to keep the Multi/Single GGX distinction here? I kept it in for compatibility, but since this is a new node, I'd prefer just having a single GGX option that enables it.
Author
Member

I'm not the right person to answer that question. Maybe Sergey or Weizhen can share their thoughts.

I'm not the right person to answer that question. Maybe Sergey or Weizhen can share their thoughts.
@ -4048,0 +4058,4 @@
};
static const EnumPropertyItem node_conductor_fresnel_type_items[] = {
{SHD_CONDUCTOR, "CONDUCTOR", 0, "Conductor Fresnel", ""},
Member

Not a big fan of naming this the same as the node. Maybe something like "Physical" would make more sense.

Then again, I'd actually prefer naming the entire node "Metallic BSDF" and having the options "Physical Conductor", "Artistic Conductor" and "F82 Approximation".

Not a big fan of naming this the same as the node. Maybe something like "Physical" would make more sense. Then again, I'd actually prefer naming the entire node "Metallic BSDF" and having the options "Physical Conductor", "Artistic Conductor" and "F82 Approximation".
Alaska marked this conversation as resolved
@ -61,6 +61,7 @@ DefNode(ShaderNode, SH_NODE_ATTRIBUTE, def_sh_attribute, "ATT
DefNode(ShaderNode, SH_NODE_AMBIENT_OCCLUSION, def_sh_ambient_occlusion,"AMBIENT_OCCLUSION", AmbientOcclusion, "Ambient Occlusion", "Compute how much the hemisphere above the shading point is occluded, for example to add weathering effects to corners.\nNote: For Cycles, this may slow down renders significantly")
DefNode(ShaderNode, SH_NODE_BACKGROUND, 0, "BACKGROUND", Background, "Background", "Add background light emission.\nNote: This node should only be used for the world surface output")
DefNode(ShaderNode, SH_NODE_HOLDOUT, 0, "HOLDOUT", Holdout, "Holdout", "Create a \"hole\" in the image with zero alpha transparency, which is useful for compositing.\nNote: the holdout shader can only create alpha when transparency is enabled in the film settings")
DefNode(ShaderNode, SH_NODE_BSDF_CONDUCTOR, def_conductor, "BSDF_CONDUCTOR", BsdfConductor, "Conductor BSDF", "Reflection with microfacet distribution, used for materials such as metal or mirrors")
Member

The description here appears to be identical to the Glossy BSDF, we might want to add something about specifically modeling the reflectivity of metals.

The description here appears to be identical to the Glossy BSDF, we might want to add something about specifically modeling the reflectivity of metals.
@ -0,0 +17,4 @@
.default_value({0.183f, 0.421f, 1.373f})
.min(0.0f)
.max(100.0f)
.description("PLACEHOLDER");
Member

I'd say "Real part of the conductor's IOR" and "Complex part of the conductor's IOR". The entire purpose of this mode is for users who know what that is, I wouldn't worry about a simple intuitive explanation here (especially since there is none as far as I know).

I'd say "Real part of the conductor's IOR" and "Complex part of the conductor's IOR". The entire purpose of this mode is for users who know what that is, I wouldn't worry about a simple intuitive explanation here (especially since there is none as far as I know).
Alaska marked this conversation as resolved
@ -0,0 +84,4 @@
{
const int fresnel_method = node->custom2;
bke::nodeSetSocketAvailability(
Member

Feels like we should do const bool is_physical = (fresnel_method == SHD_CONDUCTOR); and then use that instead of repeating it four times.

Feels like we should do `const bool is_physical = (fresnel_method == SHD_CONDUCTOR);` and then use that instead of repeating it four times.
Alaska marked this conversation as resolved
Alaska added 11 commits 2024-07-05 04:56:31 +02:00
Alaska changed title from Shader: Add Conductor BSDF Node to Shader: Add Metallic BSDF Node 2024-07-05 04:56:43 +02:00
Alaska added 3 commits 2024-07-07 06:53:02 +02:00
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u metallic-bsdf:Alaska-metallic-bsdf
git checkout Alaska-metallic-bsdf
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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 Assignees
4 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#114958
No description provided.