frenchtoast747 / webgl-obj-loader

A simple OBJ model loader to help facilitate the learning of WebGL.
http://frenchtoast747.github.io/webgl-obj-loader/
MIT License
281 stars 59 forks source link

Add MATERIAL_WEIGHT to makeBufferData #40

Open frenchtoast747 opened 6 years ago

frenchtoast747 commented 6 years ago

Enable or disable materials via the MATERIAL_WEIGHT attribute.

@qtip feel free to expand your thoughts on this issue.

qtip commented 6 years ago

We have to be able to send material information via vertex attributes. There are three strategies:

MATERIAL_INDEX

This is nice because it requires the least amount of information per-vertex. This is bad because you have to put the materialIndex int into a float and compare which is error prone and slow for the GPU. This makes it pretty much a non-option (though we should keep it anyway since it doesn't hurt anything and might be useful for some special cases)

DIFFUSE, SPECULAR, etc

This is great because it's super easy. It's bad because it wastes tons of bandwidth and memory packing the same material info over and over per-vertex.

MATERIAL_WEIGHT_0, MATERIAL_WEIGHT_1, ..., MATERIALWEIGHT(N-1)

This is like a mixture of both strategies. You can still send all the material info in via uniforms, but you send a bunch of data about which ones are available so you can avoid conditionals in shader code.