Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

OBJ renderer does not seem to use Material constants #3

Open
timmyd7777 opened this issue Oct 8, 2020 · 3 comments
Open

OBJ renderer does not seem to use Material constants #3

timmyd7777 opened this issue Oct 8, 2020 · 3 comments

Comments

@timmyd7777
Copy link

timmyd7777 commented Oct 8, 2020

This is a brilliant piece of code!

However, the OpenGL renderer does not seem to use the material constants, even though they are being read from the OBJ file. As a test, I commented out all of the texture maps in the example Chest.mtl file, leaving only the material constants Kd, Ka, Ks, Ke. For extra confirmation I changed the "diffuse" constant Kd to 0.0 1.0 0.0, to make the treasure chest appears in bright green. In every other OBJ viewer I have tried, this has the intended effect: the treasure chest appears bright (non-textured) green. However, in the example renderer provided here, the treasure chest appears featureless black.

Looking into the code, it seems that the material constants are not being passed into the vertex or fragment shaders anywhere. This is a problem for us because we have to render models that contain a mixture of textured and non-textured surfaces.

Can you provide some guidance on how to use the material constants Kd, Ka, Ks, Ke in the shaders? Or even better, add the code needed to pass them into the shaders, so they can be used for surfaces which are not textured?

Thanks again for a fantastically useful piece of work.

@timmyd7777 timmyd7777 changed the title OBJ does not seem to use Material constants OBJ renderer does not seem to use Material constants Oct 8, 2020
@rlk
Copy link
Owner

rlk commented Oct 8, 2020

You're absolutely right.

First, how this came to be: The original implementation of this library was written in the era of the OpenGL fixed-function pipeline (it's pretty old). At that time, the OBJ material model mapped easily onto the OpenGL material model. When that model was deprecated, I implemented the bare minimum GLSL necessary to accomplish what I needed at the time, and I neglected to include the materials.

It would be fairly straightforward to fix. Fortunately, the values in question are set per-material instead of per-vertex. This means that there's no material interpolation and the vertex shader doesn't need to change. They'd just need to be added as uniforms, accessible to the fragment shader, handled similarly to the AmbientLight uniform.

@timmyd7777
Copy link
Author

OK. Could I convince you to add these uniforms to the fragment shader (and also add code to pass them in from the obj's material representation) in a future release? I may take a crack at this myself over the weekend, but I'm guessing you will do a better job of this, in less time, than I will :-)

@rlk
Copy link
Owner

rlk commented Oct 9, 2020

TBH, my last release of this code was 7 years ago. My next release is unlikely to occur before the weekend.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants