Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (790)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LWJGL] How to handle separate OBJ Groups and their materials  (Read 701 times)
0 Members and 1 Guest are viewing this topic.
Offline QuicK2800

Senior Newbie


Medals: 1
Exp: 4 years



« Posted 2019-05-21 21:32:27 »

OBJ File structure allows for groups of faces to have a single material attached to them.
I have written a parser which separates groups and they each have their own material.

How can I go about getting that data to the shader?
I figure my two options are:

1) Load them in as a vertex array object attribute
2) Load them in as uniform variables

The only way I know how to implement option 1 is to load an array of material data for every vertex which seems to be a LOT of extra information. Is there a way to point to the current group's material while it's being drawn and then switch to a new material for the next group? Or, is there something I'm missing completely?

Option 2 doesn't seem viable because it seems to persist throughout the whole draw call.

Any information would be greatly appreciated.

Thanks,

~QuicK
Offline KaiHH

JGO Kernel


Medals: 686



« Reply #1 - Posted 2019-05-21 22:11:46 »

The easiest would be to use separate draw calls with different uniform buffers (for material colors) and texture unit bindings (for the different texture - if your MTL material contains texture maps).
It is also possible to cram all information into a single draw call using indexed access with a uniform array in the shader (write the actual material colors into uniform buffer and encode the index to use as an integer vertex attribute) and sampling from different texture units (encode the texture unit to use as a vertex attribute as well).
If you target ever higher OpenGL versions and more capable hardware, more options open up.
Offline QuicK2800

Senior Newbie


Medals: 1
Exp: 4 years



« Reply #2 - Posted 2019-05-22 11:59:25 »

Thank you for the fast response!

So, considering your first option:
Suppose I have a model which has two groups: a character body and a metal arm
I would batch render all of the character bodies and then all of the metal arms (or vice versa)?

Considering the second option:
I would need to store all vertex/normal/texture/index information in buffers for the VAO and then ALSO pass it in to the shader as a uniform buffer object?

(I've never used UBO's before, so pardon me if I don't understand!)

~QuicK
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (2842 views)
2018-11-16 13:46:03

hadezbladez (1024 views)
2018-11-16 13:41:33

hadezbladez (2809 views)
2018-11-16 13:35:35

hadezbladez (549 views)
2018-11-16 13:32:03

EgonOlsen (3821 views)
2018-06-10 19:43:48

EgonOlsen (4234 views)
2018-06-10 19:43:44

EgonOlsen (2542 views)
2018-06-10 19:43:20

DesertCoockie (3354 views)
2018-05-13 18:23:11

nelsongames (3468 views)
2018-04-24 18:15:36

nelsongames (4466 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!