-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[BREAKING] Feature: KHR_materials_anisotropy #7668
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
[BREAKING] Feature: KHR_materials_anisotropy #7668
Conversation
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.
Pull Request Overview
This PR introduces a draft implementation for KHR_materials_anisotropy in the WebGL(GLSL) pipeline, updating material properties, shaders, parsers, and examples to support anisotropy and its rotation.
- Added new material properties and texture maps for anisotropy and anisotropy rotation.
- Updated shader chunks and programs to utilize anisotropy parameters and integrate with the GGX specular branch.
- Extended the GLB material parser to handle the new anisotropy extension and updated relevant tests and examples.
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
utils/plugins/rollup-types-fixup.mjs | Added new anisotropy-related material property definitions. |
test/scene/materials/standard-material.test.mjs | Extended tests to cover anisotropy and its associated properties. |
src/scene/shader-lib/programs/standard.js | Integrated anisotropy defines into the shader generation for GGX specular. |
src/scene/shader-lib/chunks-glsl/standard/frag/stdFrontEnd.js | Included anisotropy shader chunks in the fragment front-end. |
src/scene/shader-lib/chunks-glsl/standard/frag/stdDeclaration.js | Declared anisotropy uniforms and texture allocations. |
src/scene/shader-lib/chunks-glsl/standard/frag/anisotropyRotation.js & anisotropy.js | Added new shader functions for sampling anisotropy and its rotation. |
src/scene/shader-lib/chunks-glsl/lit/frag/reflDirAniso.js | Updated reflection direction calculation to incorporate anisotropic effects. |
src/scene/shader-lib/chunks-glsl/lit/frag/lightSpecularAnisoGGX.js | Modified specular computation logic to account for anisotropy blending. |
src/scene/materials/standard-material.js | Updated material property definitions and parameter setting for anisotropy. |
src/framework/parsers/glb-parser.js | Extended GLB parsing to support anisotropy material extension. |
examples/* | Added new examples to demonstrate anisotropy strength, rotation, disc and lamp features. |
Why this PR is marked as "breaking"? If there are breaking changes to APIs, please document them in first post. We always try to avoid breaking anything public, and if that is not possible, then provide a deprecation path, so old ways still work and devs have time to migrate without forcing them with broken state. |
@Maksims I may have used the wrong meaning of “breaking”. There are no API-disruptive changes in this PR. I just wanted to communicate that the appearance of anisotropic reflections could be different than before. If it is inappropriate to add “breaking” in such a case, I will remove it. |
This looks pretty great! Some feedback:
|
I agree this should be marked as BREAKING, as the visuals of this feature enabled will be different then before. We use this flag to bring it up to attention of our users. |
Thank you for the feedback. |
#endif | ||
|
||
#ifdef STD_ANISOTROPY_TEXTURE | ||
dAnisotropy *= texture2DBias({STD_ANISOTROPY_TEXTURE_NAME}, {STD_ANISOTROPY_TEXTURE_UV}, textureBias).b; |
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.
only sample the texture one time to a temporary and get the data out, instead of twice.
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.
Fixed at d1504aa
@@ -84,6 +84,15 @@ export default /* glsl */` | |||
#include "clearCoatNormalPS" | |||
#endif | |||
|
|||
// anisotropy | |||
#ifdef LIT_SPECULAR |
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.
it'd be clener to write #if defined(LIT_SPECULAR) && defined() ....
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.
Fixed at d9bbc21
@@ -197,6 +206,14 @@ export default /* glsl */` | |||
litArgs_clearcoat_worldNormal = ccNormalW; | |||
#endif | |||
|
|||
#ifdef LIT_SPECULAR |
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.
same here
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.
Fixed at d9bbc21
#endif | ||
|
||
#ifdef STD_ANISOTROPY_TEXTURE | ||
dAnisotropy *= textureSampleBias({STD_ANISOTROPY_TEXTURE_NAME}, {STD_ANISOTROPY_TEXTURE_NAME}Sampler, {STD_ANISOTROPY_TEXTURE_UV}, uniform.textureBias).b; |
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.
same here, sample the texture once
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.
Fixed at d1504aa
@@ -85,6 +85,15 @@ export default /* wgsl */` | |||
#include "clearCoatNormalPS" | |||
#endif | |||
|
|||
// anisotropy | |||
#ifdef LIT_SPECULAR |
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 liner define pls.
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.
Fixed at d9bbc21
@@ -13,6 +13,7 @@ import blurVSMPS from '../chunks-glsl/lit/frag/blurVSM.js'; | |||
import clearCoatPS from '../chunks-glsl/standard/frag/clearCoat.js'; | |||
import clearCoatGlossPS from '../chunks-glsl/standard/frag/clearCoatGloss.js'; | |||
import clearCoatNormalPS from '../chunks-glsl/standard/frag/clearCoatNormal.js'; | |||
import anisotropyPS from '../chunks-glsl/standard/frag/anisotropy.js'; |
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.
these are sorted alphabetically
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.
Fixed at 6bdd3b2
@@ -187,6 +188,7 @@ const shaderChunksGLSL = { | |||
clearCoatPS, | |||
clearCoatGlossPS, | |||
clearCoatNormalPS, | |||
anisotropyPS, |
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.
these are sorted alphabetically
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.
Fixed at 6bdd3b2
@@ -182,6 +183,7 @@ const shaderChunksWGSL = { | |||
clearCoatPS, | |||
clearCoatGlossPS, | |||
clearCoatNormalPS, | |||
anisotropyPS, |
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.
these are sorted alphabetically
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.
Fixed at 6bdd3b2
@@ -13,6 +13,7 @@ import blurVSMPS from '../chunks-wgsl/lit/frag/blurVSM.js'; | |||
import clearCoatPS from '../chunks-wgsl/standard/frag/clearCoat.js'; | |||
import clearCoatGlossPS from '../chunks-wgsl/standard/frag/clearCoatGloss.js'; | |||
import clearCoatNormalPS from '../chunks-wgsl/standard/frag/clearCoatNormal.js'; | |||
import anisotropyPS from '../chunks-wgsl/standard/frag/anisotropy.js'; |
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.
these are sorted alphabetically
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.
Fixed at 6bdd3b2
This looks great! I added a bunch or small comments, should be easy to wrap it up now. |
Thank you for the comments. All fixed. |
by the way, you can run |
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.
Great work, thanks!
This PR is an implementation of
KHR_materials_anisotropy
.Notice
I also noticed during implementation that there seems to be a discrepancy in the results in the implementation variation of the getTBN() shader function. The code for the “object space TBN” case seems to compute a different (possibly incorrect) result than the codes for the other branches. When going through the “object space TBN” branch, the result of the anisotropic direction is the opposite of what is expected.
https://github.com/playcanvas/engine/blob/48a2276427d7860354655fdcc59f10572459e5ff/src/scene/shader-lib/chunks-glsl/lit/frag/TBN.js
I confirm I have read the contributing guidelines and signed the Contributor License Agreement.