Skip to content
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

Common Materials Extension #424

Closed
tparisi opened this issue Oct 6, 2015 · 95 comments
Closed

Common Materials Extension #424

tparisi opened this issue Oct 6, 2015 · 95 comments

Comments

@tparisi
Copy link
Contributor

tparisi commented Oct 6, 2015

https://github.com/KhronosGroup/glTF/tree/KHR_materials_common/extensions/Khronos/KHR_materials_common

Comments:

  • The JSON examples are inconsistent. Both 1 and 1.0 are used. Arrays are sometimes on the same line and sometimes one element per line.
  • index_of_refraction -> indexOfRefraction. glTF uses camel case for property names.
    • Same for constant_attenuation, linear_attenuation, falloff_angle, and falloff_exponent.
  • Are we sure CONSTANT needs all those properties? How is each used?
  • FLOAT_VEC4 or SAMPLER_2D -> In glTF, what is sampler 2D? Shouldn't this be a string (texture id)? We need to precisely define where the texture coordinates come from, e.g., if both diffuse and specular are texures, do they use the same or different set of texture coordinates?
  • technique - why does this have a default? Perhaps it should be required. We should also make this separate from the table and say the table is for the values object.
  • "relective": "texture_envmap" - glTF does not support cube maps.
  • This needs to include the equations.
  • This needs to include some discussion on how vertex attributes use semantics to map material inputs, e.g., normals, texture coordinates, etc.

To-do: Patrick need schema for each of the material types... can you help?

Maybe, but I did to finish the core spec reference doc first. Will let you know later this week.

@tparisi
Copy link
Contributor Author

tparisi commented Oct 6, 2015

Related to #84

@tparisi
Copy link
Contributor Author

tparisi commented Oct 6, 2015

@pjcozzi yes to all of the above. did we decide to punt on environment maps? guess i missed the memo.

for these two items, yes but it will take a little time to do these

  • This needs to include the equations.
  • This needs to include some discussion on how vertex attributes use semantics to map material inputs, e.g., normals, texture coordinates, etc.

@pjcozzi
Copy link
Member

pjcozzi commented Oct 6, 2015

did we decide to punt on environment maps?

See #266

@pjcozzi
Copy link
Member

pjcozzi commented Oct 8, 2015

@tparisi any update here?

@tfili
Copy link

tfili commented Oct 9, 2015

@tparisi Do we really need a separate transparency value? Shouldn't that just be part of the colors?

@mlimper
Copy link
Contributor

mlimper commented Oct 12, 2015

thanks, after reading over the draft I would say this is exactly the kind of compact, basic material definition which we have been missing wihin glTF so far... definitely very helpful, thanks a lot for the great work!

@pjcozzi
Copy link
Member

pjcozzi commented Oct 12, 2015

@mlimper any chance you could implement this soon? Your feedback would be valuable to help tighten up the spec.

@mlimper
Copy link
Contributor

mlimper commented Oct 12, 2015

What we would like to implement is a very simple material model to transport colors of the parts - here, the CONSTANT, BLINN, PHONG, and LAMBERT models seem like a perfect match.

I guess it could also be okay to use only PHONG or BLINN instead of using both, and maybe even LAMBERT could be left out, for the sake of simplicity, so that there is only CONSTANT and BLINN, for instance (since LAMBERT is just the diffuse part of PHONG / BLINN).
Otherwise, if there are different models and some have a specular component, maybe these ones should not have zero specualr by default (so it makes a difference whether you use default LAMBERT or PHONG/BLINN)?

Apart from that, my main question would be how exactly the lights fit in. We'll not want to use them within our system (although that doesn't necessarily mean they shouldn't be there), we'd only transport material information. One obvious possibility could move the lights out of this proposal and put them into a separate extension, but maybe that's too much and it's okay if they are optional.

@pjcozzi
Copy link
Member

pjcozzi commented Oct 12, 2015

We also need prose for generating shaders with skinning.

@tparisi
Copy link
Contributor Author

tparisi commented Oct 12, 2015

@mlimper let's not separate out lights, too complex. Let's instead define that an implementation's use of lights is optional, but if it does use them it needs to implement them correctly (or words to that effect)

@tparisi
Copy link
Contributor Author

tparisi commented Oct 12, 2015

@tfili no we want to keep transparency separate.

tparisi added a commit that referenced this issue Oct 12, 2015
@tparisi
Copy link
Contributor Author

tparisi commented Oct 12, 2015

@pjcozzi @mlimper all requested changes are in except the lighting calculations, that's next.

Please review the last few commits and LMK. I'm actually wondering about this 'optional lights' issue... it's sort of like cameras in the base glTF. What is a conforming implementation obligated to do? I feel like for both cameras and lights the use of them should be optional, but obviously, if they are used they need to be implemented to spec. Thoughts?

@tparisi
Copy link
Contributor Author

tparisi commented Oct 12, 2015

First attempt at lighting calculations are in (see 4126edf) - please review

@mlimper
Copy link
Contributor

mlimper commented Oct 13, 2015

