Page MenuHome

added emission strength to the principled BSDF node.
ClosedPublic

Authored by Kenzie (kenziemac130) on May 29 2019, 4:14 AM.
Tokens
"Like" token, awarded by MetinSeven."Love" token, awarded by gilberto_rodrigues."Like" token, awarded by Kickflipkid687."Like" token, awarded by Kdaf."Like" token, awarded by zanqdo."The World Burns" token, awarded by Ko."Love" token, awarded by mistajuliax."Love" token, awarded by AnityEx."Love" token, awarded by Shimoon."Like" token, awarded by Schamph."Like" token, awarded by YAFU."Love" token, awarded by eobet."100" token, awarded by lopoIsaac."Love" token, awarded by nacioss."Burninate" token, awarded by ostapblender."Like" token, awarded by duarteframos.

Details

Summary

I added an emission strength value to the principled BSDF node. The node currently felt incomplete without it requiring the user to add a color blend node set to multiply with a value in order to control emission strength (a bit of a paper-cut if you ask me).

It wasn't that big of a task to do but it will definitely speed up workflows and perhaps even make creating exporters with emission strength (like GLTF) simpler.

Changes include:

  • Added emission strength socket to the principled node
  • Removed hard coded strength from the cycles implementation of principled emission and replaced it with a shader input
  • Updated eevee GLSL code to include an emission strength multiplier

Here is a comparison:


(the very slight washed out difference with cycles is due to bounce lighting)

Thank you for your time!

Diff Detail

Repository
rB Blender

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Fixed hard-coded socket indices.

oops accidentally replaced the entire diff. (I don't know how to use git, sorry let me figure this out.)

After some troubleshooting I just did a fresh installation of the blender source and applied the patches.

This revision fixes:

  • Offsets later hard-coded slot indices by 1 to accommodate the new emission strength slot.
  • Cycles: When the value of emission strength value is set to 0.0 node inputs will override the branch out of the emission component.
Kenzie (kenziemac130) marked an inline comment as done.May 30 2019, 3:31 AM
Kenzie (kenziemac130) added inline comments.
source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
43

Should be fixed now, thank you for pointing that out.

Kenzie (kenziemac130) marked an inline comment as done.May 30 2019, 3:31 AM

Can i suggest that the default values follow what the SubSurface inputs are? the emission strength would be 0 and the default emission colour be white (instead of the inverse?)

Can i suggest that the default values follow what the SubSurface inputs are? the emission strength would be 0 and the default emission colour be white (instead of the inverse?)

That might have been the ideal way to do it, unfortunately I'm afraid that could break older files that only use the emission Color, when the emission strength would default to 0 the material would lack emission. And since this feature seems to be coming post 2.80 that would probably be a much bigger deal then if that change was made during the beta.

In D4971#113806, @astrand130 wrote:

Can i suggest that the default values follow what the SubSurface inputs are? the emission strength would be 0 and the default emission colour be white (instead of the inverse?)

That might have been the ideal way to do it, unfortunately I'm afraid that could break older files that only use the emission Color, when the emission strength would default to 0 the material would lack emission. And since this feature seems to be coming post 2.80 that would probably be a much bigger deal then if that change was made during the beta.

@Brecht Van Lommel (brecht) do you have any thoughts about this?

It's possible to initialize the strength to 1 only if the color is black. See versioning_cycles.c, there's other code there that does this kind of versioning patches for nodes.

It's possible to initialize the strength to 1 only if the color is black. See versioning_cycles.c, there's other code there that does this kind of versioning patches for nodes.

Thanks, I'll take a look at it and see what I can do.

Apologies for the inactivity. I've been dealing with classes. Once 2.80 releases I'll make sure to get the backwards compatibility finished and address any remaining issues so it can make it into 2.81.

Congratulations on the 2.80 Release! I hope SIGGRAPH went well.

Can i suggest that the default values follow what the SubSurface inputs are? the emission strength would be 0 and the default emission colour be white (instead of the inverse?)

It's possible to initialize the strength to 1 only if the color is black. See versioning_cycles.c, there's other code there that does this kind of versioning patches for nodes.

I was wondering if this could be a separate patch as it requires adding changes to another file which might introduce its own bugs to fix. The emission strength socket is already complete and I've been using blender with it for a while and haven't run into problems. In it's current state it should work perfectly with existing materials. Since the default material emission strength is 1.0 and its default color is still black there would be no visible changes to the existing emission results.

If the improvements in the defaults can be done separately this patch should be ready for review, and if there are no more issues a possible commit to 2.81.

Thank you.

Kenzie (kenziemac130) updated this revision to Diff 17358.EditedAug 22 2019, 3:28 AM

All conflicts should be fixed and this patch has been made ready for review and merge to 2.81.

@Brecht Van Lommel (brecht) I have some questions. I'm working on the defaults improvements as suggested by @Carlo Andreacchio (candreacchio) using versioning_cycles.c but I'm not sure what to set MAIN_VERSION_ATLEAST() to.

How do I know what version to set it to?

Currently I have:

if (!MAIN_VERSION_ATLEAST(bmain, 281, 0)) {
 for (bNode *node = ntree->nodes.first; node; node = node->next) {
  principled_emit_strength_input(node);
 }
}

With principled_emit_strength_input() as:

static void principled_emit_strength_input(bNode *node)
{
  if (node->type == SH_NODE_BSDF_PRINCIPLED) {
    bNodeSocket *emit_color_socket = nodeFindSocket(node, SOCK_IN, "Emission");
    bNodeSocket *emit_strength_socket = nodeFindSocket(node, SOCK_IN, "Emission Strength");
    float *strength_value = cycles_node_socket_float_value(emit_strength_socket);
    float *color_value = cycles_node_socket_rgba_value(emit_color_socket);

    /* If emission is already used, the strength should be set to one */
    if ((socket_is_used(emit_color_socket)) || !is_zero_v3(color_value)) {
      *strength_value = 1.0f;
    }
  }
}

I'm going to try to test it on a variety of files from the current build-bot. For now I don't want to cause potential compatibility problems, so this initial patch here won't break anything.

You increase the subversion in BKE_blender_version.h, and then use that new value in MAIN_VERSION_ATLEAST instead of 0

@astrand130 hi, are you planning to update this patch? Looks like it is close to being finished.

Hi, I would really appreciate this feature, specially to play well with GLTF export pipelines

Apologies for the delay. Life has been a little messy. I am working on updating this to the new versions of Blender right away!

Updated to be compatible with 2.90x and with updated defaults based on recommendations, maintains compatibility with older files.

The implementation looks good, but I do worry about add-on compatibility.

Most exporters will now simply export emission with the strength, which means that without modification basically all materials will export with emission.

We'll need to check on updating the FBX and glTF add-ons at least. We could also additionally be conservative and leave the default emission to black, and only set it to black later on when more add-ons support emission strength for export.

This revision is now accepted and ready to land.Jul 15 2020, 2:10 PM

Updated versioning for expected inclusion in 2.91 given current stage is in Bcon2.

The implementation looks good, but I do worry about add-on compatibility.

Just checking in to see if this needs to be merged in 2.91 soon so the addons can be adapted. I can revert the defaults but it would seem like an inconsistency and papercut UX inconvenience for legacy exporter add-ons when most people (not using GLTF) already have to set up their materials manually or use a custom solution due to broken/outdated infrastructure and the lack of PBR support in most interchange formats anyways. Would be a more ideal solution to update the exporters that support principled shader emission.

Thanks!

Kenzie (kenziemac130) updated this revision to Diff 27336.EditedJul 31 2020, 9:37 PM

Fixed forward compatibility issue for existing materials.

Reaching out to the comunity for input on compatibility and defaults: https://blender.community/c/rightclickselect/0cgbbc/

Kenzie (kenziemac130) planned changes to this revision.Aug 2 2020, 10:49 PM

Planning changes as @Brecht Van Lommel (brecht) stated:

We could also additionally be conservative and leave the default emission to black, and only set it to black later on when more add-ons support emission strength for export.

I also reached out to some people on Right-Click Select: "rex_kungolos" replied:

It is indeed a tough decision. Thought a bit about it and believe the best implementation would be to use "Emission Color: Black, Strength: 1". I'll try to explain why.

The principled BSDF shader is basically meant to be a shader to accomodate plug-and-play textures for any PBR texture set. People coming from any pipeline/previous software knowledge should be able to see it and know where to plug the textures for a quick test. While the controls are many the defaults are fine for most cases. Having to tweak an additional value just to make a texture work can easily get tedious,

White, Strength: 1 is the default in emission for the same reason, the node should work out of the box.

White, Strength: 0 is the default in principled Volume because quick tweaking of the color while having (ie) the flame attribute connected to the strength is a standard thing to do.

It may seem weird to think that every material will have an emission strength of 1 by default, but the issue here is the naming. Basically the strength is a multiplier of the emission color, so a value of 1 is neutral. I'm not suggesting renaming it to "Emission Strength Multiplier" (it barely fits), but maybe the hover tip could say so.

I think this is a good way of looking at it, I feel more comfortable reverting back defaults. This will also preserve compatibility with old addons and forward compatibility loading newer materials from older blender versions.

Kenzie (kenziemac130) updated this revision to Diff 27642.EditedAug 12 2020, 12:21 AM

Reverted with recommended defaults to be 100% compatible with previous blend files by default without the need for versioning. Forward compatibility completely maintained. Exporters/importers will not be broken. Thanks for the feedback!

This revision is now accepted and ready to land.Aug 12 2020, 12:21 AM

@Brecht Van Lommel (brecht) Are we able to get this merged in 2.91 soon?

It's my plan to look at this in the coming weeks. If you want to update the add-ons to take into account emission strength (which we'll need to do regardless), that would help speed things up.

It's my plan to look at this in the coming weeks. If you want to update the add-ons to take into account emission strength (which we'll need to do regardless), that would help speed things up.

Awesome! Not very familiar with Python. I can hack together some simple scripts, will have to learn a bit to do that but I will take a crack at it. Thanks!

Status Update: Working on updating the exporters.

Collada is almost done, just need to fix a clamping issue on import. The format is not the best candidate to receive emission strength due to it's "texture OR color" restriction.

Obj is under way. The current MTL code produces/loads fundamentally broken materials, I decided it would probably be best to rewrite most of it and support a PBR extension to drop this legacy technical debt before adding emission strength if time permits, otherwise I'll just copy the emission multiplier to the current MTL code.

Created tool to inspect Obj Mtl validity using TinyObj https://github.com/astrand130/ObjTest

My PC is currently under maintenance so I will return to my main work on this as soon as possible (Sep 4). Thanks!

@Brecht Van Lommel (brecht) I have investigated other exporters and am currently working on updating them. It has come to my attention that material export functionality in some exporters (particularly OBJ and FBX) are in rather poor condition and I would like to fix them. Before I am able to do that it would be very helpful if this patch could get merged and D8777 could get reviewed soon so these addons and exporters can be updated. Thank you.

Obj MTL Importer/Exporter has been updated. https://developer.blender.org/D8868

@Julien DUROURE (julien) this needs updates in glTF import/export. As noted above @astrand130 is working on updating importers and exporters, but as I understand it there is no glTF code yet, so up to you two to figure out who does it.

I am going to need to update the Collada importer to handle emission strength via RGBM encoding similar to how I am doing for OBJ in another patch.

Other than that OBJ and Collada is done. I will look into adding it to FBX tomorrow.

Thanks!

Would it be a better idea to set the socket ID to 22 (next unused socket id) rather than 18? It's breaking all existing scripts that reference socket 18 otherwise. Or does the visual order depend on the socket ID?

As explained here, scripts should use the name, there is no such thing as a unique numeric socket ID.
https://devtalk.blender.org/t/implement-new-node-parameters-without-breaking-existing-scripts/15433/6

Hello. Importer & exporter glTF is now using the new socket ( see feca8c528979 and f3cf3a16e989 )