Cycles: Add thin film iridescence to Principled BSDF #118477
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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 project
No Assignees
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118477
Loading…
Reference in New Issue
No description provided.
Delete Branch "LukasStockner/blender:iridescence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a WIP implementation of thin film iridescence in the Principled BSDF based on "A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence".
There's still several open topics:
generalized_schlick
OSL closure, by using the sign of the IOR as a flag (which is already hacky anyways). The Principled BSDF doesn't need the F90 control, so we could have a Principled-specific mode without F90 that does iridescence and a Generalized Schlick mode with F90 that doesn't.(1, 1, 1)
in XYZ, it must map to 100% reflectivity(1, 1, 1)
in RGB - but XYZ(1, 1, 1)
maps to yellow-ish if the usual conversion to sRGB is used.For now, here's a picture of a soap bubble, using the same parameters (IOR 1.7, 400nm) as in the paper:
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.
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.
4418a204f3
tod665174879
Updates:
d665174879
to0dcf334003
WIP: Cycles: Add thin film iridescence to Principled BSDFto Cycles: Add thin film iridescence to Principled BSDFUpdates:
main
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.
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 */
What is this TODO?
The code here wasn't accounting for the thin film yet, this is fixed now.
@ -238,0 +272,4 @@
}
float R123 = R12 * R23;
float r123 = sqrt(R123);
Why not
sqrtf()
here?Thanks, fixed.
@ -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,
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: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 computer_s
andr_p
first, then square the result).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.
Do you mean the sign of
cos_theta_t
? Infresnel_dielectric()
it is the angle between the surface normal and the refracted ray, hence negative, and the sign is used forrefract_angle()
. The result should be the same as yourfresnel_dielectric_polarized()
, i.e.cos_theta_i + eta * cos_theta_t < 0
is equivalent toeta1 * cosThetaI < eta2 * cosThetaT
.Yes, I've noticed that and updated the code accordingly.
What I meant is that the current code does
but I think it should be
(note the sign swap in the denominator). This only sign-swaps
r_p
, which doesn't matter currently since the code only returnssqr(r_p)
.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 😄
@ -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. */
I believe we should trust
fresnel_dielectric_polarized()
instead of checking TIR before calling the function.@ -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);
Specify the unit (nm).
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?)
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.
@ -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);
I think we could default to the IOR of water, which is 1.33.
0dcf334003
to5921fdfc56
@ -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
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 theelse
branch@ -39,0 +56,4 @@
}
/* Return squared amplitude to get the fraction of reflected energy. */
return make_float2(sqr(r_s), sqr(r_p));
The newly added
sqr()
is not used, I assume you wanted to use it here?At first I thought that this needs to return un-squared coefficients, so I used
average(sqr(fresnel_dielectric_polarized(...)))
infresnel_dielectric
. But with the code as it is now, I don't thinksqr(make_float2(r_s, r_p))
is much nicer thanmake_float2(sqr(r_s), sqr(r_p))
, so we might as well not add it at all I guess.@ -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));
We use
nullptr
now.Also,
average()
forfloat2
doesn't seem to be defined on metal 😕Ah, okay, I wasn't sure if that's supported on GPU but looks like it is.
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.
@ -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,
This does not compile on Metal. Add
ccl_private
.@blender-bot build +gpu
The GPU tests are known to be failing currently, for everything except Cycles. So the reported failures from the latest run can be ignored.
Checkout
From your project repository, check out a new branch and test the changes.