What is a conforming implementation obligated to do? I feel like for both cameras and lights the use of them should be optional, but obviously, if they are used they need to be implemented to spec. Thoughts?

Well, to be honest, I guess we would not implement lights from glTF, or at least they would get a very low priority, since we usually integrate data from multiple sources to show everythin in a common context. If we would also import lights with every asset, it would all become a huge mess. So, that would probably mean our implementation would not be 100% spec conformant, I guess...

The conceptual problem here, and also with other things such as Cameras, is probably that glTF tries to be a format for both: Defining a single asset, and defining a complete scene setup. It's a problem of scope, lights and cameras often have a global scope, I guess, while meshes can be perfectly seen as something that can be integrated into an existing scene. However, it might not even be that clear for all cases: if a light is supposed to model the sun, it makes sense to ignore it when integrating an asset into an existing scene. In contrast, if a light is supposed to model one of the headlights of a car, attached to the model, it makes probably sense to load it, even if the current context already has lighting.

@pjcozzi What is your approach in Cesium? What would happen if I would try to import an asset that has lights into an existing world?

Possible conclusion: Some frameworks might want to ignore lights that have a global scope. Probably, all frameworks should be able to load lights that have a local scope, if they want to be spec-conformant. Therefore, one could add this scoping property to lights, to separate what is "scene data" and what is "asset data"... (maybe this also makes sense for other properties, such as camera viewpoints?)

Another thing that could make sense is that the glTF spec provides a list of all existing features, such as "meshes", "lights", "cameras", ... . An implementation can then provide a list of features it supports. On top of that, one could identify certain feature sets as "support level X" or "profile Y", to ease communication about the state of an implementation.

@tfili
Copy link

tfili commented Oct 14, 2015

@tparisi Looking at technique.parameters shouldn't the node property be moved into an extension object. It looks like it was removed from the core spec, but I don't see it in the extension spec.

@tparisi
Copy link
Contributor Author

tparisi commented Oct 14, 2015

@tfili good catch. Please make sure the converter does this and I will update the extension spec.

@tfili
Copy link

tfili commented Oct 15, 2015

@tparisi @pjcozzi In the converter generated shaders we look in the collada extra tags for double sided lighting and we respect that. It's used by a bunch exporters. Do we want to add this in the extension spec so we can generate the correct shaders or should I output it in the extras tag of the extension?

@tparisi
Copy link
Contributor Author

tparisi commented Oct 15, 2015

I personally think we should just put double-sided into the values. Extras is just another added level of nonsense. @pjcozzi what do you think?

@tfili
Copy link

tfili commented Oct 15, 2015

I agree. Also one issue I'm running into is knowing if an image has transparency. When I get the glTF it just has the extension, so I have to generate techniques/shaders/etc, but I can't correctly detect the states at that point. I would have to wait for the image to load and figure it out. That is very difficult with our workflow. The converter however knows this already, so adding a property there would be much easier. For values that take a color or string, maybe have that be an color or object instead like this

"diffuse" : {
    "texture": "texture1",
    "transparent": true
}

@pjcozzi
Copy link
Member

pjcozzi commented Oct 15, 2015

I personally think we should just put double-sided into the values. Extras is just another added level of nonsense. @pjcozzi what do you think?

OK.

@pjcozzi
Copy link
Member

pjcozzi commented Oct 15, 2015

As for if lights should be required, I suggest that we allow an asset to not have any lights, in which case, the engine is free to use their own lights, e.g., in Cesium, it would be the sun. If an asset contains lights, then the engine is required to generate a shader that uses those lights and any engine-specific lights it has. The Cesium team can make an open-source library to generate the shaders based on @tfili's work.

In the short-term, lights in an asset are not a big deal for Cesium; longer term, we would use them for lights on satellites, aircrafts, trucks, etc.

@tfili what do you think based on your experience implementing this extension so far?

@pjcozzi
Copy link
Member

pjcozzi commented Oct 15, 2015

The intro says "BLINN" means "Blinn-Phong" but the Blinn section says it means "Blinn-Torrance-Sparrow." Which is it? Why not just stock Blinn-Phong? @tfili is looking at Three, Babylon, etc. to see what they implement, e.g., they might need to implement another a new material if glTF uses Blinn-Torrance-Sparrow and their engine doesn't.

@tfili
Copy link

tfili commented Oct 28, 2015

Ok, that works for me. I'm working on the implementation now.

@tfili
Copy link

tfili commented Oct 28, 2015

I've finished the converter and Cesium implementations. The things that should be updated in the spec are:

  • Added doubleSided to the material (this was discussed and implemented before but never put in the spec).
  • Added transparent to the material.
  • Made all values an object with the properties type & value

@tparisi @pjcozzi Is there anything else?

@pjcozzi
Copy link
Member

pjcozzi commented Oct 28, 2015

Nothing else from me.

@tparisi
Copy link
Contributor Author

tparisi commented Oct 28, 2015

Hi @tfili good catches.

Do you or @pjcozzi definitively know the render states that go with both of these flags? If so I'll also add that language. Pretty sure it's CULL_FACE disabled for doubleSided, what about for transparency? I imagine it's a combo, please advise on spec language...

