-
Notifications
You must be signed in to change notification settings - Fork 252
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
Provide a super simple way for engines to add support for spec gloss #331
Comments
For what it's worth, the "lossless" conversion goes the other way. Spec/Gloss is more flexible than Metal/Rough, and there is a direct, simple conversion from metal/rough to spec/gloss, but not the other way around. See KhronosGroup/glTF#696 (comment) and some OSGjs sample code. Basically the metallic map is used to
As such, there's no lossless "reverse" conversion, since diffuse and specular could be unrelated colors, there's no way to combine them into a sensible baseColor. Also note the |
@emackey I thought this stage would provide a super simple way for engines to add support for spec gloss. What do you suggest? Engines should just natively support both? Or engines could natively support spec gloss and then convert metal rough to it? |
Yes, I believe the accepted wisdom is that for engines that want to support both, the best practice is to "natively" support PBR in the form of spec/gloss, and have a simple transformation in the fragment shader to get there from metal/rough when needed. You can see this is what OSGjs is doing. I forgot to check what |
Gotcha, thanks! |
@emackey
Perhaps the title should be edited to avoid confusion. |
Updated. |
Started thinking about this again recently. The links broke during the great extension folder re-org, here are updated links:
Looking at the formulas at the bottom of that section, I see alpha is (1 - glossiness) squared, which is the same as the roughness-squared that glTF-WebGL-PBR uses. The other formula is this:
Here it looks like we're making sure that the diffuse channel goes dark for "metals" (or anytime there's high specular, since this is not metal/rough workflow we're talking about). But I'm confused, shouldn't a standard spec/gloss workflow already have this calculation baked into the supplied diffuse map? For example, in WaterBottle's spec/gloss assets, one can clearly see a particular yellowish color of the bottle. Some pixels have this color in the diffuse map, with black in the spec map. Other pixels have this color in the spec map with black in the diffuse map. This seems very akin to the metal/rough workflow where one base color has some metal areas and some non-metal areas. But why would I take the spec/gloss version's diffuse map and re-multiply it by |
I really need to write up how I came up with the math. It's in my backlog. The gist of it is to solve for the workflow inputs given the two sets of equations for metallic-roughness and specular-glossiness. I will try to spend some time doing this.
All the implementations of spec/gloss that I've seen does this to ensure energy conservation. As far as I know, it is not baked into the diffuse map.
The original textures for the water bottle was authored with metal/rough. The spec/gloss textures were created using the exact formula in the conversion function in the link you mentioned. |
Oh I think I see. The conversion from metal/rough to spec/gloss explicitly divides out the "oneMinusMaxSpecular" part, presumably expecting the runtime to multiply that back in later, as per the Cdiff formula above. |
@lilleyse I think I understand what's needed in the shader. If you or someone can get a branch of gltf-pipeline going with the mechanical hookup of specGloss, to get those textures/factors loaded into uniforms and the corresponding metal/rough textures/factors properly ignored for such models, I think the shader changes will be fairly simple from there. Up to you if/when you want to prioritize this. In the above snippet, With these changes (applied only for spec/gloss models), |
Moved to CesiumGS/cesium#6921, |
See
The text was updated successfully, but these errors were encountered: