-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
WebGPURenderer: Add multi-scattering energy compensation for direct lighting #32089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
28b0f00
WebGPURenderer: Add multi-scattering energy compensation for direct l…
mrdoob e485dbc
Clean up.
mrdoob 19dd702
Clean up.
mrdoob 50a00dc
Updated screenshot.
mrdoob bc371cf
Merge branch 'dev' into webgpu-multiscatter
mrdoob 94f917f
Merge branch 'dev' into webgpu-multiscatter
mrdoob 2f9fced
Updated screenshots.
mrdoob 5d2c641
Merge branch 'dev' into webgpu-multiscatter
mrdoob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import BRDF_GGX from './BRDF_GGX.js'; | ||
| import DFGApprox from './DFGApprox.js'; | ||
| import { specularColor, specularF90, roughness } from '../../core/PropertyNode.js'; | ||
|
Check warning on line 3 in src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js
|
||
| import { normalView } from '../../accessors/Normal.js'; | ||
| import { positionViewDirection } from '../../accessors/Position.js'; | ||
| import { Fn, float } from '../../tsl/TSLBase.js'; | ||
|
|
||
| // GGX BRDF with multi-scattering energy compensation for direct lighting | ||
| // This provides more accurate energy conservation, especially for rough materials | ||
| // Based on "Practical Multiple Scattering Compensation for Microfacet Models" | ||
| // https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf | ||
| const BRDF_GGX_Multiscatter = /*@__PURE__*/ Fn( ( { lightDirection, f0, f90, roughness: _roughness, f, USE_IRIDESCENCE, USE_ANISOTROPY } ) => { | ||
|
|
||
| // Single-scattering BRDF (standard GGX) | ||
| const singleScatter = BRDF_GGX( { lightDirection, f0, f90, roughness: _roughness, f, USE_IRIDESCENCE, USE_ANISOTROPY } ); | ||
|
|
||
| // Multi-scattering compensation | ||
| const dotNL = normalView.dot( lightDirection ).clamp(); | ||
| const dotNV = normalView.dot( positionViewDirection ).clamp(); | ||
|
|
||
| // Precomputed DFG values for view and light directions | ||
| const dfgV = DFGApprox( { roughness: _roughness, dotNV } ); | ||
| const dfgL = DFGApprox( { roughness: _roughness, dotNV: dotNL } ); | ||
|
|
||
| // Single-scattering energy for view and light | ||
| const FssEss_V = f0.mul( dfgV.x ).add( f90.mul( dfgV.y ) ); | ||
| const FssEss_L = f0.mul( dfgL.x ).add( f90.mul( dfgL.y ) ); | ||
|
|
||
| const Ess_V = dfgV.x.add( dfgV.y ); | ||
| const Ess_L = dfgL.x.add( dfgL.y ); | ||
|
|
||
| // Energy lost to multiple scattering | ||
| const Ems_V = float( 1.0 ).sub( Ess_V ); | ||
| const Ems_L = float( 1.0 ).sub( Ess_L ); | ||
|
|
||
| // Average Fresnel reflectance | ||
| const Favg = f0.add( f0.oneMinus().mul( 0.047619 ) ); // 1/21 | ||
|
|
||
| // Multiple scattering contribution | ||
| // Uses geometric mean of view and light contributions for better energy distribution | ||
| const Fms = FssEss_V.mul( FssEss_L ).mul( Favg ).div( float( 1.0 ).sub( Ems_V.mul( Ems_L ).mul( Favg ).mul( Favg ) ).add( 1e-5 ) ); | ||
|
|
||
| // Energy compensation factor | ||
| const compensationFactor = Ems_V.mul( Ems_L ); | ||
|
|
||
| const multiScatter = Fms.mul( compensationFactor ); | ||
|
|
||
| return singleScatter.add( multiScatter ); | ||
|
|
||
| } ); | ||
|
|
||
| export default BRDF_GGX_Multiscatter; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.