webgl-obj-loader icon indicating copy to clipboard operation
webgl-obj-loader copied to clipboard

Add MATERIAL_WEIGHT to makeBufferData

Open frenchtoast747 opened this issue 8 years ago • 1 comments

Enable or disable materials via the MATERIAL_WEIGHT attribute.

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

frenchtoast747 avatar Nov 10 '17 19:11 frenchtoast747

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

MATERIAL_INDEX

  • Send all of the materials (diffuse, spec, etc) into the shader through uniforms.
  • Use the materialIndex attribute to pick the one needed for a given vertex

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

  • Send literally all of the material information in through attributes--no uniforms necessary

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, ..., MATERIAL_WEIGHT_(N-1)

  • Send all of the materials (diffuse, spec, etc) into the shader through uniforms.
  • Set N float attributes (with values either 0 or 1), where N is the max number of materials you want your shader to support.
  • Compute, e.g., diffuse like: vec3 diffuse = mat0.diffuse * materialWeight0 + mat1.diffuse * materialWeight1 + ... + mat(N-1).diffuse * 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.

qtip avatar Nov 10 '17 19:11 qtip