#version 150 core #extension GL_EXT_gpu_shader4 : enable #extension GL_EXT_texture_array : enable //[ precision highp float; precision highp int; //] #define pi 3.141592653589793238462643383279 out vec4 out_data; out vec4 out_aux; uniform sampler2D u_tex0; uniform sampler2D u_tex1; uniform sampler2DArray u_tex2; uniform ivec2 u_s; uniform int u_t; //------------------------------------------------------------------------------------------ // IQ's noise fragment shader //------------------------------------------------------------------------------------------ void out_0() { int n = int(gl_FragCoord.x * 40.0 + gl_FragCoord.y * 6400.0); n = (n << 13) ^ n; out_aux = out_data = vec4(1.0 - float( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } //------------------------------------------------------------------------------------------ // Summed area table generation: // This shader will be repeatedly applied (ping/pong) with an increasing delta at each pass. // The number of passes is equal to the minimum value of the log base X of the image size. // X being the delta increase at each pass. // Not that this procedure will be applied horizontally and vertically. //------------------------------------------------------------------------------------------ void out_1() { vec4 t[8]; ivec2 coord = ivec2(gl_FragCoord.xy); for(int i=0; i<8; ++i) { t[i] = texelFetch( u_tex0, coord, 0 ); coord -= u_s; t[i] += texelFetch( u_tex0, coord, 0 ); coord -= u_s; } t[0] += t[1]; t[2] += t[3]; t[4] += t[5]; t[6] += t[7]; t[0] += t[2]; t[4] += t[6]; out_data = t[0] + t[4]; } //------------------------------------------------------------------------------------------ // Box blur of arbitrary size (u_t) using summed area table (u_tex0). //------------------------------------------------------------------------------------------ void out_2() { ivec2 tSize = ivec2(textureSize2D(u_tex0, 0)); ivec2 p = ivec2(gl_FragCoord.xy); ivec4 uv = ivec4( min(p + u_t, tSize-ivec2(1)), max(p - u_t, ivec2(0)) ); ivec2 area = max(uv.xy - uv.zw, ivec2(1)); out_data = ( texelFetch( u_tex0, uv.xy, 0 ) - texelFetch( u_tex0, uv.xw, 0 ) - texelFetch( u_tex0, uv.zy, 0 ) + texelFetch( u_tex0, uv.zw, 0 ) ) / (area.x * area.y); } //------------------------------------------------------------------------------------------ // Multiscale Turing patterns. // References : // * Cyclic Symmetric Multi-Scale Turing Patterns by Jonathan McCabe // * Multi-Scale Turing Patterns by Jason Rampe (Softology's Blog) //------------------------------------------------------------------------------------------ void out_3() { float delta[7] = float[7](0.0025, 0.0045, 0.0065, 0.0085, 0.015, 0.0125, 0.0145); int symmetry[7] = int[7](4,2,2,2,3,3,3); int scale[7] = int[7](0,2,3,4,5,6,8); vec2 size = textureSize(u_tex1, 0); vec2 p = gl_FragCoord.xy - size*0.5; float min = 65535.0; int bestIndex = 6; vec2 best; for(int k=0; k<7; k++) { vec2 tmp = vec2(0.0); int nrot = symmetry[k]; int idx = scale[k]; for(int i=0; i