I'm rendering multiple objects with multiple material. Usually material is represented as uniform in shader, and to render the whole scene we call draw for each material.
Can I represent material (Kd, Ka etc) as vertex attribute and send it to fragment shader with flat interpolation? This way we can draw with just a single command. What is the disadvantage of this approach?
You can definitely do this; simply define the material as a vertex attribute just as you would for color, normal, or position. I wouldn't worry too much about sending 2 extra floats (diffuse, ambient) per vertex to a modern graphics card. There might be a slight performance difference, but not much. If this is what you need, then using a vertex attribute is the cleanest approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With