Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store material as vertex attribute

Tags:

opengl

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?

like image 798
Dzung Nguyen Avatar asked Apr 21 '26 18:04

Dzung Nguyen


1 Answers

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.

like image 133
Matt Fichman Avatar answered Apr 25 '26 04:04

Matt Fichman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!