Have you think of how many summation & multiply operations can you do within for-loops in GPU fragment shader?
I irrigorously tested the following fragment shader on ShaderToy, which gives me 100,000 operations at 22 FPS on a GTX 1080, for 25, 000 operations, it runs smoothly at 60 FPS.
So, what’s the limitation of your GPU processors?
Warning: Your WebGL may crash if you move to the rightwards.
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
// Just an irrigorous test of GPU's computational power. float char(vec2 p, int C) { if (p.x < 0. || p.x > 1. || p.y < 0.|| p.y > 1.) return 0.; return textureGrad(iChannel0, p/16. + fract(vec2(C, 15-C/16) / 16.), dFdx(p/16.),dFdy(p/16.) ).r; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; fragColor = vec4(uv,0.5+0.5*sin(iGlobalTime),1.0); float loops = 100000.0 * ((length(iMouse) < 1e-2) ? 0.3 : (iMouse.x / iResolution.x)); for (float k = 0.0; k < loops; k = k + 1.0) { fragColor.rgb += vec3(k / 10000000000.0); } vec3 c = fragColor.rgb; vec3 fontColor = vec3(1.0) - c; vec2 p = fragCoord.xy / iResolution.y; // move mouse x, see FPS c = mix(c, fontColor, char((p * 5.0) - vec2(0., 1.), 77)); c = mix(c, fontColor, char((p * 5.0) - vec2(.5, 1.), 79)); c = mix(c, fontColor, char((p * 5.0) - vec2(1., 1.), 86)); c = mix(c, fontColor, char((p * 5.0) - vec2(1.5, 1.), 69)); c = mix(c, fontColor, char((p * 5.0) - vec2(2.5, 1.), 77)); c = mix(c, fontColor, char((p * 5.0) - vec2(3., 1.), 79)); c = mix(c, fontColor, char((p * 5.0) - vec2(3.5, 1.), 85)); c = mix(c, fontColor, char((p * 5.0) - vec2(4., 1.), 83)); c = mix(c, fontColor, char((p * 5.0) - vec2(4.5, 1.), 69)); c = mix(c, fontColor, char((p * 5.0) - vec2(5.5, 1.), 88)); c = mix(c, fontColor, char((p * 5.0), 83)); c = mix(c, fontColor, char((p * 5.0) - vec2(.5, 0.), 69)); c = mix(c, fontColor, char((p * 5.0) - vec2(1., 0.), 69)); c = mix(c, fontColor, char((p * 5.0) - vec2(2., 0.), 70)); c = mix(c, fontColor, char((p * 5.0) - vec2(2.5, 0.), 80)); c = mix(c, fontColor, char((p * 5.0) - vec2(3., 0.), 83)); fragColor.rgb = c; } |