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

Add reading/saving shaders from/to .mtl files #43

Open
ereator opened this issue Mar 11, 2022 · 7 comments
Open

Add reading/saving shaders from/to .mtl files #43

ereator opened this issue Mar 11, 2022 · 7 comments
Labels
feature request New feature or request shader Issue related to a shader or shading

Comments

@ereator
Copy link
Member

ereator commented Mar 11, 2022

Is your feature request related to a problem? Please describe.
When loading geometry from an .obj files containing multiple objects (e.g. as groups [g]) it is often the case that these objects have links to theirs materials, saved in accompanying .mtl files. Thus, it is very important to add reading / saving shaders into / from .mtl files. The description of the Wavefront material template library file format may be found at Wikipedia.

Describe the solution you'd like
Add methods load() and save() to CShader class.

@ereator ereator added feature request New feature or request shader Issue related to a shader or shading labels Mar 11, 2022
@ereator ereator changed the title [FEATURE REQUEST] Add support for Wavefront material template library .mtl files [FEATURE REQUEST] Add reading / saving shaders from / to .mtl files Mar 11, 2022
@ereator ereator changed the title [FEATURE REQUEST] Add reading / saving shaders from / to .mtl files Add reading/saving shaders from/to .mtl files Mar 11, 2022
@otmanesabir
Copy link
Collaborator

otmanesabir commented Apr 17, 2022

@ereator I would be happy to have a look at this feature request and provide a PR sometime in the near future. Is this still up for grabs?

If so, I'd go ahead and assign this to myself.

@ereator
Copy link
Member Author

ereator commented Apr 18, 2022

@otmanesabir Thank you very much for your will to help with this feature!
Yes, this is still a feature request. The idea that many models saved in .obj files have reference to corresponding .mtl files. It would be really cool to be able to serialize the shaders as well.

@otmanesabir
Copy link
Collaborator

@ereator brilliant - will have a go at this!|

Would we also want to try to directly load shaders (.mtl) if they are referenced in obj files?

@ereator
Copy link
Member Author

ereator commented Apr 19, 2022

@otmanesabir
sure, this is the main idea to load them along with geometry in .obj file

@otmanesabir
Copy link
Collaborator

@ereator
while working on this feature I found some issues that I believe are worth discussing.
Generally, parsing the files is quite straightforward and trivial. However, where we put this logic turned to be a bit more tricky. Here are the reasons:

  • The CShader class is an abstract class since it doesn't implement the shade method from the IShader interface. Therefore, one can't instantiate the CShader class.
  • Additionally, because the shade method is not implemented, then actually assigning CShader as a shader to an object will result in no results showing.

I've considered moving this loading logic to the CShaderGeneral; however, I soon realized that we rely mostly on coefficients in order to simulate the shader results. The coefficients for ambient and diffuse components are unavailable in MTL files since they only provide the colors. I've considered loading the colors externally (i.e.: provided by the user) and then passing the coefficients separately but this will make it difficult to load ready-to-go objects on the fly with their textures/shaders ready to go as well.

Any thoughts on these issues? Or how we can approach this here?

@ereator
Copy link
Member Author

ereator commented Apr 23, 2022

@otmanesabir
I think this feature may be implemented in a few stages - during the implementation, I hope it will become clearer what and where should be placed.
Maybe it makes sense to put the implementation first in CShaderPhong class... It already contains the most important coefficients as ks, ka, etc. Textures in .mtl files at the beginning may be completely ignored. So, every time when material appears in .obj file, we can create a new Phong shader and then apply it to a solid, corresponding to a group in the .obj file...

@otmanesabir
Copy link
Collaborator

otmanesabir commented Apr 23, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request shader Issue related to a shader or shading
Projects
None yet
Development

No branches or pull requests

2 participants