WIP: Fix #114780: Cycles: Importance sampling correction #115241

Draft
Amine Bensalem wants to merge 8 commits from HamilcarR/blender:cycles-114780_chiang-hair into main

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

Principled Chiang hair longitudinal importance sampling correction,
according to the new pbrt fix here :
https://github.com/mmp/pbrt-v3/pull/256 ,
for issue : #114780.

Edit : Fix inverted scale tilt

300s old 300 s new (fixed scale tilt) Difference
old new diff
Principled Chiang hair longitudinal importance sampling correction, according to the new pbrt fix here : https://github.com/mmp/pbrt-v3/pull/256 , for issue : #114780. Edit : Fix inverted scale tilt | 300s old |300 s new (fixed scale tilt) | Difference| |---------------|--------------------------------------------|------------------| |![old](https://projects.blender.org/attachments/d8994a13-0da7-46c9-b7f4-3e6eab5be11e)|![new](https://projects.blender.org/attachments/7f825ae7-189d-4ba3-beaa-4425cf2d81aa)|![diff](https://projects.blender.org/attachments/997cae28-65d8-45d3-880a-3cfa893e652c)|
Amine Bensalem added 1 commit 2023-11-21 16:12:09 +01:00
87d098abc0 Cycles: Fix #114780 : Importance sampling correction
Principled Chiang hair longitudinal importance sampling correction,
according to the new pbrt fix here :
https://github.com/mmp/pbrt-v3/pull/256
Iliya Katushenock changed title from WIP:Cycles: Fix #114780 : Importance sampling correction to WIP: Fix #114780: Cycles: Importance sampling correction 2023-11-21 16:18:06 +01:00
First-time contributor

The Old image has the compositor enabled while the Corrected one does not.

The Old image has the compositor enabled while the Corrected one does not.
Author
Contributor

The Old image has the compositor enabled while the Corrected one does not.

Ah it's true . sorry , I don't know what results to expect yet , it's the first time I work with BSDFs . Still working on it , but I think the second image is not valid ... when changing alpha values to 0 , I don't see any difference with the second image...
Should expect the hair to be more "glossy" like , since light doesn't scatter as much , I guess ?

> The Old image has the compositor enabled while the Corrected one does not. Ah it's true . sorry , I don't know what results to expect yet , it's the first time I work with BSDFs . Still working on it , but I think the second image is not valid ... when changing alpha values to 0 , I don't see any difference with the second image... Should expect the hair to be more "glossy" like , since light doesn't scatter as much , I guess ?
First-time contributor

There is a difference.
The fix seems to reduce color noise, improve noise for certain sections, as well as adding a bit of specularity to some areas (especially the bottom part of the image).
40sample old
40sam chiang old 4.0.0.png

There is a difference. The fix seems to reduce color noise, improve noise for certain sections, as well as adding a bit of specularity to some areas (especially the bottom part of the image). 40sample old ![40sam chiang old 4.0.0.png](/attachments/014cac00-a202-441e-b161-c6e056cb2ad2)
Author
Contributor

can you pinpoint the differences on the image if that doesn't bother you ?
For example , I can see that there's a difference in colors , this is your version :
old chiang

And the one I "corrected" :
new chiang

I'm no 3D artist , but I can see mine has some kind of a greyish look... while yours has more pronounced colors .
I also cannot find the difference in specularity

can you pinpoint the differences on the image if that doesn't bother you ? For example , I can see that there's a difference in colors , this is your version : ![old chiang](/attachments/f9d324d6-6ec8-4b74-b8ca-1df4460eefaa) And the one I "corrected" : ![new chiang](/attachments/edd0cbbf-5635-4590-908e-e0229dc5c3e5) I'm no 3D artist , but I can see mine has some kind of a greyish look... while yours has more pronounced colors . I also cannot find the difference in specularity
First-time contributor

Reduced color noise:
reduced color noise.png

Enhanced specularity (cattle is not the best example to show cuticle tilt, sheep would most likely be better, or you could try increasing the tilt to something like 25 to see if large tilts highlight the difference), this little clump of hair and the loose children around it are brighter, indicating either enhanced or different specularity (in this specific section, the secondary reflection seems to benefit the most):
specular.png

Edit, We could probably get a control reference between old and new by setting tilt to 0, since that code only(?) handles tilt.

Reduced color noise: ![reduced color noise.png](/attachments/7e19ddb2-67bc-4914-9b8a-e772af7e9fff) Enhanced specularity (cattle is not the best example to show cuticle tilt, sheep would most likely be better, or you could try increasing the tilt to something like 25 to see if large tilts highlight the difference), this little clump of hair and the loose children around it are brighter, indicating either enhanced or different specularity (in this specific section, the secondary reflection seems to benefit the most): ![specular.png](/attachments/fd6a1a33-f0f8-4e48-80de-e09bb33eae0f) Edit, We could probably get a control reference between old and new by setting tilt to 0, since that code only(?) handles tilt.
Author
Contributor

I now see the difference for the noise , but for the specularity , not at all , is it that subtle on this kind of fur ?
Edit : Also , I think the noise reduction is due to the jpeg compression algorithm , need more tests

I now see the difference for the noise , but for the specularity , not at all , is it that subtle on this kind of fur ? Edit : Also , I think the noise reduction is due to the jpeg compression algorithm , need more tests
First-time contributor

How did you make the difference image? Using the images you provide I get this
differnece.jpg

Also, could you send me/link me the build.

How did you make the `difference` image? Using the images you provide I get this ![differnece.jpg](/attachments/357cf70d-f84e-4c31-8305-3930aaa943d8) Also, could you send me/link me the build.
Author
Contributor

How did you make the difference image? Using the images you provide I get this
differnece.jpg

Hi , I just used the compositor :
diffy

Also, could you send me/link me the build.

can you tell me how to do this ? one of the makefile file ?

Edit : rendered the two bases images into .hdr files , and made another diff , I think the compression messed up my other renders when I saved them into png or jpeg...

diff

that line at the top , on the other hand is troublesome...

> How did you make the `difference` image? Using the images you provide I get this > ![differnece.jpg](/attachments/357cf70d-f84e-4c31-8305-3930aaa943d8) Hi , I just used the compositor : ![diffy](/attachments/4bee9628-9b4d-439e-a9f6-8e5a9a752a22) > Also, could you send me/link me the build. can you tell me how to do this ? one of the `makefile` file ? Edit : rendered the two bases images into .hdr files , and made another diff , I think the compression messed up my other renders when I saved them into png or jpeg... ![diff](/attachments/a86fd078-91e1-485d-a1a5-5214e5abd817) that line at the top , on the other hand is troublesome...
16 MiB
2.0 MiB
Amine Bensalem force-pushed cycles-114780_chiang-hair from 21ee5c8859 to ea85357491 2023-11-27 10:02:57 +01:00 Compare
Amine Bensalem added 4 commits 2024-02-14 06:21:57 +01:00
Amine Bensalem changed title from WIP: Fix #114780: Cycles: Importance sampling correction to Fix #114780: Cycles: Importance sampling correction 2024-02-17 08:47:25 +01:00
Iliya Katushenock added this to the Render & Cycles project 2024-02-17 13:05:10 +01:00
Brecht Van Lommel requested review from Brecht Van Lommel 2024-02-20 16:52:53 +01:00
Brecht Van Lommel requested review from Weizhen Huang 2024-02-20 16:52:53 +01:00
Weizhen Huang requested changes 2024-03-18 13:13:13 +01:00
Weizhen Huang left a comment
Member

Thank you! Sorry for the delay, somehow this PR totally slipped my attention.

The implementation looks mostly correct, however, it totally negated the behaviour of scale tilt, that's not what we want. You should add bsdf->alpha = -bsdf->alpha; in bsdf_hair_chiang_setup() (alternatively, preserve the +/- signs in hair_alpha_angles()), fix another issue I mentioned about the residual component, and update the reference images you posted in the PR. Then we can have a look how much this PR improves.

Thank you! Sorry for the delay, somehow this PR totally slipped my attention. The implementation looks mostly correct, however, it totally negated the behaviour of scale tilt, that's not what we want. You should add `bsdf->alpha = -bsdf->alpha;` in `bsdf_hair_chiang_setup()` (alternatively, preserve the +/- signs in `hair_alpha_angles()`), fix another issue I mentioned about the residual component, and update the reference images you posted in the PR. Then we can have a look how much this PR improves.
@ -225,8 +227,8 @@ ccl_device_inline void hair_attenuation(
}
/* Given the tilt angle, generate the rotated theta_i for the different bounces. */
Member

also change theta_i to theta_o in the comment.
BTW the comment is quite misleading, considering it's not generating angles but sin_angles and cos_angles.
I would prefer rewriting it as:
/* Update sin_theta_o and cos_theta_o to account for scale tilt in each bounces. */

also change `theta_i` to `theta_o` in the comment. BTW the comment is quite misleading, considering it's not generating angles but sin_angles and cos_angles. I would prefer rewriting it as: `/* Update sin_theta_o and cos_theta_o to account for scale tilt in each bounces. */`
HamilcarR marked this conversation as resolved
@ -349,2 +351,3 @@
const float3 local_O = make_float3(dot(sd->wi, X), dot(sd->wi, Y), dot(sd->wi, Z));
const float3 local_O = make_float3(
dot(sd->wi, X), dot(sd->wi, Y), dot(sd->wi, Z)); /* wo in pbrt */
Member

Put this comment above the code, add a period at the end of sentence

Put this comment above the code, add a period at the end of sentence
HamilcarR marked this conversation as resolved
@ -394,3 +393,1 @@
float cos_theta_i = cos_from_sin(sin_theta_i);
float angles[6];
float angles[6]; /* contains sinThetaOp and cosThetaOp for each ray bounce */
Member

This comment does not explain what sinThetaOp and cosThetaOp are. Maybe:
/* Updated sin_theta_o and cos_theta_o accounting for scale tilt in each bounce. */
Remember to use proper English sentence, starting with a captical letter and ending with a full-stop: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#comments
I would also prefer putting this comment above the variable.

This comment does not explain what `sinThetaOp` and `cosThetaOp` are. Maybe: `/* Updated sin_theta_o and cos_theta_o accounting for scale tilt in each bounce. */` Remember to use proper English sentence, starting with a captical letter and ending with a full-stop: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#comments I would also prefer putting this comment above the variable.
HamilcarR marked this conversation as resolved
@ -398,3 +398,1 @@
hair_alpha_angles(sin_theta_i, cos_theta_i, -bsdf->alpha, angles);
sin_theta_i = angles[2 * p];
cos_theta_i = angles[2 * p + 1];
sintheta_temp_o = angles[2 * p];
Member

I do not like this naming, because this variable has a concrete meaning and is therefore not temp, and it does not following the naming convention of the nearby code.
I suggest sin_theta_o_tilted

I do not like this naming, because this variable has a concrete meaning and is therefore not temp, and it does not following the naming convention of the nearby code. I suggest `sin_theta_o_tilted`
Author
Contributor

agreed , this was poorly named.

agreed , this was poorly named.
HamilcarR marked this conversation as resolved
@ -433,3 +435,3 @@
{
const float Mp = longitudinal_scattering(
sin_theta_i, cos_theta_i, sin_theta_o, cos_theta_o, 4.0f * bsdf->v);
sin_theta_i, cos_theta_i, sintheta_temp_o, costheta_temp_o, 4.0f * bsdf->v);
Member

In eval() we don't consider scale tilt for the residual component, we shouldn't change this behaviour here.

In `eval()` we don't consider scale tilt for the residual component, we shouldn't change this behaviour here.
HamilcarR marked this conversation as resolved
Amine Bensalem changed title from Fix #114780: Cycles: Importance sampling correction to WIP: Fix #114780: Cycles: Importance sampling correction 2024-04-25 17:54:07 +02:00
Author
Contributor

Thank you! Sorry for the delay, somehow this PR totally slipped my attention.

The implementation looks mostly correct, however, it totally negated the behaviour of scale tilt, that's not what we want. You should add bsdf->alpha = -bsdf->alpha; in bsdf_hair_chiang_setup() (alternatively, preserve the +/- signs in hair_alpha_angles()), fix another issue I mentioned about the residual component, and update the reference images you posted in the PR. Then we can have a look how much this PR improves.

Thank you for your feedback.
I'm sorry myself for the delay , tough two last months at work.
there's just one question , concerning the residual component , from my understanding , this is the last "ray" coming out of the hair, but why isn't scale tilt applied at this level ?

> Thank you! Sorry for the delay, somehow this PR totally slipped my attention. > > The implementation looks mostly correct, however, it totally negated the behaviour of scale tilt, that's not what we want. You should add `bsdf->alpha = -bsdf->alpha;` in `bsdf_hair_chiang_setup()` (alternatively, preserve the +/- signs in `hair_alpha_angles()`), fix another issue I mentioned about the residual component, and update the reference images you posted in the PR. Then we can have a look how much this PR improves. Thank you for your feedback. I'm sorry myself for the delay , tough two last months at work. there's just one question , concerning the residual component , from my understanding , this is the last "ray" coming out of the hair, but why isn't scale tilt applied at this level ?
Member

why isn't scale tilt applied at this level ?

The residual term accumulates all the contribution after TRT, and is assumed to be diffuse, so the tilt doesn't make a difference.

> why isn't scale tilt applied at this level ? The residual term accumulates all the contribution after TRT, and is assumed to be diffuse, so the tilt doesn't make a difference.
Amine Bensalem added 2 commits 2024-04-29 20:30:05 +02:00
Amine Bensalem requested review from Weizhen Huang 2024-04-30 00:41:20 +02:00
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u cycles-114780_chiang-hair:HamilcarR-cycles-114780_chiang-hair
git checkout HamilcarR-cycles-114780_chiang-hair
Sign in to join this conversation.
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 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#115241
No description provided.