Comments (1)
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.
from webgl-obj-loader.
Related Issues (20)
- Documentation / Example for materials HOT 3
- Add support for calculating tangents and bitangents HOT 1
- development example dosen't work well. HOT 1
- Texture bug HOT 1
- version is undefined and OBJ is undefined HOT 2
- UV layout, error in the code. HOT 2
- Missing TypeScript header file HOT 4
- Add submesh support HOT 2
- Clarify attribute indexing documentation HOT 5
- Update triangulate() to provide a better triangulation algorithm
- error HOT 3
- 'window' is not defined in node.js HOT 4
- I get "" in filename on the sponza HOT 2
- Wrong parsing when faces is quade with uv HOT 2
- Write better tests for triangulation HOT 1
- Layout.SPECULAR_EXPONENT Attribute size
- error TS2307: Cannot find module 'webgl-obj-loader' HOT 5
- DownloadModels() use. HOT 3
- how do I load a model in webgl2 with multiple material/objects?
- Threejs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webgl-obj-loader.