javascript - WebGL Weird Performance Drop in Chrome -
i have been trying learn webgl have made simple model loading script. thought working fine , dandy until pulled chrome's devtools timeline , saw getting ~20 fps when rendering 100 models. weird part was, cpu idle of time on each frame.
my first thought must gpu bound, seemed unlikely because shaders short , not complex. tested 10 models , again one, , did increase performance, still getting less 40 fps. pulled chrome://tracing, , saw both gpu wasn't doing each frame either. majority of each frame in crgpumain filled "processing swap", , crbrowsermain spent of time on glfinish (called "compositingiosurfacemac::drawiosurface").
processing swap appears major problem, not glfinish.
so question is, causing browser spend time on glfinish? ideas on how fix problem?
each model has 40608 elements , 20805 vertices,
update - corrected numbers of simplified mesh:
- 3140 elements
- 6091 vertices
the models pseudo-instanced data passed gpu once per frame. large number of vertices problem?
the demo can found here.
rendering code:
thing.prototype.renderinstances = function(){ if (this.loaded){ var instance; gl.bindbuffer(gl.array_buffer, this.vertexbuffer); gl.vertexattribpointer(shaderprogram.vertexpositionattribute, 3, gl.float, false, 0, 0); gl.bindbuffer(gl.array_buffer, this.normalbuffer); gl.vertexattribpointer(shaderprogram.vertexnormalattribute, 3, gl.float, true, 0, 0); gl.bindbuffer(gl.element_array_buffer, this.indexbuffer); for(var in this.instances){ instance = this.instances[i]; setmatrixuniforms(instance.matrix); gl.drawelements(gl.triangles, this.numitems, gl.unsigned_short,0); } } };
vertex shader code:
attribute vec3 avertexposition; attribute vec3 avertexnormal; uniform mat4 ummatrix; uniform mat4 uvmatrix; uniform mat4 upmatrix; uniform vec3 ulightdirection; varying float vlight; void main(void) { mat4 mvmatrix = uvmatrix*ummatrix; //toji's manual transpose mat3 normalmatrix = mat3(mvmatrix[0][0], mvmatrix[1][0], mvmatrix[2][0], mvmatrix[0][1], mvmatrix[1][1], mvmatrix[2][1], mvmatrix[0][2], mvmatrix[1][2], mvmatrix[2][2]); gl_position = upmatrix*uvmatrix*ummatrix*vec4(avertexposition, 1.0); vec3 lightdirection = ulightdirection*normalmatrix; vec3 normal = normalize(avertexnormal*normalmatrix); vlight = max(dot(avertexnormal,ulightdirection),0.0); }
Comments
Post a Comment