Skip to content
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

Merged
merged 7 commits into from
Jul 14, 2022
Merged

Support for KHR_materials_ior #4429

merged 7 commits into from
Jul 14, 2022

Conversation

GSterbrant
Copy link
Contributor

@GSterbrant GSterbrant commented Jul 13, 2022

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

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

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.
Copy link
Contributor

@willeastcott willeastcott left a 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! 🌷

@mvaligursky
Copy link
Contributor

Would you have some screenshot demonstrating what it can be used for?

@GSterbrant
Copy link
Contributor Author

Added two screenshots showing both the refraction and how the specular effects change with the refraction index.

@willeastcott willeastcott added enhancement area: graphics Graphics related issue labels Jul 14, 2022
Copy link
Contributor

@mvaligursky mvaligursky left a 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.

@GSterbrant GSterbrant merged commit 28baade into main Jul 14, 2022
@@ -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));
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

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.

@GSterbrant GSterbrant deleted the gsterbrant_materials_ior branch July 14, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support glTF extension: KHR_materials_ior
4 participants