-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Quick KHR_materials_dispersion implementation #14501
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14501/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/14501/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/14501/merge#BCU1XR#0 |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Wanted to comment about the failed vis tests - it seems like this PR breaks the node material PBR playground. You can see it here (using the build snapshot of this PR) https://playground.babylonjs.com/?snapshot=refs/pull/14501/merge#D8AK3Z#17 |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Waiting for the CI to run without errors before reviewing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only reviewed the glTF parts. I'll leave the shader parts to @Popov72.
packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts
Show resolved
Hide resolved
packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts
Outdated
Show resolved
Hide resolved
packages/dev/serializers/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts
Outdated
Show resolved
Hide resolved
packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts
Outdated
Show resolved
Hide resolved
packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts
Outdated
Show resolved
Hide resolved
…persion.ts Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>
…_dispersion.ts Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
I have a draft sample model in the works: KhronosGroup/glTF#2340 (comment) |
Can not wait this is way too cool to see all of you here :-) |
Sorry, I'm just getting back to this. Is there a way that I can run the failing tests locally? Or see some better output? |
yes, you can run visualization tests locally or against the snapshot of this PR. If you want to run locally, first run If you want to test against the pull request (no need for the local server) you can change the environment variable CDN_BASE_URL to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
packages/dev/core/src/Shaders/ShadersInclude/pbrBlockSubSurface.fx
Outdated
Show resolved
Hide resolved
Can we merge that one? |
@bghgary ? Or else should we move it to draft |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one only tiny comment but great job on the PR @MiiBond !!!!
packages/dev/core/src/Materials/Node/Blocks/PBR/subSurfaceBlock.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the glTF parts
Sample asset of the Khronie Award, suggested by @emackey. I couldn't get it to drag-n-drop into the Babylon.js demo above, guess I need to use a Playground? Anyhow here's the asset so far, screenshot from the main Sandbox. Also in Dassault Systemes' PBR Sample Renderer:
|
I've adjusted the materials for the text a bit more, so the rear-facing text is a better match to the look of the front-facing text. I'm also able to see dispersion rendering in the Sandbox. However it only seems to appear when I disable "Use Thickness as Depth". This asset is modeled to scale, and the glass is 1cm thick, so shouldn't we be seeing more dispersion here with it enabled?
|
FYI, submitted the KhronieAward asset to the glTF Sample Assets repo: KhronosGroup/glTF-Sample-Assets#99 |
When the "use thickness as depth" option is ticked, the effect is not visible because the thickness used is too low: this is the "Max thickness value", which is 0.01 by default. If you increase this value/increase the intensity of dispersion, you should start to see something. |
@Popov72 Thanks. Actually we had some interesting discussion of this effect on this week's PBR call, and I've investigated a little bit further since then. My current thoughts are:
But now the bad news: There's no fix for only 1 opaque pass. Consider the following screenshot with "use thickness as depth" turned off: The background isn't too exciting, but I want to call out a particular tan spot on the ground, behind the swirly letter O in the middle of the Khronos logo. This same tan spot on the ground can be seen in 3 different places: You can see it through the main piece of glass, you can see it again looking through the top bevel that angles your line of sight down to the spot behind the glass, and you can see the same tan spot a third time by looking through the left-edge bevel in the glass which angles your line of sight to the right and finds the same spot behind the glass. So there are 3 lines of sight to the same background spot. But the single opaque-pass render has plastered the swirly letter O on top of the one spot, so now that logo is visible in all three locations. Long story short, I don't think there's any easy fix for this using only a single opaque pass. But it's interesting to study where the limitations are for this type of rendering (and someday this may become moot when realtime raytracing is common). |
Here's a go at implementing dispersion in the renderer as well as support for the glTF KHR_materials_dispersion extension.
I'm not completely satisfied with the implementation in the shader. It's a bit ugly but creating another function was the only way I could see to avoid duplicating lots of code.
![Screenshot 2023-11-07 at 4 26 55 PM](https://private-user-images.githubusercontent.com/1069125/281278735-34daa5bb-7225-4014-8bae-8c35c75392b8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTUyODgsIm5iZiI6MTczOTI1NDk4OCwicGF0aCI6Ii8xMDY5MTI1LzI4MTI3ODczNS0zNGRhYTViYi03MjI1LTQwMTQtOGJhZS04YzM1Yzc1MzkyYjgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMDYyMzA4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2Q2ZWVlZTE0NGZkNDY4ODk3OTMyMzc5NjUwOGNlYzdmZWE2OTc0MjlhNjk3MmRjZjU2NmNhMjFlYWI5NTg1MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.QuF0GacLUKQG58n4MqEjBf0fxa9gyuSJcMUJHyspeAw)
To mimic the dispersion effect, I compute the refraction coords 3 times with slightly different IOR's and then sample the environment refraction with each of these. The final refraction is a combination of R from the first, G from the second and B from the last.