-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support for KHR_materials_ior #4429
Conversation
The refraction index previously only in the backend has now been moved to the front end. Refraction should be additive to reflections, and not be part of the diffuse light. Added extension for extracting ior, which also pre-calculates f0.
Since refraction is a diffuse effect, it should be weighted against the diffuse light being diffused by the surface.
…'s inferred from the refraction index.
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.
Approving with a minor comment. This PR is a beautiful thing! 🌷
Would you have some screenshot demonstrating what it can be used for? |
Added two screenshots showing both the refraction and how the specular effects change with the refraction index. |
… let's make sure we check for it.
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.
looks really good to me.
@@ -305,13 +305,18 @@ const standard = { | |||
code.append(this._addMap("diffuse", "diffusePS", options, litShader.chunks)); | |||
func.append("getAlbedo();"); | |||
|
|||
if (options.refraction) { | |||
decl.append("float dIor;"); | |||
code.append(this._addMap("refractionIndex", "iorPS", options, litShader.chunks)); |
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.
This function assumes a full map - so you need to add all the iorPS members to material - iorPSMap, iorPSUv, iorPSTiling, iorPSOffset etc and then handle them in the shader.
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 think you mean refractionIndexMap
, refractionMapUv
, etc, right?
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.
iorPS
is the chunk name.
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.
Yes!
Though I see from https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md that refraction index is a per-material constant (not texture or vertex driven).
@GSterbrant is it even necessary to have a customisation chunk for this? Seems like ior is literally just a float per material. User can set that on javascript - no need for customising chunks etc.
Description
This PR adds support for controlling index of refraction (IOR) from the frontend of the shader chunks, adds support for the KHR_materials_ior extension, as well as precalculates the F0 specular factor with is dependent on IOR.
Fixes #3652
This image illustrates, in Y diffuse color from black to red, in X refraction index from 1 to 2.
![image](https://user-images.githubusercontent.com/107400752/178753549-687ebcd4-4be5-4602-8b52-7e8fcd79c59a.png)
This illustrates the visual change on the specular when IOR is changed, as that impacts the f0 specular component. As in the previous image, in Y diffuse color ranges from black to red, in X refraction index from 1 to 2.
![image](https://user-images.githubusercontent.com/107400752/178753637-74a2515c-4ad9-48de-a046-02e8a26b39aa.png)