Skip to content

Commit ad52606

Browse files
committed
added alpha to blitter batch
1 parent 12ac4cc commit ad52606

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

v3/src/renderer/webgl/batches/blitter/BlitterBatch.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ BlitterBatch.prototype = {
8282

8383
var attribArray = [
8484
CreateAttribDesc(gl, program, 'a_position', 2, gl.FLOAT, false, CONST.VERTEX_SIZE, 0),
85-
CreateAttribDesc(gl, program, 'a_tex_coord', 2, gl.FLOAT, false, CONST.VERTEX_SIZE, 8)
85+
CreateAttribDesc(gl, program, 'a_tex_coord', 2, gl.FLOAT, false, CONST.VERTEX_SIZE, 8),
86+
CreateAttribDesc(gl, program, 'a_color', 1, gl.FLOAT, false, CONST.VERTEX_SIZE, 16)
8687
];
8788

8889
var vertexArray = new VertexArray(CreateBuffer(gl, gl.ARRAY_BUFFER, gl.STREAM_DRAW, null, vertexDataBuffer.getByteCapacity()), attribArray);
@@ -131,7 +132,7 @@ BlitterBatch.prototype = {
131132
return (this.vertexDataBuffer.getByteLength() >= this.vertexDataBuffer.getByteCapacity());
132133
},
133134

134-
add: function (x, y, frame)
135+
add: function (x, y, frame, alpha)
135136
{
136137
this.manager.setBatch(this, frame.texture.source[0].glTexture);
137138

@@ -148,21 +149,25 @@ BlitterBatch.prototype = {
148149
vertexBuffer[vertexOffset++] = y;
149150
vertexBuffer[vertexOffset++] = uvs.x0;
150151
vertexBuffer[vertexOffset++] = uvs.y0;
151-
152+
vertexBuffer[vertexOffset++] = alpha;
153+
152154
vertexBuffer[vertexOffset++] = x;
153155
vertexBuffer[vertexOffset++] = y + height;
154156
vertexBuffer[vertexOffset++] = uvs.x1;
155157
vertexBuffer[vertexOffset++] = uvs.y1;
158+
vertexBuffer[vertexOffset++] = alpha;
156159

157160
vertexBuffer[vertexOffset++] = x + width;
158161
vertexBuffer[vertexOffset++] = y + height;
159162
vertexBuffer[vertexOffset++] = uvs.x2;
160163
vertexBuffer[vertexOffset++] = uvs.y2;
164+
vertexBuffer[vertexOffset++] = alpha;
161165

162166
vertexBuffer[vertexOffset++] = x + width;
163167
vertexBuffer[vertexOffset++] = y;
164168
vertexBuffer[vertexOffset++] = uvs.x3;
165169
vertexBuffer[vertexOffset++] = uvs.y3;
170+
vertexBuffer[vertexOffset++] = alpha;
166171

167172
this.elementCount += CONST.PARTICLE_INDEX_COUNT;
168173
},

v3/src/renderer/webgl/batches/blitter/FragmentShader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = [
22
'precision lowp float;',
33
'uniform sampler2D u_sampler2D;',
44
'varying vec2 v_tex_coord;',
5+
'varying float v_alpha;',
56
'void main() {',
6-
' gl_FragColor = texture2D(u_sampler2D, v_tex_coord);',
7+
' gl_FragColor = texture2D(u_sampler2D, v_tex_coord) * vec4(1.0, 1.0, 1.0, v_alpha);',
78
'}'
89
].join('\n');

v3/src/renderer/webgl/batches/blitter/VertexShader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ module.exports = [
22
'uniform mat4 u_view_matrix;',
33
'attribute vec2 a_position;',
44
'attribute vec2 a_tex_coord;',
5+
'attribute float a_alpha;',
56
'varying vec2 v_tex_coord;',
7+
'varying float v_alpha;',
68
'void main () {',
79
' gl_Position = u_view_matrix * vec4(a_position, 1.0, 1.0);',
810
' v_tex_coord = a_tex_coord;',
11+
' v_alpha = a_alpha;',
912
'}'
1013
].join('\n');

v3/src/renderer/webgl/batches/blitter/const.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ var VertexShader = require('./VertexShader');
33

44
var CONST = {
55

6-
// VERTEX_SIZE = sizeof(vec2) + sizeof(vec2)
7-
VERTEX_SIZE: 16,
6+
// VERTEX_SIZE = sizeof(vec2) + sizeof(vec2) + sizeof(float)
7+
VERTEX_SIZE: 20,
88
INDEX_SIZE: 2,
99
PARTICLE_VERTEX_COUNT: 4,
1010
PARTICLE_INDEX_COUNT: 6,
1111

1212
// How many 32-bit components does the vertex have.
13-
PARTICLE_VERTEX_COMPONENT_COUNT: 4,
13+
PARTICLE_VERTEX_COMPONENT_COUNT: 5,
1414

1515
// Can't be bigger since index are 16-bit
1616
MAX_PARTICLES: 10000,

0 commit comments

Comments
 (0)