Repository navigation
[KMC-extension] reworked intro, equation, shininess note - #1075
andreasplesch wants to merge 12 commits into
Conversation
and implementation note from draft spec.
|
Fixes #945. |
|
-1 This extension should become KHR_cmn_lights extension, as it does not fit well to PBR. For common materials, we can take it 1:1. |
|
Would it work better to complete this extension in the https://github.com/UX3D-nopper/glTF/ fork to avoid confusion ? |
|
Basically, the extension is fine for for the common materials. But for PBR materials, we need too many exceptions, that I will suggest a separate one. Sorry for the confusion. |
| "KHR_lights" : { | ||
| "lights": [ | ||
| { | ||
| "positional": [ |
There was a problem hiding this comment.
typo: I guess "positional" is supposed to be a dictionary? should be curly brackets then not square...
In the interest of expediting a material model that runs more efficiently on mobile devices, could we consider splitting this PR in two, and finishing up KHR_cmnBlinnPhong before we tackle lighting? Anecdotally, most users are using glTF for individual models, so I see blinn-phong as the more important (and perhaps less complex?) extension here. |
| |**diffuseTexture** | [`textureInfo`](/specification/2.0/README.md#reference-textureInfo) | The diffuse texture.|No| | ||
| |**specularFactor** | `number[3]` | The specular RGB color of the material. |No, default: `[1.0,1.0,1.0]`| | ||
| |**shininessFactor** | `number` | The shininess of the material.|No, default: `1.0` | | ||
| |**specularShininessTexture**| [`textureInfo`](/specification/2.0/README.md#reference-textureInfo)|The specular shininess texture.|No| |
There was a problem hiding this comment.
I assume this means specular is RGB channels, and shininess is A. We've discussed a bit in the past, and I don't remember where we ended up on this question, but there was some concern that because using RGB+A requires PNG, transmission size might actually end up worse than if two JPGs had been used (e.g. RGB + R).
|
Generally the blinn-phong proposal looks good to me. One note, three.js and A-Frame can currently support |
|
|
||
| TODO: EXPLAIN FURTHER | ||
|
|
||
| The following table lists the allowed types and ranges for the specular-glossiness model: |
There was a problem hiding this comment.
s/specular-glossiness/Blinn-Phong
| The following code illustrates the basic computation: | ||
|
|
||
| ``` | ||
| color = <emission> + <ambient> * al + <diffuse> * max(N * L, 0) + <specular> * max(H * N, 0)^<shininess> |
There was a problem hiding this comment.
on one of the other threads i did suggest adding the following (it is submitted as a PR against what i suspect is now a dead fork)
diffuseTerm = diffuseFactor * diffuseTexture
specularTerm = specularFactor * specularShininessTexture.rgb
shineTerm = shininessFactor * specularShininessTexture.a
emissiveTerm = emissiveFactor * emissiveTexture // core Materials spec
occlusionTerm = occlusionFactor * occlusionTexture // core Materials spec
color = emissiveTerm + occlusionTerm * (diffuseTerm * max(N * L, 0) + specularTerm * max(H * N, 0)^shineTerm)
where
N – Normal vector
L – Light vector
H – Half-angle vector,calculated as halfway between the unit Eye and Light vectors, using the equation H= normalize(I+L)
Textures are optional, and if provided, will modulate the base Factor value. Note that specularShininessTexture contains the specular modulation as the rgb components and shininess modulation as the alpha component.
|
If I'm reading correctly, the discussion in #947 ended with:
The logical conclusion seems to be that a constant material is flagged as such by a completely empty cmnBlinnPhong extension? In other words, just a somewhat wordy boolean opt-in. Was the explicit type really problematic? I'm all for simplified APIs, but I thought the type added clarity rather than complexity. Of course it could be argued that we should then have a cmnLambert and a cmnConstant, with correspondingly tighter schemas -- indeed, like what @donmccurdy just suggested in #1095. |
|
Thinking about this more, I am also worried about the wording:
This implies the correct way to specify a Constant material would be: {
"name": "RedConstant",
"emissiveFactor": [1, 0, 0],
"extensions": {
"KHR_materials_cmnBlinnPhong": {
"diffuseFactor": [0, 0, 0, 0],
"specularFactor": [0, 0, 0],
"shininessFactor": 0
}
}
}This doesn't feel very natural. The Constant material is identified by the presence of a blinn-phong extension, even though no factors from the blinn-phong extension are actually used. Also, we may someday want to allow animation of materials (say, opacity or color). In that case, you could define an initial diffuse state of I think we should probably be more explicit about the intended shading model, rather than having things implicitly in EDIT: So to be specific, I would recommend that we do one of two things: A. Rename this extension |
|
Some of the questions here seem to be related to what I asked about in #947 (comment) (and I hope that what I wrote there was not considered as a "proposal", considering the disclaimer: I don't know which performance implications this might have). But the point mentioned above, about the animations, is IMHO an important conceptual one: If the official statement will be that zero factors imply a different shading model, then loaders/viewers might be tempted to use (pseudo) code like (The goal of this would be (performance) optimizations, of course. I still wonder whether there will really be noticable performance differences between these imlementations, considering that even the most complex shader here is comparatively simple. But regardless of that: ) If some material value changed afterwards (be it through animations or something like a "material editor" UI component), then this would cause problems. I'm not so deeply involved here to make any proposals, but think that it might be possible to cover both directions with implementation notes:
But this is just a vague idea. |
|
i much prefer the idea of each extension being specific to its function e.g. material_blinnphong does only that. If you want a _constant material, then define another material type. |
Yes, these notes would clear up any ambiguity. The downside of the second is that (unless we add an explicit indication of shading model) there is then no option to switch to something cheaper.
I'm asking around, and while all of these shaders are comparatively simple, there are implementation differences that make a bigger difference (at least in three.js).
For the reasons above, devs will have reasons to target a specific material type. I think it's fine for engines to have Blinn-Phong and use that in all cases (let's include this implementation note), but I don't think we should omit any indication of the shading model from the format, for implementations that need to distinguish between shading models.
I'm fine with this, or with a single extension that is explicit about the shading model. Note that if split out, constant material would just be a boolean flag like |
|
I will just add a note here, redundant perhaps, but for emphasis: that the relationship between performance and shader choice is far from predictable, as it passes through the domain of aesthetic consideration and art style. I think this extension should carefully avoid accidentally encoding any assumptions about how an application might choose to downgrade shader complexity; it should simply retain as much expressive power as possible. To take our case as an example: we decided early on that the user base we're hoping to attract early on is going to be largely on mid-grade android devices. In VR, reduced frame rate is not a reasonable path for graceful adaptation -- only scene complexity is. So we embraced in all our art a low-poly, unlit, flat-shaded style. This seems like exactly the kind of deliberate decision that you would want to encode explicitly in the asset file, not leave it as an optional optimization path to the loader/viewer. |
The KHR_lights extension is treated elsewhere.
-some language -removed ambient -added occlusion and explanations
|
Although I fear that I am one of the least suitable persons to keep editing this PR, I went ahead and removed the lights extension language as it was included here by accident and adopted most (all?) of the specific suggestions made. Apologies to those I overlooked. |
| Given the long history of the Blinn-Phong model and the vast amount of collective experience with applying this model, the demand for convenient use of such materials is still exists. | ||
|
|
||
| This extension defines a single material type, Blinn-Phong. Other or simpler materials types such as Lambert or Constant can be described by having zero factors. | ||
| This extension defines a single material type, Blinn-Phong. Other or simpler materials types such as Lambert or Constant may be emulated by applying zero factors. Please note, strict Lambert or Constant materials may be specified in dedicated extensions. |
There was a problem hiding this comment.
I think I would just omit the second two sentences, so that this paragraph becomes:
Given the long history of the Blinn-Phong model and the vast amount of collective experience with applying this model, the demand for convenient use of such materials is still exists. This extension defines a single material type, Blinn-Phong.
(Mentioning that simpler materials can be emulated via Blinn-Phong can be mentioned in the extensions for those materials)
|
@andreasplesch thanks for helping to move this forward! 🙂 Your changes look good to me; I just added one additional suggestion. There's already a |
Since other potential material extensions are already referred to and Lambert/Constant extensions are being actively discussed, the removed sentences are not necessary anymore.
|
I could also resubmit this PR against another branch if that would be preferable. |
@andreasplesch Thanks, that might be best — could you resubmit this against a |
|
Closing this PR after resubmitting to as #1111 against the gltf2-common-materials branch. Happy to reopen here for any reason. |
This PR is also available as https://github.com/UX3D-nopper/glTF/pull/1 since it was based on the UX3D-nopper fork. However, the suggestion was to provide the PR against KhronosGroup/glTF .
Please feel free to edit freely or ignore all suggestions and just use as input for discussion on phrasing, language and content.