3 ms·
In addition to the texturing & filtering argument Eric makes in this article, I think learning and using pre multiplied blending is extra important in WebGL bec
by dahart 11y ago
In addition to the texturing & filtering argument Eric makes in this article, I think learning and using pre multiplied blending is extra important in WebGL because WebGL canvases are always composited over the page, and the default compositing mode is pre multipled.
I mocked up a fiddle to demonstrate this point. https://jsfiddle.net/dahart/m4z61tz1/ https://jsfiddle.net/dahart/m4z61tz1/
*edit: a little explanation, the fiddle shows, in the top half, blending using the most commonly learned method for non-premultiplied colors/textures, with gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
In the bottom half, blending is done with pre-multiplied colors, and gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA).
The main point is how, using WebGL's default settings, you can see through what should be opaque areas on top, and the stuff on the bottom looks and behaves correctly.
The fiddle has enough toggles and comments in the code and fragment shader to get the non-pre multiplied blending & compositing to work correctly.
- TACIXAT 11y agoDo you have any recommended resources for learning WebGL?
- dahart 11y agohttp://webglfundamentals.org http://webglfundamentals.org is a fantastic place to start.
- ulyssesgrant 11y agoThe author of this blog post has a course on Udacity where he teaches the basics of real time rendering using three.js
- dietrichepp 11y agoIn my experience, you should always turn off compositing in WebGL. The performance differences are sometimes rather extreme.