javascript - Webgl Angle loops really slow -
i have here glsl, , works charm. compiling taking 3 minutes or something. know due angle, angle piece of software converts opengl es 2.0 code directx 9 webgl on windows systems. if disable angle, compiles in second. know's why nested loops soo slow in angle. , if there work around? mean can't let wait more minute per shader.
for ( int b = 0; b < numberofsplitpoints; b++ ) { if ( cameradepth > splitpoints[b] && cameradepth < splitpoints[b+1] ) { const float numberofsplitpoints = float( number_of_split_points - 1 ); vec4 projcoords = v_projtexturecoords[b]; projcoords /= projcoords.w; projcoords = 0.5 * projcoords + 0.5; float shadowdepth = projcoords.z; projcoords.x /= numberofsplitpoints; projcoords.x += float(b) / numberofsplitpoints; for( int x = 0; x < fullkernelsize; x++ ) { for( int y = 0; y < fullkernelsize; y++ ) { vec2 pointer = vec2( float(x-kernelsize) / 3072.0, float(y-kernelsize) / 1024.0 ); float convolution = kernel[x] * kernel[y]; vec4 color = texture2d(shadowmapsampler, projcoords.xy+pointer); if(encodedepth( color ) + shadowbias > shadowdepth) { light += convolution; } else { light += convolution * 0.6; } } } } } vec2 random = normalize(texture2d(randomsampler, screensize * uv / 64.0).xy * 2.0 - 1.0); float ambiantamount = 0.0; const int kernel = 4; float offset = ssoasamplerad / depth; for(int x = 0; x<kernel; x++) { vec2 = reflect(directions[x], random) * offset; vec2 b = vec2( a.x *0.707 - a.y*0.707, a.x*0.707 + a.y*0.707 ); ambiantamount += abientocclusion(uv, a*0.25, position, normal); ambiantamount += abientocclusion(uv, b*0.50, position, normal); ambiantamount += abientocclusion(uv, a*0.75, position, normal); ambiantamount += abientocclusion(uv, b, position, normal); }
the glsl es not define while loops , "dynamically" bounded loops mandatory. angle takes advantage of , extensive loop unrolling: if have for ( int b = 0; b < numberofsplitpoints; b++ ), numberofsplitpoints has constant expression, otherwise shader won't compile.
the loop unrolling supposed allow native shader optimizer more optimizations , minimize divergence, (in code) if have numberofsplitpoints , fullkernelsize large, unrolled code can long (code in inner-most part repeated numberofsplitpoints*fullkernelsize*fullkernelsize times), may cause optimizer , compiler go sorts of trouble.
Comments
Post a Comment