Cycles: Add thin film iridescence to Principled BSDF #118477

Merged
Lukas Stockner merged 18 commits from LukasStockner/blender:iridescence into main 2024-05-02 14:28:57 +02:00
Member

This is an implementation of thin film iridescence in the Principled BSDF based on "A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence".

There are still several open topics that are left for future work:

  • Currently, the thin film only affects dielectric Fresnel, not metallic. Properly specifying thin films on metals requires a proper conductive Fresnel term with complex IOR inputs, any attempt of trying to hack it into the F82 model we currently use for the Principled BSDF is fundamentally flawed. In the future, we'll add a node for proper conductive Fresnel, including thin films.
  • The F0/F90 control is not very elegantly implemented right now. It fundamentally works, but enabling thin film while using a Specular Tint causes a jump in appearance since the models integrate it differently. Then again, thin film interference is a physical effect, so of course a non-physical tweak doesn't play nicely with it.
  • The white point handling is currently quite crude. In short: The code computes XYZ values of the reflectance spectrum, but we'd need the XYZ values of the product of the reflectance spectrum and the neutral illuminant of the working color space. Currently, this is addressed by just dividing by the XYZ values of the illuminant, but it would be better to do a proper chromatic adaptation transform or to use the proper reference curves for the working space instead of the XYZ curves from the paper.

As an example, here's a picture of a soap bubble, using the same parameters (IOR 1.7, 400nm) as in the paper:
Screenshot from 2024-02-20 01-05-40.png

I've also compared the results to the great comparison by @PascalSchon from here and the paper supplemental material, and it matches at least in terms of overall hue.

