[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Premultiplied alpha blending and issues with color accuracy

On Fri, May 11, 2012 at 11:00 AM, Thor Harald Johansen <thj@thj.no> wrote:
And okay, from your and Ben's comments, it seems I'm going to have to look more carefully at how multi-texturing actually works. All the examples I found were doing things like switching textures for each side of a cube, etc. None demonstrated blending of multiple textures. I find API references to be really hard to learn from. :/
Using multiple textures is relatively straightforward.

// bind first texture
gl.bindTexture(gl.TEXTURE_2D, first_texture);
gl.uniform1i(gl.getUniformLocation(program, 'first_texture'), 0);
// bind second texture
gl.bindTexture(gl.TEXTURE_2D, second_texture);
gl.uniform1i(gl.getUniformLocation(program, 'second_texture'), 1);

And then in the shader have:

varying vec2 uv;
uniform sampler2D first_texture, second_texture;
void main(){
  gl_FragColor = texture2D(first_texture, uv) + texture2D(second_texture, uv);