-
-
Notifications
You must be signed in to change notification settings - Fork 35.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
GLTFLoader: Remove onBeforeRender dependency #14099
GLTFLoader: Remove onBeforeRender dependency #14099
Conversation
Yes, I am inclined to agree that doing so is better than creating a custom |
I agree, however, I mustered up an API example that is slightly less tedious and better suited for automation. #14031. Unfortunately i didn't realize that there were lint issues with the GLTF loader so when i linted the entire file, it made the diff look scary. But this example should be cleaner. Slightly cleaner PR to look at might be #13198 I think for the time being, it's a way to leverage more of the existing code, remove some redundancy and and decouple some concerns within the existing system. |
examples/js/loaders/GLTFLoader.js
Outdated
shader.fragmentShader = shader.fragmentShader.replace( '#include <metalnessmap_fragment>', params.chunks.glossinessMapFragmentChunk ); | ||
shader.fragmentShader = shader.fragmentShader.replace( '#include <lights_physical_fragment>', params.chunks.lightPhysicalFragmentChunk ); | ||
|
||
}; |
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.
Would this still work if we extend MeshStandardMaterial with a new type, GLTFMeshStandardSGMaterial
, and set GLTFMeshStandardSGMaterial.prototype.onBeforeCompile
?
function GLTFMeshStandardSGMaterial (params) {
MeshStandardMaterial.call(this, params);
material.userData.extraUniforms = {
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: params.uniforms
};
}
It would be nice to be able to return a normal constructor from getMaterialType
, or at minimum to have an .isGLTFMeshStandardSGMaterial===true
flag on the material for GLTFExporter to find.
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'm not sure about the prototype, i think it might have to be bound in the constructor. This is one of those gotchas that i always have to console.log
. I don't think onBeforeCompile
exists on the prototype object at all.
Ideally i would like to not have to keep onBeforeCompile
for too long in lieu of material includes. But for now, if this works, yes i think a new class is the best way to handle this.
examples/js/loaders/GLTFLoader.js
Outdated
glossiness: { value: 0.5 }, | ||
specularMap: { value: null }, | ||
glossinessMap: { value: null } | ||
}; |
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 realize this isn't new with your changes, but let's use the defaults from the extension spec:
specular: 0xffffff
glossiness: 1.0
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.
Will do, if this looks good i can proceed to clean this diff up a bit. This is being set to that default somewhere else though, but that's probably cruft, it should be here. I also realized i haven't actually removed the onBeforeRender
, there should be no mention of it in this file.
Nice work. I don't really like the current specular-glossiness material implementation, especially I tried The current implementation has another issue.
This solution can also solve this issue. |
It's as tricky to clone something with I do have concerns though about Would you be open to giving this other API some support after this lands? |
examples/js/loaders/GLTFLoader.js
Outdated
@@ -728,15 +759,20 @@ THREE.GLTFLoader = ( function () { | |||
material.glossinessMap = params.glossinessMap === undefined ? null : params.glossinessMap; | |||
material.glossiness = params.glossiness; | |||
|
|||
if ( material.glossinessMap ) { |
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.
im not sure what to do about this
And maybe link this here: I'm not a CS person, but i'm trying to learn, i've been curious about the callback, why it makes sense, why it doesn't. I'm not sure where this implementation falls. |
The further this is pushed out the more work it causes. Conflicts were solved already. |
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.
Agreed that this improves the loader.
I want to test this on a few models still, but would like to work toward merging this.
examples/js/loaders/GLTFLoader.js
Outdated
* @pailhead | ||
*/ | ||
|
||
function SpecularGlossinessPbrMaterial( params ) { |
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 we discussed possible names if a spec/gloss PBR material were added to three.js once before, and MeshStandardSGMaterial was the candidate? Perhaps let's use that.
examples/js/loaders/GLTFLoader.js
Outdated
].join( '\n' ); | ||
|
||
var uniforms = { | ||
specular: { value: new THREE.Color().setHex( 0x111111 ) }, |
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.
Not a new issue with your code I realize, but could you make this 0xFFFFFF
to match the spec?
examples/js/loaders/GLTFLoader.js
Outdated
|
||
var uniforms = { | ||
specular: { value: new THREE.Color().setHex( 0x111111 ) }, | ||
glossiness: { value: 0.5 }, |
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.
Similarly, default in glTF should be 1.0 here.
this._extraUniforms = uniforms; | ||
|
||
// please see #14031 or #13198 for an alternate approach | ||
this.onBeforeCompile = function ( 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.
If we put onBeforeCompile
on the SpecularGlossinessPbrMaterial prototype, does it still work? Having it support cloning would probably make sense in this case.
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’m not sure I think it won’t like the prototype. But cloning this should still work since it calls the constructor. I’ll rename these look at the conflict and see where it leads us. Thank you.
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.
Ok, this looks good as-is.
6204e49
to
c9b7607
Compare
rebase yeey. With the messed up branch i had, it was even more fun. I think it's fixed now, and i've addressed the naming. @donmccurdy |
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 good to me, thanks! 👍
You can also remove the now-unused cloneMaterial
helper function.
this._extraUniforms = uniforms; | ||
|
||
// please see #14031 or #13198 for an alternate approach | ||
this.onBeforeCompile = function ( 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.
Ok, this looks good as-is.
nuked |
|
||
}; | ||
|
||
Object.defineProperties( |
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.
do you think it would be ok to add /*eslint-disable*/
for these lines, they're reaaaaly spaced out for getters and setters?
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.
Perhaps use one-liners like get: function () { return uniforms.specularMap.value; }
? I'd be fine with that yeah. 👍
|
||
uniforms.glossinessMap.value = v; | ||
//how about something like this - @pailhead | ||
if ( v ) { |
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.
@donmccurdy did you catch this? It's a little bit quirky i think, since needsUpdate
is also probably needed. I see two issues here, the general pattern with three.js when refreshing shaders, and then these defines in particular.
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.
Oh thanks for calling that out, and the comment about USE_ROUGHNESSMAP. Requiring needsUpdate
seems fine / I don't have any better ideas. 👍
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.
Excellent! Call it done for now :)
Is this still relevant? I can fix the conflicts but sinceI've fixed them several times in the past 15 months, it'd be cool if one of these milestones were actually upheld :) |
I'll let @takahirox and @donmccurdy decide if it's still relevant. |
Damn, sorry I didn’t know this would be such a tough one. |
Um, seems it's not. If this refactoring is still wanted, I suggest to create a new PR from scratch. |
Could it please be elaborated a bit what made this irrelevant and what should the new PR created from scratch contain? Is it just the conflicts? I think it was fine conflict wise during these R103 period and was approved but didn’t make it. Some pointers for the new PR if it’s needed at all would be useful :) Thank you! |
I've approved the PR, as it meaningfully simplifies the current code — I have no concerns with the changes. |
Yes. |
Also, I feel @takahirox no longer has time to review |
Sweet thank you for the info! I can look into this by the end of this week. |
It looks like i'm unable to reopen this though. |
@pailhead Thanks for fixing my issue before it even appeared! I fixed your conflicts and your work was just merged at long last, so you're welcome to close this one. Sorry for the wait. |
@elalish Merging your PR merged this PR 😀 |
@pailhead Thank you ! :-) |
Per conversation with @mrdoob.
Refactor
GLTFLoader
to remove theonBeforeRender
dependency withonBeforeCompile
dependency. It seems to make more sense to have the material manage the uniforms, rather than a scene graph node.Ideally i would not use
onBeforeCompile
but an alternate approach where different systems of theWebGLRenderer
could be leveraged. But this is a step.The linter should maybe be run in this file, as it's got a lot of complaints in the dev branch.
ping @takahirox @donmccurdy