@pjcozzi
Copy link
Member

pjcozzi commented Oct 29, 2015

@tparisi
Copy link
Contributor Author

tparisi commented Oct 29, 2015

@tfili @pjcozzi LMK when we have the models converted and I'll start on the Three.js loader. Are we doing it in master or the materials branch?

@pjcozzi
Copy link
Member

pjcozzi commented Oct 29, 2015

OK, we'll open a pull request into master with the models. The issue is #448.

@tparisi
Copy link
Contributor Author

tparisi commented Oct 29, 2015

I think the PR should be off the materials branch and then we'll merge back into master once everything is sorted out with the Three.js importer

@pjcozzi
Copy link
Member

pjcozzi commented Oct 29, 2015

OK, we'll target the pull request to the materials branch.

@tfili
Copy link

tfili commented Oct 29, 2015

PR in #468

@tparisi
Copy link
Contributor Author

tparisi commented Nov 5, 2015

Just checked in language for doubleSided and transparent please review @pjcozzi

@pjcozzi
Copy link
Member

pjcozzi commented Nov 9, 2015

transparency update looks good. doubleSided needs to mention to flip the normal for backfacing triangles. For example, here is @tfili's implementation:

            if (khrMaterialsCommon.doubleSided) {
                fragmentShader += '  if (gl_FrontFacing == false)\n';
                fragmentShader += '  {\n';
                fragmentShader += '    normal = -normal;\n';
                fragmentShader += '  }\n';
            }

@pjcozzi
Copy link
Member

pjcozzi commented Jan 11, 2016

To finish this, I believe there are the following outstanding issues:

@tparisi @tfili @mlimper is there anything else?

@mlimper
Copy link
Contributor

mlimper commented Jan 12, 2016

I think that's it

@tparisi
Copy link
Contributor Author

tparisi commented Jan 12, 2016

We can close #510 and #509 - but #523 are we sure about removing type? see
my comment

On Tue, Jan 12, 2016 at 1:36 AM, Max Limper notifications@github.com
wrote:

I think that's it


Reply to this email directly or view it on GitHub
#424 (comment).

Tony Parisi tparisi@gmail.com
Follow me on Twitter! http://twitter.com/auradeluxe
Read my blog at http://www.tonyparisi.com/
Learn WebGL http://learningwebgl.com/
Mobile 415.902.8002
Skype auradeluxe

Read my books!
Learning Virtual Reality
http://www.amazon.com/Learning-Virtual-Reality-Experiences-Applications/dp/1491922834

Programming 3D Applications in HTML5 and
WebGLhttp://www.amazon.com/Programming-Applications-HTML5-WebGL-Visualization/dp/1449362966
http://www.amazon.com/Programming-Applications-HTML5-WebGL-Visualization/dp/1449362966WebGL,
Up and Running

http://www.amazon.com/dp/144932357X

@mlimper
Copy link
Contributor

mlimper commented Jan 13, 2016

If it would be updated in the examples, it would facilitate implementation and increase compatibility
(Basically, we are staying with your initial proposal #424 (comment))

@pjcozzi
Copy link
Member

pjcozzi commented Jan 13, 2016

We are going to update the samples, see #523 (comment)

@yyc-git
Copy link

yyc-git commented Feb 4, 2016

Hello!
Does KHR_materials_common support normal map? I don't see the field in KHR_materials_common.
Thank you~

@tfili
Copy link

tfili commented Feb 4, 2016

It doesn't. It's meant to mimic Collada's common profile that supports basic lighting models (constant, lambert, blinn and phong). For more advanced techniques you'll have to provide shaders.

@yyc-git
Copy link

yyc-git commented Feb 4, 2016

Thanks for your reply.

For more advanced techniques you'll have to provide shaders.

provide shaders? You mean that I should use the shader generated by gltf converter? Or How can I provide shader?

In my case, I just want to use my shader generated by my engine instead of using the shader provided by gltf converter. My shader supports normal map.
So How can I read normap map data from .gltf file? Could you give me some suggestions? Thanks.

@tparisi
Copy link
Contributor Author

tparisi commented Feb 4, 2016

Hi YYC

You will need to create your own extension. Info here:

https://github.com/KhronosGroup/glTF/blob/master/extensions/README.md

Yours would be a "vendor extension."

I can envision that we would someday add normal maps to the common materials extension. So maybe you can think about designing your extension for eventual inclusion in a future version of the KHR_ extension. We can't make about promises about that right now, but please keep the idea in mind while you are designing your feature and let's talk about it soon...

@yyc-git
Copy link

yyc-git commented Feb 4, 2016

OK, I get it, thanks a lot~

@pjcozzi
Copy link
Member

pjcozzi commented Jul 16, 2017

@McNopper OK to close as duplicate with #947 and #945?

@pjcozzi
Copy link
Member

pjcozzi commented Dec 23, 2017

I believe this it is OK to close this as now duplicate with #1163 and friends.

@donmccurdy please let me know if you think otherwise.

@pjcozzi pjcozzi closed this as completed Dec 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants