diff options
author | Even Oscar Andersen <even.oscar.andersen@qt.io> | 2024-04-17 09:24:05 +0200 |
---|---|---|
committer | Even Oscar Andersen <even.oscar.andersen@qt.io> | 2024-04-18 11:39:16 +0200 |
commit | 547de2d4e5d5619e5d37b91ad534f9260492e339 (patch) | |
tree | fbbf0c693091de7c0ad2d779b7628eb9d4ec268a /examples/quick | |
parent | 9f32ed3d56da64a596129771f9da131a4dd21260 (diff) |
wasm: CustomMaterial: Change shader program so that it is accepted by WebGL
There are issues with for loops in GLSL, see for instance:
https://learnwebgl.brown37.net/12_shader_language/glsl_control_structures.html
The solution is to rewrite the shader so that it also works on WebGL.
Fixes: QTBUG-123593
Change-Id: Ia9fd4d9ef3f1b99a29d4bbabae20ad779fe4fbba
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'examples/quick')
-rw-r--r-- | examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag | 19 | ||||
-rw-r--r-- | examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag.qsb | bin | 2538 -> 2603 bytes | |||
-rw-r--r-- | examples/quick/scenegraph/custommaterial/shaders/mandelbrot.vert.qsb | bin | 1547 -> 1521 bytes |
3 files changed, 14 insertions, 5 deletions
diff --git a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag index 77cc67e4b5..72d63bb32c 100644 --- a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag +++ b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag @@ -30,21 +30,30 @@ void main() c.x = (vTexCoord.x - 0.5) / ubuf.zoom + ubuf.center.x; c.y = aspect_ratio * (vTexCoord.y - 0.5) / ubuf.zoom + ubuf.center.y; - int i; + int iLast; z = c; - for (i = 0; i < ubuf.limit; i++) { + for (int i = 0; i < 1000000; i++) { + if (i >= ubuf.limit) + { + iLast = i; + break; + } float x = (z.x * z.x - z.y * z.y) + c.x; float y = (z.y * z.x + z.x * z.y) + c.y; - if ((x * x + y * y) > 4.0) break; + if ((x * x + y * y) > 4.0) + { + iLast = i; + break; + } z.x = x; z.y = y; } - if (i == ubuf.limit) { + if (iLast == ubuf.limit) { fragColor = vec4(0.0, 0.0, 0.0, 1.0); } else { - float f = (i * 1.0) / ubuf.limit; + float f = (iLast * 1.0) / ubuf.limit; fragColor = mix(color1, color2, sqrt(f)); } } diff --git a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag.qsb b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag.qsb Binary files differindex 550c0377ae..97ec1c2633 100644 --- a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag.qsb +++ b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag.qsb diff --git a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.vert.qsb b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.vert.qsb Binary files differindex ba2904d1c9..37105cfe60 100644 --- a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.vert.qsb +++ b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.vert.qsb |