This is an implementation of thin film iridescence in the Principled BSDF based on ["A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence"](https://belcour.github.io/blog/research/publication/2017/05/01/brdf-thin-film.html). There are still several open topics that are left for future work: - Currently, the thin film only affects dielectric Fresnel, not metallic. Properly specifying thin films on metals requires a proper conductive Fresnel term with complex IOR inputs, any attempt of trying to hack it into the F82 model we currently use for the Principled BSDF is fundamentally flawed. In the future, we'll add a node for proper conductive Fresnel, including thin films. - The F0/F90 control is not very elegantly implemented right now. It fundamentally works, but enabling thin film while using a Specular Tint causes a jump in appearance since the models integrate it differently. Then again, thin film interference is a physical effect, so of course a non-physical tweak doesn't play nicely with it. - The white point handling is currently quite crude. In short: The code computes XYZ values of the reflectance spectrum, but we'd need the XYZ values of the product of the reflectance spectrum and the neutral illuminant of the working color space. Currently, this is addressed by just dividing by the XYZ values of the illuminant, but it would be better to do a proper chromatic adaptation transform or to use the proper reference curves for the working space instead of the XYZ curves from the paper. As an example, here's a picture of a soap bubble, using the same parameters (IOR 1.7, 400nm) as in the paper: ![Screenshot from 2024-02-20 01-05-40.png](/attachments/8a049a33-1925-497c-852e-c4dab1dad8ad) I've also compared the results to the great comparison by @PascalSchon from [here](https://projects.blender.org/blender/blender/issues/99447#issuecomment-920492) and the paper supplemental material, and it matches at least in terms of overall hue.
Lukas Stockner added the
Module
Render & Cycles
label 2024-02-20 03:28:58 +01:00
Member

EEVEE rendering of the Principled BSDF is currently broken. This is of how the node inputs are being passed to node_shader_gpu_bsdf_principled. A simple fix is to just add the extra inputs to that function and leave them unused. (Your main focus seems to be Cycles, so leaving these unused at the moment is fine). Something as simple as: f666e9d034 will do at the moment.

Sorry for "reviewing" minor features while you probably want feedback on the more important stuff.

EEVEE rendering of the Principled BSDF is currently broken. This is of how the node inputs are being passed to `node_shader_gpu_bsdf_principled`. A simple fix is to just add the extra inputs to that function and leave them unused. (Your main focus seems to be Cycles, so leaving these unused at the moment is fine). Something as simple as: https://projects.blender.org/Alaska/blender/commit/f666e9d0347c3194aaab483e5e11931f4ceaa9be will do at the moment. Sorry for "reviewing" minor features while you probably want feedback on the more important stuff.
Lukas Stockner force-pushed iridescence from 4418a204f3 to d665174879 2024-02-26 05:12:21 +01:00 Compare
Author
Member

Updates:

  • Fixed EEVEE, thanks @Alaska
  • Implemented a basic approach for handling the color conversion correctly-ish. There's a slightly better approach (Von Kries-style chromatic adaption matrix) that might make sense, and a much better approach that is complete overkill (explicitly computing the Fresnel-domain reference curves).
  • The code accounts for F0 now, so the Specular Tint input has an effect (I'd really advise against combining it with Thin Film, however)
  • Overall code cleanup
  • Switched over to using the polarization-aware approach, turns out it does make a notable difference for IOR>1.5
  • Fixed a few bugs around the interaction with Fresnel
Updates: - Fixed EEVEE, thanks @Alaska - Implemented a basic approach for handling the color conversion correctly-ish. There's a slightly better approach (Von Kries-style chromatic adaption matrix) that might make sense, and a much better approach that is complete overkill (explicitly computing the Fresnel-domain reference curves). - The code accounts for F0 now, so the Specular Tint input has an effect (I'd really advise against combining it with Thin Film, however) - Overall code cleanup - Switched over to using the polarization-aware approach, turns out it does make a notable difference for IOR>1.5 - Fixed a few bugs around the interaction with Fresnel
Lukas Stockner force-pushed iridescence from d665174879 to 0dcf334003 2024-04-15 17:46:47 +02:00 Compare
Lukas Stockner changed title from WIP: Cycles: Add thin film iridescence to Principled BSDF to Cycles: Add thin film iridescence to Principled BSDF 2024-04-15 17:48:31 +02:00
Author
Member

Updates:

  • Rebased to latest main
  • Fixed handling of TIR on the bottom interface (thin film to bulk medium)
  • Fixed handling of backfacing IOR

I'm not aware of any remaining issues, so I think this is ready for review. There's things that could be improved later (the color adaption method, adding it as a standalone node etc.), but the basics are there.

Updates: - Rebased to latest `main` - Fixed handling of TIR on the bottom interface (thin film to bulk medium) - Fixed handling of backfacing IOR I'm not aware of any remaining issues, so I think this is ready for review. There's things that could be improved later (the color adaption method, adding it as a standalone node etc.), but the basics are there.
Lukas Stockner requested review from Brecht Van Lommel 2024-04-15 17:51:58 +02:00
Lukas Stockner requested review from Weizhen Huang 2024-04-15 17:51:58 +02:00
Weizhen Huang requested changes 2024-04-16 16:49:27 +02:00
Dismissed
Weizhen Huang left a comment
Member

I did not test this PR thoroughly, just had a first pass. I believe some points in you PR description is outdated, please update them.
I set up a soap bubble and it looks beatiful. I wonder what parameters should I use for coated metal?

I did not test this PR thoroughly, just had a first pass. I believe some points in you PR description is outdated, please update them. I set up a soap bubble and it looks beatiful. I wonder what parameters should I use for coated metal?
@ -383,6 +419,7 @@ ccl_device Spectrum bsdf_microfacet_estimate_albedo(KernelGlobals kg,
if (!is_zero(reflectance) && bsdf->fresnel_type == MicrofacetFresnel::GENERALIZED_SCHLICK) {
ccl_private FresnelGeneralizedSchlick *fresnel = (ccl_private FresnelGeneralizedSchlick *)
bsdf->fresnel;
/* TODO: Iridescence */
Member

What is this TODO?

What is this TODO?
Author
Member

The code here wasn't accounting for the thin film yet, this is fixed now.

The code here wasn't accounting for the thin film yet, this is fixed now.
weizhen marked this conversation as resolved
@ -238,0 +272,4 @@
}
float R123 = R12 * R23;
float r123 = sqrt(R123);
Member

Why not sqrtf() here?

Why not `sqrtf()` here?
Author
Member

Thanks, fixed.

Thanks, fixed.
weizhen marked this conversation as resolved
@ -238,0 +288,4 @@
/* Computes reflectivity (R) and phase shift (phi) for perpendicular (.x) and parallel (.y)
* polarized light. */
ccl_device_inline void fresnel_dielectric_polarized(const float cosThetaI,
Member

This function is almost identical as fresnel_dielectric() except for the phase computation, would it be practical to reuse that function? The phase computation could then be:

phi->x = float(r_s < 0.0f) * M_PI_F;
phi->y = float(r_p < 0.0f) * M_PI_F;

The existing function also returns cos_theta_t, which is needed for computing the OPD.

If it turns out to be impractical, I would then prefer that these two functions have the same structure, notation and comment, eg. snake_case, a comment indicating total internal reflection, mentioning s and p polarization (or compute r_s and r_p first, then square the result).

This function is almost identical as `fresnel_dielectric()` except for the phase computation, would it be practical to reuse that function? The phase computation could then be: ``` phi->x = float(r_s < 0.0f) * M_PI_F; phi->y = float(r_p < 0.0f) * M_PI_F; ``` The existing function also returns `cos_theta_t`, which is needed for computing the OPD. If it turns out to be impractical, I would then prefer that these two functions have the same structure, notation and comment, eg. `snake_case`, a comment indicating total internal reflection, mentioning s and p polarization (or compute `r_s` and `r_p` first, then square the result).
Author
Member

Good point, thanks, those are indeed very similar. I'll merge them together.

Comparing the two, I think I found a sign error in the current code. So far it wouldn't have mattered because we only use squared values, but it does matter for the phase.

Good point, thanks, those are indeed very similar. I'll merge them together. Comparing the two, I think I found a sign error in the current code. So far it wouldn't have mattered because we only use squared values, but it does matter for the phase.
Member

Do you mean the sign of cos_theta_t? In fresnel_dielectric() it is the angle between the surface normal and the refracted ray, hence negative, and the sign is used for refract_angle(). The result should be the same as your fresnel_dielectric_polarized(), i.e. cos_theta_i + eta * cos_theta_t < 0 is equivalent to eta1 * cosThetaI < eta2 * cosThetaT.

Do you mean the sign of `cos_theta_t`? In `fresnel_dielectric()` it is the angle between the surface normal and the refracted ray, hence negative, and the sign is used for `refract_angle()`. The result should be the same as your `fresnel_dielectric_polarized()`, i.e. `cos_theta_i + eta * cos_theta_t < 0` is equivalent to `eta1 * cosThetaI < eta2 * cosThetaT`.
Author
Member

Yes, I've noticed that and updated the code accordingly.
What I meant is that the current code does

const float r_p = (cos_theta_t + eta * cos_theta_i) / (cos_theta_t - eta * cos_theta_i);

but I think it should be

const float r_p = (cos_theta_t + eta * cos_theta_i) / (eta * cos_theta_i - cos_theta_t);

(note the sign swap in the denominator). This only sign-swaps r_p, which doesn't matter currently since the code only returns sqr(r_p).

Yes, I've noticed that and updated the code accordingly. What I meant is that the current code does ``` const float r_p = (cos_theta_t + eta * cos_theta_i) / (cos_theta_t - eta * cos_theta_i); ``` but I think it should be ``` const float r_p = (cos_theta_t + eta * cos_theta_i) / (eta * cos_theta_i - cos_theta_t); ``` (note the sign swap in the denominator). This only sign-swaps `r_p`, which doesn't matter currently since the code only returns `sqr(r_p)`.
Member

Yes, you are right, I was not paying attention to the denominator. I remember switching the order was only to make the two lines have the same structure because the sign didn't matter. Sorry for the confusion 😄

Yes, you are right, I was not paying attention to the denominator. I remember switching the order was only to make the two lines have the same structure because the sign didn't matter. Sorry for the confusion 😄
weizhen marked this conversation as resolved
@ -238,0 +331,4 @@
/* Compute angle inside the thin film (after refraction at the top interface). */
float cosTheta2_sq = 1.0f - sqr(eta1 / eta2) * (1.0f - sqr(cosTheta));
if (cosTheta2_sq < 0.0f) {
/* TIR at the top interface. */
Member

I believe we should trust fresnel_dielectric_polarized() instead of checking TIR before calling the function.

I believe we should trust `fresnel_dielectric_polarized()` instead of checking TIR before calling the function.
weizhen marked this conversation as resolved
@ -261,0 +261,4 @@
/* Panel for Thin Film settings. */
PanelDeclarationBuilder &film = b.add_panel("Thin Film").default_closed(true);
film.add_input<decl::Float>("Thin Film Thickness").default_value(0.0).min(0.0f).max(100000.0f);
Member

Specify the unit (nm).

Specify the unit (nm).
Author
Member

Good point. If we're already handling units, might as well do it properly: I've created #120900 for this, depending on what PR gets merged first I'll just update the other to tag this input correctly.

Good point. If we're already handling units, might as well do it properly: I've created #120900 for this, depending on what PR gets merged first I'll just update the other to tag this input correctly.

Default value for float socket is 0.0f by default, no reason to make this explicit.
Max value also does looks like meaningless (what for such soft max?)

Default value for float socket is `0.0f` by default, no reason to make this explicit. _Max value also does looks like meaningless (what for such soft max?)_

I think it's easier to understand the code with the default value explicit.

For soft max indeed FLT_MAX should generally be used if there is no real upper bound. But this can sometimes cause numerical precision problems, so not sure it works here.

I think it's easier to understand the code with the default value explicit. For soft max indeed `FLT_MAX` should generally be used if there is no real upper bound. But this can sometimes cause numerical precision problems, so not sure it works here.

I mean, at some point such declaration can be cleaned due to the fact this is not really necessary.

I mean, at some point such declaration can be cleaned due to the fact this is not really necessary.
weizhen marked this conversation as resolved
@ -261,0 +263,4 @@
PanelDeclarationBuilder &film = b.add_panel("Thin Film").default_closed(true);
film.add_input<decl::Float>("Thin Film Thickness").default_value(0.0).min(0.0f).max(100000.0f);
#define SOCK_THIN_FILM_THICKNESS_ID 28
film.add_input<decl::Float>("Thin Film IOR").default_value(1.3f).min(1.0f).max(1000.0f);
Member

I think we could default to the IOR of water, which is 1.33.

I think we could default to the IOR of water, which is 1.33.
weizhen marked this conversation as resolved
Lukas Stockner force-pushed iridescence from 0dcf334003 to 5921fdfc56 2024-04-22 01:53:53 +02:00 Compare
Weizhen Huang reviewed 2024-04-22 12:26:41 +02:00
@ -390,3 +425,1 @@
float z = sqrtf(fabsf((bsdf->ior - 1.0f) / (bsdf->ior + 1.0f)));
s = lookup_table_read_3D(
kg, rough, cos_NI, z, kernel_data.tables.ggx_gen_schlick_ior_s, 16, 16, 16);
/* Precomputing LUTs for thin-film iridescence isn't viable, so fall back to the specular
Member

For cognitive ease I would prefer to add an empty if (fresnel->thin_film.thickness > 0.1f) branch and put the comment there, the following block is then put in the else branch

For cognitive ease I would prefer to add an empty `if (fresnel->thin_film.thickness > 0.1f)` branch and put the comment there, the following block is then put in the `else` branch
weizhen marked this conversation as resolved
@ -39,0 +56,4 @@
}
/* Return squared amplitude to get the fraction of reflected energy. */
return make_float2(sqr(r_s), sqr(r_p));
Member

The newly added sqr() is not used, I assume you wanted to use it here?

The newly added `sqr()` is not used, I assume you wanted to use it here?
Author
Member

At first I thought that this needs to return un-squared coefficients, so I used average(sqr(fresnel_dielectric_polarized(...))) in fresnel_dielectric. But with the code as it is now, I don't think sqr(make_float2(r_s, r_p)) is much nicer than make_float2(sqr(r_s), sqr(r_p)), so we might as well not add it at all I guess.

At first I thought that this needs to return un-squared coefficients, so I used `average(sqr(fresnel_dielectric_polarized(...)))` in `fresnel_dielectric`. But with the code as it is now, I don't think `sqr(make_float2(r_s, r_p))` is much nicer than `make_float2(sqr(r_s), sqr(r_p))`, so we might as well not add it at all I guess.
weizhen marked this conversation as resolved
@ -39,0 +64,4 @@
float eta,
ccl_private float *r_cos_theta_t)
{
return average(fresnel_dielectric_polarized(cos_theta_i, eta, r_cos_theta_t, NULL));
Member

We use nullptr now.
Also, average() for float2 doesn't seem to be defined on metal 😕

We use `nullptr` now. Also, `average()` for `float2` doesn't seem to be defined on metal 😕
Author
Member

Ah, okay, I wasn't sure if that's supported on GPU but looks like it is.

Ah, okay, I wasn't sure if that's supported on GPU but looks like it is.
Member

I think the kernel is all C++ now, but not feature complete on some GPUs, not sure what exactly is supported but if buildbot doesn't complain it should be fine.

I think the kernel is all C++ now, but not feature complete on some GPUs, not sure what exactly is supported but if buildbot doesn't complain it should be fine.
weizhen marked this conversation as resolved
Weizhen Huang reviewed 2024-04-22 12:31:07 +02:00
@ -500,2 +542,3 @@
template<MicrofacetType m_type>
ccl_device Spectrum bsdf_microfacet_eval(ccl_private const ShaderClosure *sc,
ccl_device Spectrum bsdf_microfacet_eval(KernelGlobals kg,
const ShaderClosure *sc,
Member

This does not compile on Metal. Add ccl_private.

This does not compile on Metal. Add `ccl_private`.
weizhen marked this conversation as resolved
Author
Member

@blender-bot build +gpu

@blender-bot build +gpu
Brecht Van Lommel approved these changes 2024-04-24 20:51:15 +02:00
Brecht Van Lommel left a comment
Owner

The GPU tests are known to be failing currently, for everything except Cycles. So the reported failures from the latest run can be ignored.

The GPU tests are known to be failing currently, for everything except Cycles. So the reported failures from the latest run can be ignored.
Lukas Stockner force-pushed iridescence from 4453b67e5c to d149ae8550 2024-05-02 02:45:22 +02:00 Compare
Author
Member
  • Updated default IOR to 1.33
  • Fixed issue with near-parallel incidence
  • Using wavelength units
  • Rebased to latest main
- Updated default IOR to 1.33 - Fixed issue with near-parallel incidence - Using wavelength units - Rebased to latest main
Weizhen Huang approved these changes 2024-05-02 14:19:45 +02:00
Weizhen Huang left a comment
Member

Looks beautiful!

Looks beautiful!
Lukas Stockner merged commit 17f2cdd104 into main 2024-05-02 14:28:57 +02:00
Lukas Stockner deleted branch iridescence 2024-05-02 14:28:59 +02:00
Member

Should we have a test file for this?

Should we have a test file for this?
Author
Member

Yes, I can think of a few cases:

  • Reflection with thin film IOR < bulk IOR
  • Reflection with thin film IOR > bulk IOR
  • Transmission with thin film IOR < bulk IOR
  • Transmission with thin film IOR > bulk IOR
  • Transmission with bulk IOR = 1.0
  • Glossy/Transmission Color pass

The first 5 can probably be combined into one file. I'll put something together.

Yes, I can think of a few cases: - Reflection with thin film IOR < bulk IOR - Reflection with thin film IOR > bulk IOR - Transmission with thin film IOR < bulk IOR - Transmission with thin film IOR > bulk IOR - Transmission with bulk IOR = 1.0 - Glossy/Transmission Color pass The first 5 can probably be combined into one file. I'll put something together.
First-time contributor

. . . I'll put something together.

I've been looking forward to this for a week now -- still working on it?

> . . . I'll put something together. **[I've been](https://blenderartists.org/t/trying-out-the-4-2-0-alpha-thin-film-iridescence/1528296)** looking forward to this for a week now -- still working on it?
Author
Member

. . . I'll put something together.

I've been looking forward to this for a week now -- still working on it?

The test files won't be particularly useful from a user perspective, they're just for development/CI use.
There's really not much to using the feature - you just set the main IOR as usual, then you set the IOR of the thin film, then you set the thickness of the film. From there, it's just a matter of tweaking the values to get the desired look.

> > . . . I'll put something together. > > **[I've been](https://blenderartists.org/t/trying-out-the-4-2-0-alpha-thin-film-iridescence/1528296)** looking forward to this for a week now -- still working on it? The test files won't be particularly useful from a user perspective, they're just for development/CI use. There's really not much to using the feature - you just set the main IOR as usual, then you set the IOR of the thin film, then you set the thickness of the film. From there, it's just a matter of tweaking the values to get the desired look.
Member

If the usage doesn't seem straightforward, we can maybe list some example phenomena and the value ranges in the manual? Or even provide a .blend file, we do have it for Glossy BSDF.

@KickAir8p I would imagine it's more like there is a known phenomenon the user wants to model, then they could go search for the required values for base IOR, thin film IOR and film thickness. For example, if you want to model a soap bubble, the base IOR is 1.0 (air), the film IOR is 1.33 (water), and the film thickness is between 10 and 1000nm; for rock dove neck feathers the film IOR is 1.55 (keratin), the thickness is somewhere between 400 and 600nm, then you plug in some absorbing volume inside. There are also iridescent phenomena not explained by thin-film interference but can be approximated nonetheless, so the user just tweak the IORs and thickness until the material has roughly the desired look.

If the usage doesn't seem straightforward, we can maybe list some example phenomena and the value ranges in the manual? Or even provide a .blend file, we do have it for Glossy BSDF. @KickAir8p I would imagine it's more like there is a known phenomenon the user wants to model, then they could go search for the required values for base IOR, thin film IOR and film thickness. For example, if you want to model a soap bubble, the base IOR is 1.0 (air), the film IOR is 1.33 (water), and the film thickness is between 10 and 1000nm; for rock dove neck feathers the film IOR is 1.55 (keratin), the thickness is somewhere between 400 and 600nm, then you plug in some absorbing volume inside. There are also iridescent phenomena not explained by thin-film interference but can be approximated nonetheless, so the user just tweak the IORs and thickness until the material has roughly the desired look.
First-time contributor

. . . provide a .blend file, we do have it for Glossy BSDF.

Or the new Ray Portal BSDF -- I've found the test .blend files provided for that to be particularly helpful.

@KickAir8p I would imagine it's more like there is a known phenomenon the user wants to model, then they could go search for the required values for base IOR, thin film IOR and film thickness. For example, if you want to model a soap bubble . . .

I'm not asking for devs to demo every conceivable use. But it seems like there's frequently a disconnect between the technical explanations and translating those into boots-on-the-ground usage that a few basic examples in blend files can go a long way to bridge. On your soap bubble point, the top post has a picture (photo?) of a soap bubble with the assertion that this node replicates some aspects of the effect. A blend file accomplishing that would be a substantial adjunct to giving numbers in a post, especially since the blend would (of necessity) include info on the requirements of the mesh that the node is intended to shade, recommended lighting (hello Blender's forest.exr), etc.

Maybe this seems so intuitively obvious to the people who created the thing that they think only a blithering idiot would need an example blend file to get the point. Please note my blithering in this post, and this idiot will be happy to provide more if it would help.

> . . . provide a .blend file, we do have it for Glossy BSDF. Or the new Ray Portal BSDF -- I've found **[the test .blend files provided](https://projects.blender.org/blender/blender/pulls/114386)** for that to be particularly helpful. > @KickAir8p I would imagine it's more like there is a known phenomenon the user wants to model, then they could go search for the required values for base IOR, thin film IOR and film thickness. For example, if you want to model a soap bubble . . . I'm not asking for devs to demo every conceivable use. But it seems like there's frequently a disconnect between the technical explanations and translating those into boots-on-the-ground usage that a few basic examples in blend files can go a long way to bridge. On your soap bubble point, the top post has a picture (photo?) of a soap bubble with the assertion that this node replicates some aspects of the effect. A blend file accomplishing that would be a substantial adjunct to giving numbers in a post, especially since the blend would (of necessity) include info on the requirements of the mesh that the node is intended to shade, recommended lighting (hello Blender's forest.exr), etc. Maybe this seems so intuitively obvious _**to the people who created the thing**_ that they think only a blithering idiot would need an example blend file to get the point. Please note my blithering in this post, and this idiot will be happy to provide more if it would help.
Member

@KickAir8p Here's a guide on how to create a scene using thin films, focused around the bubble.

  • Model the object you want to add a thin film too. Since I am using a bubble, and I want things to be simple, I will use a simple sphere.
  • Configure your Principled BSDF for your "base material" (what's under the thin film)
    • In the case of a bubble, the "base material" is air. So that means setting transmission to 1.0, roughness to 0.0, and IOR to 1.0 or close to it.
  • Now you can add a thin film on top of your base material. This is done by:
    • Setting the thin film IOR (soap bubbles are made out of soapy water, so I will use a IOR of water, 1.33)
    • And setting the thin film thickness (soap bubble typically range between 10nm, and 1000nm), so I will pick a value between these two that looks nice, or add some variable thickness with textures.
  • Then you can start playing around with other combinations.

Here is the .blend file I created: Thin film bubble example.blend

When you start playing around, you will notice some things.

  • If the thin film IOR and base IOR are close to each other, the effect is minimal. (This is based on the physics of the real world. Due to the similar IORs, reflections off the back of the thin film are less common, reducing the interference effect of thin films that creates the colours)
  • It's much easier to see the thin film effect if the thing below/behind the thin film is dark (This is the same for reflections on any material)
  • The thin film thickness needs to be quite thick (hundreds of nanometers) to produce noticeable results. But if you go too thick, the effect disappears. This is based on the physics of thin films. The thin film needs to be quite thick because light bouncing off the top and back of the thin film interfere to increase or decrease the intensity of certain wave lengths (colours) of light. Typically the thickness needs to be near the wave lengths of visible light (380 to 700 nanometers) to produce noticeable effects.

You might be wondering, why do I use a IOR of 1.33 while the original pull request uses a IOR of 1.7 for the soap bubble. The original pull request based their example image on the example image provided in a paper about thin film rendering. And the paper probably just used an IOR of 1.7 to exaggerate the effect. I used a IOR of 1.33 because that's water. Maybe the IOR of a soapy water is 1.7 due to the soap?

@KickAir8p Here's a guide on how to create a scene using thin films, focused around the bubble. - Model the object you want to add a thin film too. Since I am using a bubble, and I want things to be simple, I will use a simple sphere. - Configure your Principled BSDF for your "base material" (what's under the thin film) - In the case of a bubble, the "base material" is air. So that means setting transmission to 1.0, roughness to 0.0, and IOR to 1.0 or close to it. - Now you can add a thin film on top of your base material. This is done by: - Setting the thin film IOR (soap bubbles are made out of soapy water, so I will use a IOR of water, 1.33) - And setting the thin film thickness (soap bubble typically range between 10nm, and 1000nm), so I will pick a value between these two that looks nice, or add some variable thickness with textures. - Then you can start playing around with other combinations. Here is the .blend file I created: [Thin film bubble example.blend](/attachments/a5ac56e4-2837-4cff-adf6-c3d441185ad0) When you start playing around, you will notice some things. - If the thin film IOR and base IOR are close to each other, the effect is minimal. (This is based on the physics of the real world. Due to the similar IORs, reflections off the back of the thin film are less common, reducing the interference effect of thin films that creates the colours) - It's much easier to see the thin film effect if the thing below/behind the thin film is dark (This is the same for reflections on any material) - The thin film thickness needs to be quite thick (hundreds of nanometers) to produce noticeable results. But if you go too thick, the effect disappears. This is based on the physics of thin films. The thin film needs to be quite thick because light bouncing off the top and back of the thin film interfere to increase or decrease the intensity of certain wave lengths (colours) of light. Typically the thickness needs to be near the wave lengths of visible light (380 to 700 nanometers) to produce noticeable effects. --- You might be wondering, why do I use a IOR of 1.33 while the original pull request uses a IOR of 1.7 for the soap bubble. The original pull request based their example image on the example image provided in a paper about thin film rendering. And the paper probably just used an IOR of 1.7 to exaggerate the effect. I used a IOR of 1.33 because that's water. Maybe the IOR of a soapy water is 1.7 due to the soap?
First-time contributor

. . . Here is the .blend file I created . . .

Appreciate it, details here.

Edited to add: test render with blend file (CC0 Public Domain) that near-replicates real-world effect is up here if it'd help.

> . . . Here is the .blend file I created . . . Appreciate it, **[details here](https://blenderartists.org/t/trying-out-the-4-2-0-alpha-thin-film-iridescence/1528296/3)**. Edited to add: test render with blend file (CC0 Public Domain) that near-replicates real-world effect is **[up here](https://blenderartists.org/t/trying-out-the-4-2-0-alpha-thin-film-iridescence/1528296/10)** if it'd help.
First-time contributor

Very nice work @LukasStockner! I just today stumbled upon this feature, but already tried it out on an example image from my Blender Conference 2022 presentation (linked as you might remember :) ).

For reference, the result of my node implementation: bubble_nodes.png
And here's the result of the Principled BSDF implementation: bubble_principled.png
I think they're very close! What impresses me even more is that your implementation finished rendering 9.4 times quicker. I'm looking forward to seeing this supported on metals as well, but very impressed so far!

The only thing I can't figure out, is the seemingly absent second 'hot spot' (reflection of the sun) from the inside of the bubble when rendered with the Principled shader.

I double-checked by turning off the HDRI that illuminates the scene, and replaced it with a sun lamp. I set the sun lamp to a power where it saturates the camera. In that case, the nodes implementation yields a significantly brighter reflection (~1000x) from the inside of the surface than the Principled implementation. See here (values of bottom highlight shown in screen shot):

Nodes:

bubble_nodes_sunlight.png

Principled:

bubble_principled_sunlight.png

Is this what we should expect, or might there be something going?
In case it's useful for anyone, here's the file with the HDRI and sun lamp + both thin film materials

Cheers,
Robert

Very nice work @LukasStockner! I just today stumbled upon this feature, but already tried it out on an example image from my Blender Conference 2022 [presentation](https://conference.blender.org/2022/presentations/1410/) (linked as you might remember :) ). For reference, the result of my node implementation: ![bubble_nodes.png](/attachments/0b19dcaa-e059-46cf-bf0c-75da71435fcc) And here's the result of the Principled BSDF implementation: ![bubble_principled.png](/attachments/a55272cb-c886-47be-812d-ebafcbb3b681) I think they're very close! What impresses me even more is that your implementation finished rendering **9.4 times quicker**. I'm looking forward to seeing this supported on metals as well, but very impressed so far! The only thing I can't figure out, is the seemingly absent second 'hot spot' (reflection of the sun) from the inside of the bubble when rendered with the Principled shader. I double-checked by turning off the HDRI that illuminates the scene, and replaced it with a sun lamp. I set the sun lamp to a power where it saturates the camera. In that case, the nodes implementation yields a significantly brighter reflection (~1000x) from the inside of the surface than the Principled implementation. See here (values of bottom highlight shown in screen shot): **Nodes:** ![bubble_nodes_sunlight.png](/attachments/315c9fe3-0dda-4843-b6b2-126ed59f7425) **Principled:** ![bubble_principled_sunlight.png](/attachments/147dbc1c-168e-4d07-b647-87095dc7e191) Is this what we should expect, or might there be something going? In case it's useful for anyone, [here's the file](https://1drv.ms/u/s!As4YW75gSl86jZIOV-iaPiY-hXAUyw?e=g6HA27) with the HDRI and sun lamp + both thin film materials Cheers, Robert
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
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
7 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#118477
No description provided.