-
-
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
Add MeshStandardMaterialSG #11038
Add MeshStandardMaterialSG #11038
Conversation
Well, let me close once. |
Updated and reopened |
Nice job. I personally do not care for your refactoring, however. You have taken an implementation detail, and pushed it up to the API and created another layer of obfuscation -- especially for users -- by creating the new As I suggested here, leave Maybe something like this: function MeshStandardMaterialSG( parameters ) {
MeshStandardMaterial.call( this );
this.defines[ 'STANDARD_SG' ] = '';
this.type = 'MeshStandardMaterialSG';
this.glossiness = 0.5;
this.specular = new Color( 0x111111 );
this.glossinessMap = null;
this.specularMap = null;
delete this.metalness;
delete this.roughness;
delete this.metalnessMap;
delete this.roughnessMap;
this.setValues( parameters );
} Yes, I understand that you can argue otherwise from a software-design standpoint. However, I expect that 99% of users will use |
OK, that makes sense. |
@@ -1,4 +1,4 @@ | |||
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP ) | |||
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP ) || defined( USE_GLOSSINESSMAP) || defined( USE_SPECULAR2MAP ) |
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.
SPECULAR2MAP
?
defined( USE_GLOSSINESSMAP ) // white space
It is unfortunate that specularMap
is used for multiple purposes. We will have to fix that. It should be RGB and represent the specular reflectance of the material.
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 I'm right, this is a related comment? #9339 (comment)
src/renderers/shaders/ShaderLib.js
Outdated
@@ -82,12 +82,15 @@ var ShaderLib = { | |||
UniformsLib.displacementmap, | |||
UniformsLib.roughnessmap, | |||
UniformsLib.metalnessmap, | |||
UniformsLib.glossinessmap, | |||
UniformsLib.fog, | |||
UniformsLib.lights, | |||
{ | |||
emissive: { value: new Color( 0x000000 ) }, | |||
roughness: { value: 0.5 }, | |||
metalness: { value: 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.
Yes, should be
metalness: { 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.
That isn't what I edited.
I already noticed that and sent another PR.
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, I saw that PR earlier. :-)
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.
Ah, ok. I understand what you meant.
…et MeshStandardMaterialSG inherit MeshStandardMaterial
Updated |
As discussed in the SFHTML5 meetup (😁), I think it'll be better if, for now, |
Alright, I wanna try that before I leave the USA! |
That suits me fine. I assume we then do not require the addition of |
Yeah, that's the idea. I personally didn't like the name and I couldn't think of a better name. At this point this is mainly for the GLTF2Loader anyway. |
Well, I couldn't make a time. |
The MeshPhong model is specular/glossy. If we merge this, we should remove MeshPhong if this is accepted. We really shouldn't have two materials that are basically the same thing. |
In light of what @bhouston said, I agree. I did not realize that was an option. Removing We could keep |
I've implemented Specular-Glossiness extension support with On the current implementation, I'll try The code would be like this,
([de]serialization would't work well with it tho) |
Done |
Sweeeet! |
@donmccurdy looks good? |
examples/js/loaders/GLTF2Loader.js
Outdated
uniforms.envMap.value = material.envMap; | ||
uniforms.normalMap.value = material.normalMap; | ||
uniforms.specularMap.value = material.specularMap; | ||
uniforms.glossinessMap.value = 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.
Do you need to add these? Maybe others?
uniforms.normalScale
uniforms.displacementMap
uniforms.displacementScale
uniforms.displacementBias
uniforms.envMapIntensity
uniforms.opacity
uniforms.offsetRepeat
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.
Oops, right.
I think we should also have them and others
for the compatibility with StandardMaterial
as much as possible.
I'll update...
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, this is a pain, but it is illustrative to show how it is done...
It is also why I prefer the oddly-named MeshStandardMaterialSG
as a built-in material over this ShaderMaterial
approach.
…with MeshStandardMaterial
Updated |
I know I have been overruled, but |
Nice work @takahirox! The implementation of this approach looks good to me, and I don't have any comment on If possible in a clean way, I might prefer to isolate the spec-gloss code in an extension object. Something like: class GLTFSpecGlossExtersion {
extendMaterialParams (params, ...) {
params.foo = bar;
// ...
}
createShaderMaterial (params) {
material = new THREE.ShaderMaterial( /* ... */ );
// ...
material.onBeforeRender = function () { /* ... */ };
return material;
}
} This helps readability IMHO, avoiding 500+ line methods, and the division is clean enough because the specification for extensions is self-contained already. But I'm OK with the code as-is, if we prefer to have all material code in one larger method. |
Lets wait to see if people actually use this workflow. |
Updated! |
Great thanks — looks good to me! |
Very nice! |
Thanks! |
examples/js/loaders/GLTF2Loader.js
Outdated
@@ -2475,6 +2464,47 @@ THREE.GLTF2Loader = ( function () { | |||
|
|||
} | |||
|
|||
// for Specular-Glossiness | |||
if ( child.material && child.material.type === 'ShaderMaterial' ) { |
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.
@takahirox Can you change this so material.type
is not used for this purpose? I do not think that pattern is used elsewhere...
In this case, it should be something like
if ( child.material && child.material.isGLTFSpecularGlossinessMaterial ) {
#10985
This PR
MeshStandardMaterialSG
which can handle glTF Specular-Glossiness extension.GLTF2Loader
support glTF Specular-Glossiness extension.You can see
MeshStandardMaterialSG
example in Inwebgl_loader_gltf2
exampleby selecting Specular-Glossiness extension with BoomBox model.
Only the difference between
MeshStandardMaterial
andMeshStandardMaterialSG
is
metalness/roughness
orspecular/glossiness
.So I made
MeshStandardMaterialCommon
and let them inherit it./cc @donmccurdy @WestLangley