diff options
author | Paul Olav Tvete <[email protected]> | 2020-06-18 15:32:21 +0200 |
---|---|---|
committer | Paul Olav Tvete <[email protected]> | 2020-06-24 19:48:45 +0200 |
commit | 2be6c85b8023f41d964c4c9d45343368b26a0830 (patch) | |
tree | d39f44cee9aeb86e1205cd5c95f41b2c99c977a6 /examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag | |
parent | af34b83c17861622a7d462c603a5c164e6e9e55a (diff) |
New custom material example
Fixes: QTBUG-78577
Change-Id: I280ffeda4bba1a9c170feb1ffa4b6c95eb0e6d28
Reviewed-by: Laszlo Agocs <[email protected]>
Diffstat (limited to 'examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag')
-rw-r--r-- | examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag new file mode 100644 index 0000000000..0e5f63e7a8 --- /dev/null +++ b/examples/quick/scenegraph/custommaterial/shaders/mandelbrot.frag @@ -0,0 +1,48 @@ +//! [1] +#version 440 + +layout(location = 0) in vec2 vTexCoord; + +layout(location = 0) out vec4 fragColor; + +//! [2] +// uniform block: 84 bytes +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; // offset 0 + float qt_Opacity; // offset 64 + float zoom; // offset 68 + vec2 center; // offset 72 + int limit; // offset 80 +} ubuf; +//! [2] + +void main() +{ + vec4 color1 = vec4(1.0, 0.85, 0.55, 1); + vec4 color2 = vec4(0.226, 0.0, 0.615, 1); + + float aspect_ratio = -ubuf.qt_Matrix[0][0]/ubuf.qt_Matrix[1][1]; + vec2 z, c; + + 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; + z = c; + for (i = 0; i < ubuf.limit; i++) { + 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; + z.x = x; + z.y = y; + } + + if (i == ubuf.limit) { + fragColor = vec4(0.0, 0.0, 0.0, 1.0); + } else { + float f = (i * 1.0) / ubuf.limit; + fragColor = mix(color1, color2, sqrt(f)); + } +} +//! [1] |