├── README.md ├── example-computeshader ├── .gitignore ├── addons.make ├── bin │ └── data │ │ ├── Common │ │ ├── Noise2D.glslinc │ │ ├── Noise3D.glslinc │ │ ├── Noise4D.glslinc │ │ ├── PhotoshopBlendModes.glslinc │ │ ├── ShaderHelpers.glslinc │ │ └── SimplexNoiseDerivatives4D.glslinc │ │ └── compute.glsl ├── example-computeshader.sln ├── example-computeshader.vcxproj ├── example-computeshader.vcxproj.filters ├── icon.rc └── src │ └── ofApp.cpp ├── example-glslify ├── .gitignore ├── Makefile ├── Project.xcconfig ├── addons.make ├── bin │ └── data │ │ ├── Common │ │ ├── Common.glslinc │ │ ├── Noise2D.glslinc │ │ ├── Noise3D.glslinc │ │ ├── Noise4D.glslinc │ │ ├── PhotoshopBlendModes.glslinc │ │ ├── ShaderHelpers.glslinc │ │ ├── SimplexNoiseDerivatives4D.glslinc │ │ └── ofCommon.glslinc │ │ ├── package.json │ │ └── shader.glsl ├── config.make ├── example.sln ├── example.vcxproj ├── example.vcxproj.filters ├── example.xcodeproj │ └── project.pbxproj ├── icon.rc ├── openFrameworks-Info.plist └── src │ └── ofApp.cpp ├── example ├── .gitignore ├── Makefile ├── Project.xcconfig ├── addons.make ├── bin │ └── data │ │ ├── Common │ │ ├── Common.glslinc │ │ ├── Noise2D.glslinc │ │ ├── Noise3D.glslinc │ │ ├── Noise4D.glslinc │ │ ├── PhotoshopBlendModes.glslinc │ │ ├── ShaderHelpers.glslinc │ │ ├── SimplexNoiseDerivatives4D.glslinc │ │ └── ofCommon.glslinc │ │ └── shader.glsl ├── config.make ├── example.sln ├── example.vcxproj ├── example.vcxproj.filters ├── example.xcodeproj │ └── project.pbxproj ├── icon.rc ├── openFrameworks-Info.plist └── src │ └── ofApp.cpp ├── shader ├── Common │ ├── Common.glslinc │ ├── Noise2D.glslinc │ ├── Noise3D.glslinc │ ├── Noise4D.glslinc │ ├── PhotoshopBlendModes.glslinc │ ├── ShaderHelpers.glslinc │ ├── SimplexNoiseDerivatives4D.glslinc │ └── ofCommon.glslinc ├── passthrough120.glsl ├── passthrough150.glsl └── passthrough430.glsl └── src └── ofxShaderRunner.h /README.md: -------------------------------------------------------------------------------- 1 | # ofxShaderRunner 2 | 3 | The shader addon for businessman 4 | 5 | + No ofMesh, glBegin/End. Only shader 6 | + No .vert, .frag, .geom: Only .glsl 7 | + Autoreloading support 8 | + ~~[glslify](https://github.com/stackgl/glslify) support~~ 9 | 10 | more detail, see: https://www.youtube.com/watch?v=IXsvKlwVdn0 11 | -------------------------------------------------------------------------------- /example-computeshader/.gitignore: -------------------------------------------------------------------------------- 1 | .svn 2 | .hg 3 | .cvs 4 | 5 | # osx 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | Icon 10 | *.app 11 | ._* 12 | DerivedData 13 | 14 | # xcode3 15 | *.mode1v3 16 | *.pbxuser 17 | build/ 18 | 19 | # xcode4 20 | *.xcodeproj/* 21 | !*.xcodeproj/project.pbxproj 22 | !*.xcodeproj/default.* 23 | **/*.xcodeproj/* 24 | !**/*.xcodeproj/project.pbxproj 25 | !**/*.xcodeproj/default.* 26 | *.xcworkspace/* 27 | !*.xcworkspace/contents.xcworkspacedata 28 | 29 | # windows 30 | *.exe 31 | Thumbs.db 32 | ehthumbs.db 33 | 34 | # vs 35 | ipch/ 36 | [Bb]in/ 37 | [Oo]bj/ 38 | *.aps 39 | *.ncb 40 | *.opensdf 41 | *.sdf 42 | *.cachefile 43 | *.suo 44 | *.user 45 | *.sln.docstates 46 | *.opendb 47 | 48 | # Object files 49 | *.o 50 | 51 | # Libraries 52 | *.lib 53 | *.a 54 | 55 | # Shared objects (inc. Windows DLLs) 56 | *.dll 57 | *.so 58 | *.so.* 59 | *.dylib 60 | -------------------------------------------------------------------------------- /example-computeshader/addons.make: -------------------------------------------------------------------------------- 1 | ofxShaderRunner 2 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/Noise2D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D simplex noise function. 3 | // Author : Ian McEwan, Ashima Arts. 4 | // Maintainer : ijm 5 | // Lastmod : 20110822 (ijm) 6 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 7 | // Distributed under the MIT License. See LICENSE file. 8 | // https://github.com/ashima/webgl-noise 9 | // 10 | 11 | // ------------------------------------------------------------------------------------- 12 | // 13 | float snoise(vec2 v) 14 | { 15 | const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 16 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 17 | -0.577350269189626, // -1.0 + 2.0 * C.x 18 | 0.024390243902439); // 1.0 / 41.0 19 | // First corner 20 | vec2 i = floor(v + dot(v, C.yy) ); 21 | vec2 x0 = v - i + dot(i, C.xx); 22 | 23 | // Other corners 24 | vec2 i1; 25 | //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 26 | //i1.y = 1.0 - i1.x; 27 | i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); 28 | // x0 = x0 - 0.0 + 0.0 * C.xx ; 29 | // x1 = x0 - i1 + 1.0 * C.xx ; 30 | // x2 = x0 - 1.0 + 2.0 * C.xx ; 31 | vec4 x12 = x0.xyxy + C.xxzz; 32 | x12.xy -= i1; 33 | 34 | // Permutations 35 | i = mod289(i); // Avoid truncation effects in permutation 36 | vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) 37 | + i.x + vec3(0.0, i1.x, 1.0 )); 38 | 39 | vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); 40 | m = m*m ; 41 | m = m*m ; 42 | 43 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 44 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 45 | 46 | vec3 x = 2.0 * fract(p * C.www) - 1.0; 47 | vec3 h = abs(x) - 0.5; 48 | vec3 ox = floor(x + 0.5); 49 | vec3 a0 = x - ox; 50 | 51 | // Normalise gradients implicitly by scaling m 52 | // Approximation of: m *= inversesqrt( a0*a0 + h*h ); 53 | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); 54 | 55 | // Compute final noise value at P 56 | vec3 g; 57 | g.x = a0.x * x0.x + h.x * x0.y; 58 | g.yz = a0.yz * x12.xz + h.yz * x12.yw; 59 | return 130.0 * dot(m, g); 60 | } 61 | 62 | // ------------------------------------------------------------------------------------- 63 | // 64 | float snoiseu(vec2 v) 65 | { 66 | return (snoise( v ) + 1.0) * 0.5; 67 | } 68 | 69 | // ------------------------------------------------------------------------------------- 70 | // 71 | float fbm_5oct( vec2 p ) 72 | { 73 | float f = 0.0; 74 | f += 0.50000*snoise( p ); p = p*2.02; 75 | f += 0.25000*snoise( p ); p = p*2.03; 76 | f += 0.12500*snoise( p ); p = p*2.01; 77 | f += 0.06250*snoise( p ); p = p*2.04; 78 | f += 0.03125*snoise( p ); 79 | return f/0.984375; 80 | } 81 | 82 | // ------------------------------------------------------------------------------------- 83 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 84 | // 85 | float fbm(vec2 P, int octaves, float lacunarity, float gain) 86 | { 87 | float sum = 0.0; 88 | float amp = 1.0; 89 | vec2 pp = P; 90 | 91 | for( int i = 0; i < octaves; i+=1) 92 | { 93 | amp *= gain; 94 | sum += amp * snoise(pp); 95 | pp *= lacunarity; 96 | } 97 | 98 | return sum; 99 | } 100 | 101 | // ------------------------------------------------------------------------------------- 102 | // Returns the FBM in the range 0..1 103 | // 104 | float fbmu(vec2 _p, int _octaves, float _lacunarity, float _persistence ) 105 | { 106 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/Noise3D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // ------------------------------------------------------------------------------------- 13 | // 14 | float snoise(vec3 v) 15 | { 16 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 17 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 18 | 19 | // First corner 20 | vec3 i = floor(v + dot(v, C.yyy) ); 21 | vec3 x0 = v - i + dot(i, C.xxx) ; 22 | 23 | // Other corners 24 | vec3 g = step(x0.yzx, x0.xyz); 25 | vec3 l = 1.0 - g; 26 | vec3 i1 = min( g.xyz, l.zxy ); 27 | vec3 i2 = max( g.xyz, l.zxy ); 28 | 29 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 30 | // x1 = x0 - i1 + 1.0 * C.xxx; 31 | // x2 = x0 - i2 + 2.0 * C.xxx; 32 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 33 | vec3 x1 = x0 - i1 + C.xxx; 34 | vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 35 | vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 36 | 37 | // Permutations 38 | i = mod289(i); 39 | vec4 p = permute( permute( permute( 40 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 41 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 42 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 43 | 44 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 45 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 46 | float n_ = 0.142857142857; // 1.0/7.0 47 | vec3 ns = n_ * D.wyz - D.xzx; 48 | 49 | vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 50 | 51 | vec4 x_ = floor(j * ns.z); 52 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 53 | 54 | vec4 x = x_ *ns.x + ns.yyyy; 55 | vec4 y = y_ *ns.x + ns.yyyy; 56 | vec4 h = 1.0 - abs(x) - abs(y); 57 | 58 | vec4 b0 = vec4( x.xy, y.xy ); 59 | vec4 b1 = vec4( x.zw, y.zw ); 60 | 61 | //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; 62 | //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; 63 | vec4 s0 = floor(b0)*2.0 + 1.0; 64 | vec4 s1 = floor(b1)*2.0 + 1.0; 65 | vec4 sh = -step(h, vec4(0.0)); 66 | 67 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 68 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 69 | 70 | vec3 p0 = vec3(a0.xy,h.x); 71 | vec3 p1 = vec3(a0.zw,h.y); 72 | vec3 p2 = vec3(a1.xy,h.z); 73 | vec3 p3 = vec3(a1.zw,h.w); 74 | 75 | //Normalise gradients 76 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 77 | p0 *= norm.x; 78 | p1 *= norm.y; 79 | p2 *= norm.z; 80 | p3 *= norm.w; 81 | 82 | // Mix final noise value 83 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 84 | m = m * m; 85 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 86 | dot(p2,x2), dot(p3,x3) ) ); 87 | } 88 | 89 | // ------------------------------------------------------------------------------------- 90 | // 91 | float fbm_2oct(vec3 p) 92 | { 93 | float final = snoise(p); 94 | p *= 1.94; 95 | final += snoise(p) * 0.5; 96 | return final / 1.5; 97 | } 98 | 99 | // ------------------------------------------------------------------------------------- 100 | // 101 | float fbm_3oct(vec3 p) 102 | { 103 | float final = snoise(p); 104 | p *= 1.94; 105 | final += snoise(p) * 0.5; 106 | p *= 3.75; 107 | final += snoise(p) * 0.25; 108 | return final / 1.75; 109 | 110 | } 111 | 112 | // ------------------------------------------------------------------------------------- 113 | // 114 | float fbm_5oct( vec3 p ) 115 | { 116 | float f = 0.0; 117 | f += 0.50000*snoise( p ); p = p*2.02; 118 | f += 0.25000*snoise( p ); p = p*2.03; 119 | f += 0.12500*snoise( p ); p = p*2.01; 120 | f += 0.06250*snoise( p ); p = p*2.04; 121 | f += 0.03125*snoise( p ); 122 | return f/0.984375; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 127 | // 128 | float fbm(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 129 | { 130 | float sum = 0.0; 131 | float amp = 1.0; 132 | vec3 pp = _p; 133 | float totalAmp = 0.0; 134 | 135 | for( int i = 0; i < _octaves; i++) 136 | { 137 | amp *= _persistence; 138 | totalAmp += amp; 139 | sum += amp * snoise(pp); 140 | pp *= _lacunarity; 141 | } 142 | 143 | return sum / totalAmp; 144 | } 145 | 146 | // ------------------------------------------------------------------------------------- 147 | // Returns the FBM in the range 0..1 148 | // 149 | float fbmu(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 150 | { 151 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 152 | } 153 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/Noise4D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // (sqrt(5) - 1)/4 = F4, used once below 13 | #define F4 0.309016994374947451 14 | 15 | // ------------------------------------------------------------------------------------- 16 | // 17 | float snoise(vec4 v) 18 | { 19 | const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4 20 | 0.276393202250021, // 2 * G4 21 | 0.414589803375032, // 3 * G4 22 | -0.447213595499958); // -1 + 4 * G4 23 | 24 | // First corner 25 | vec4 i = floor(v + dot(v, vec4(F4)) ); 26 | vec4 x0 = v - i + dot(i, C.xxxx); 27 | 28 | // Other corners 29 | 30 | // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) 31 | vec4 i0; 32 | vec3 isX = step( x0.yzw, x0.xxx ); 33 | vec3 isYZ = step( x0.zww, x0.yyz ); 34 | // i0.x = dot( isX, vec3( 1.0 ) ); 35 | i0.x = isX.x + isX.y + isX.z; 36 | i0.yzw = 1.0 - isX; 37 | // i0.y += dot( isYZ.xy, vec2( 1.0 ) ); 38 | i0.y += isYZ.x + isYZ.y; 39 | i0.zw += 1.0 - isYZ.xy; 40 | i0.z += isYZ.z; 41 | i0.w += 1.0 - isYZ.z; 42 | 43 | // i0 now contains the unique values 0,1,2,3 in each channel 44 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 45 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 46 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 47 | 48 | // x0 = x0 - 0.0 + 0.0 * C.xxxx 49 | // x1 = x0 - i1 + 1.0 * C.xxxx 50 | // x2 = x0 - i2 + 2.0 * C.xxxx 51 | // x3 = x0 - i3 + 3.0 * C.xxxx 52 | // x4 = x0 - 1.0 + 4.0 * C.xxxx 53 | vec4 x1 = x0 - i1 + C.xxxx; 54 | vec4 x2 = x0 - i2 + C.yyyy; 55 | vec4 x3 = x0 - i3 + C.zzzz; 56 | vec4 x4 = x0 + C.wwww; 57 | 58 | // Permutations 59 | i = mod289(i); 60 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 61 | vec4 j1 = permute( permute( permute( permute ( 62 | i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 63 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 64 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 65 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 66 | 67 | // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope 68 | // 7*7*6 = 294, which is close to the ring size 17*17 = 289. 69 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 70 | 71 | vec4 p0 = grad4(j0, ip); 72 | vec4 p1 = grad4(j1.x, ip); 73 | vec4 p2 = grad4(j1.y, ip); 74 | vec4 p3 = grad4(j1.z, ip); 75 | vec4 p4 = grad4(j1.w, ip); 76 | 77 | // Normalise gradients 78 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 79 | p0 *= norm.x; 80 | p1 *= norm.y; 81 | p2 *= norm.z; 82 | p3 *= norm.w; 83 | p4 *= taylorInvSqrt(dot(p4,p4)); 84 | 85 | // Mix contributions from the five corners 86 | vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); 87 | vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); 88 | m0 = m0 * m0; 89 | m1 = m1 * m1; 90 | return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) 91 | + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; 92 | 93 | } 94 | 95 | 96 | // ------------------------------------------------------------------------------------- 97 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 98 | // 99 | float fbm(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 100 | { 101 | float sum = 0.0; 102 | float amp = 1.0; 103 | vec4 pp = _p; 104 | float totalAmp = 0.0; 105 | 106 | for( int i = 0; i < _octaves; i++) 107 | { 108 | amp *= _persistence; 109 | totalAmp += amp; 110 | sum += amp * snoise(pp); 111 | pp *= _lacunarity; 112 | } 113 | 114 | return sum / totalAmp; 115 | } 116 | 117 | // ------------------------------------------------------------------------------------- 118 | // Returns the FBM in the range 0..1 119 | // 120 | float fbmu(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 121 | { 122 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // 127 | vec3 fbmvec3(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 128 | { 129 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 130 | tmp.x = fbm( vec4( _p.x, _p.y, _p.z, _p.w ), _octaves, _lacunarity, _persistence ); 131 | tmp.y = fbm( vec4( _p.y + 3.422, _p.x + 21.13, _p.w + 312.2, _p.z + 132.32 ), _octaves, _lacunarity, _persistence ); 132 | tmp.z = fbm( vec4( _p.w + 1.234, _p.z + 87.31, _p.y + 2367.1, _p.x + 894.21 ), _octaves, _lacunarity, _persistence ); 133 | return tmp; 134 | } 135 | 136 | // ------------------------------------------------------------------------------------- 137 | vec3 snoisevec3( vec4 _p ) 138 | { 139 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 140 | tmp.x = snoise( vec4( _p.x, _p.y, _p.z, _p.w ) ); 141 | tmp.y = snoise( vec4( _p.y, _p.x, _p.w, _p.z ) ); 142 | tmp.z = snoise( vec4( _p.w, _p.z, _p.y, _p.x ) ); 143 | return tmp; 144 | } -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/PhotoshopBlendModes.glslinc: -------------------------------------------------------------------------------- 1 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 2 | // 3 | // 25 of the layer blending modes from Photoshop. 4 | // 5 | // The ones I couldn't figure out are from Nvidia's advanced blend equations extension spec - 6 | // http://www.opengl.org/registry/specs/NV/blend_equation_advanced.txt 7 | // 8 | // ~bj.2013 9 | // 10 | 11 | vec3 darken( vec3 s, vec3 d ) 12 | { 13 | return min(s,d); 14 | } 15 | 16 | vec3 multiply( vec3 s, vec3 d ) 17 | { 18 | return s*d; 19 | } 20 | 21 | vec3 colorBurn( vec3 s, vec3 d ) 22 | { 23 | return 1.0 - (1.0 - d) / s; 24 | } 25 | 26 | vec3 linearBurn( vec3 s, vec3 d ) 27 | { 28 | return s + d - 1.0; 29 | } 30 | 31 | vec3 darkerColor( vec3 s, vec3 d ) 32 | { 33 | return (s.x + s.y + s.z < d.x + d.y + d.z) ? s : d; 34 | } 35 | 36 | vec3 lighten( vec3 s, vec3 d ) 37 | { 38 | return max(s,d); 39 | } 40 | 41 | vec3 screen( vec3 s, vec3 d ) 42 | { 43 | return s + d - s * d; 44 | } 45 | 46 | vec3 colorDodge( vec3 s, vec3 d ) 47 | { 48 | return d / (1.0 - s); 49 | } 50 | 51 | vec3 linearDodge( vec3 s, vec3 d ) 52 | { 53 | return s + d; 54 | } 55 | 56 | vec3 lighterColor( vec3 s, vec3 d ) 57 | { 58 | return (s.x + s.y + s.z > d.x + d.y + d.z) ? s : d; 59 | } 60 | 61 | float overlay( float s, float d ) 62 | { 63 | return (d < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 64 | } 65 | 66 | vec3 overlay( vec3 s, vec3 d ) 67 | { 68 | vec3 c; 69 | c.x = overlay(s.x,d.x); 70 | c.y = overlay(s.y,d.y); 71 | c.z = overlay(s.z,d.z); 72 | return c; 73 | } 74 | 75 | float softLight( float s, float d ) 76 | { 77 | return (s < 0.5) ? d - (1.0 - 2.0 * s) * d * (1.0 - d) 78 | : (d < 0.25) ? d + (2.0 * s - 1.0) * d * ((16.0 * d - 12.0) * d + 3.0) 79 | : d + (2.0 * s - 1.0) * (sqrt(d) - d); 80 | } 81 | 82 | vec3 softLight( vec3 s, vec3 d ) 83 | { 84 | vec3 c; 85 | c.x = softLight(s.x,d.x); 86 | c.y = softLight(s.y,d.y); 87 | c.z = softLight(s.z,d.z); 88 | return c; 89 | } 90 | 91 | float hardLight( float s, float d ) 92 | { 93 | return (s < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 94 | } 95 | 96 | vec3 hardLight( vec3 s, vec3 d ) 97 | { 98 | vec3 c; 99 | c.x = hardLight(s.x,d.x); 100 | c.y = hardLight(s.y,d.y); 101 | c.z = hardLight(s.z,d.z); 102 | return c; 103 | } 104 | 105 | float vividLight( float s, float d ) 106 | { 107 | return (s < 0.5) ? 1.0 - (1.0 - d) / (2.0 * s) : d / (2.0 * (1.0 - s)); 108 | } 109 | 110 | vec3 vividLight( vec3 s, vec3 d ) 111 | { 112 | vec3 c; 113 | c.x = vividLight(s.x,d.x); 114 | c.y = vividLight(s.y,d.y); 115 | c.z = vividLight(s.z,d.z); 116 | return c; 117 | } 118 | 119 | vec3 linearLight( vec3 s, vec3 d ) 120 | { 121 | return 2.0 * s + d - 1.0; 122 | } 123 | 124 | float pinLight( float s, float d ) 125 | { 126 | return (2.0 * s - 1.0 > d) ? 2.0 * s - 1.0 : (s < 0.5 * d) ? 2.0 * s : d; 127 | } 128 | 129 | vec3 pinLight( vec3 s, vec3 d ) 130 | { 131 | vec3 c; 132 | c.x = pinLight(s.x,d.x); 133 | c.y = pinLight(s.y,d.y); 134 | c.z = pinLight(s.z,d.z); 135 | return c; 136 | } 137 | 138 | vec3 hardMix( vec3 s, vec3 d ) 139 | { 140 | return floor(s + d); 141 | } 142 | 143 | vec3 difference( vec3 s, vec3 d ) 144 | { 145 | return abs(d - s); 146 | } 147 | 148 | vec3 exclusion( vec3 s, vec3 d ) 149 | { 150 | return s + d - 2.0 * s * d; 151 | } 152 | 153 | vec3 subtract( vec3 s, vec3 d ) 154 | { 155 | return s - d; 156 | } 157 | 158 | vec3 divide( vec3 s, vec3 d ) 159 | { 160 | return s / d; 161 | } 162 | 163 | // rgb<-->hsv functions by Sam Hocevar 164 | // http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl 165 | vec3 rgb2hsv(vec3 c) 166 | { 167 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 168 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 169 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 170 | 171 | float d = q.x - min(q.w, q.y); 172 | float e = 1.0e-10; 173 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 174 | } 175 | 176 | vec3 hsv2rgb(vec3 c) 177 | { 178 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 179 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 180 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 181 | } 182 | 183 | vec3 hue( vec3 s, vec3 d ) 184 | { 185 | d = rgb2hsv(d); 186 | d.x = rgb2hsv(s).x; 187 | return hsv2rgb(d); 188 | } 189 | 190 | vec3 color( vec3 s, vec3 d ) 191 | { 192 | s = rgb2hsv(s); 193 | s.z = rgb2hsv(d).z; 194 | return hsv2rgb(s); 195 | } 196 | 197 | vec3 saturation( vec3 s, vec3 d ) 198 | { 199 | d = rgb2hsv(d); 200 | d.y = rgb2hsv(s).y; 201 | return hsv2rgb(d); 202 | } 203 | 204 | vec3 luminosity( vec3 s, vec3 d ) 205 | { 206 | float dLum = dot(d, vec3(0.3, 0.59, 0.11)); 207 | float sLum = dot(s, vec3(0.3, 0.59, 0.11)); 208 | float lum = sLum - dLum; 209 | vec3 c = d + lum; 210 | float minC = min(min(c.x, c.y), c.z); 211 | float maxC = max(max(c.x, c.y), c.z); 212 | if(minC < 0.0) return sLum + ((c - sLum) * sLum) / (sLum - minC); 213 | else if(maxC > 1.0) return sLum + ((c - sLum) * (1.0 - sLum)) / (maxC - sLum); 214 | else return c; 215 | } 216 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/ShaderHelpers.glslinc: -------------------------------------------------------------------------------- 1 | #define HALF_PI 1.57079632679489661923 2 | #define PI 3.14159265358979323846 3 | #define TWO_PI 6.28318530717958647693 4 | 5 | float map( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 6 | float mapClamped( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return clamp( ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin), outputMin, outputMax ); } 7 | 8 | vec3 map( vec3 value, vec3 inputMin, vec3 inputMax, vec3 outputMin, vec3 outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 9 | 10 | float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } 11 | float stepInOut( float _edge1, float _edge2, float _val ) { return step(_edge1, _val) - step(_edge2,_val); } 12 | float smoothStepInOut( float _low0, float _high0, float _high1, float _low1, float _t ) { return smoothstep( _low0, _high0, _t ) * (1.0 - smoothstep( _high1, _low1, _t )); } 13 | 14 | float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 15 | vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 16 | vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 17 | vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 18 | 19 | float permute(float x) { return mod289(((x*34.0)+1.0)*x); } 20 | vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); } 21 | vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); } 22 | 23 | float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; } 24 | vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; } 25 | 26 | 27 | // ------------------------------------------------------------ 28 | mat4 makeLookAt(vec3 eye, vec3 center, vec3 up) 29 | { 30 | mat4 M; 31 | 32 | vec3 zaxis = normalize(eye - center); 33 | vec3 xaxis = normalize( cross(up, zaxis) ); 34 | vec3 yaxis = cross(zaxis,xaxis); 35 | 36 | M[0] = vec4(xaxis,0); 37 | M[1] = vec4(yaxis,0); 38 | M[2] = vec4(zaxis,0); 39 | M[3] = vec4(eye,1); 40 | 41 | return M; 42 | } 43 | 44 | // ------------------------------------------------------------ 45 | mat4 rotationMatrix(vec3 axis, float angle) 46 | { 47 | axis = normalize(axis); 48 | float s = sin(angle); 49 | float c = cos(angle); 50 | float oc = 1.0 - c; 51 | 52 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 53 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 54 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 55 | 0.0, 0.0, 0.0, 1.0); 56 | } 57 | 58 | 59 | // -------------------------------------- 60 | vec3 randomPointOnSphere( vec3 _random ) 61 | { 62 | float lambda = _random.x; 63 | float u = map( _random.y, 0.0, 1.0, -1.0, 1.0 ); 64 | float phi = _random.z * (2.0 * PI ); 65 | 66 | vec3 p; 67 | p.x = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * cos(phi); 68 | p.y = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * sin(phi); 69 | p.z = pow(lambda, 1.0/3.0) * u; 70 | 71 | return p; 72 | } 73 | 74 | // -------------------------------------- 75 | vec3 opTwistX( vec3 _p, float _angPerUnit ) 76 | { 77 | float c = cos( _angPerUnit * _p.x); 78 | float s = sin( _angPerUnit * _p.x); 79 | mat2 m = mat2(c,-s,s,c); 80 | return vec3( _p.x, m * _p.yz ); 81 | } 82 | 83 | // -------------------------------------- 84 | vec3 opTwistY( vec3 _p, float _angPerUnit ) 85 | { 86 | float c = cos( _angPerUnit * _p.y); 87 | float s = sin( _angPerUnit * _p.y); 88 | mat2 m = mat2(c,-s,s,c); 89 | 90 | vec2 rotXZ = m * _p.xz; 91 | 92 | return vec3( rotXZ.x, _p.y, rotXZ.y ); 93 | } 94 | 95 | // -------------------------------------- 96 | vec3 opTwistZ( vec3 _p, float _angPerUnit ) 97 | { 98 | float c = cos( _angPerUnit * _p.z); 99 | float s = sin( _angPerUnit * _p.z); 100 | mat2 m = mat2(c,-s,s,c); 101 | 102 | vec2 rotXY = m * _p.xy; 103 | 104 | return vec3( rotXY.x, rotXY.y, _p.z ); 105 | } 106 | 107 | // -------------------------------------- 108 | float CatmullRom( float u, float x0, float x1, float x2, float x3 ) 109 | { 110 | float u2 = u * u; 111 | float u3 = u2 * u; 112 | return ((2 * x1) + 113 | (-x0 + x2) * u + 114 | (2*x0 - 5*x1 + 4*x2 - x3) * u2 + 115 | (-x0 + 3*x1 - 3*x2 + x3) * u3) * 0.5; 116 | } 117 | 118 | // http://www.iquilezles.org/www/articles/functions/functions.htm 119 | 120 | // -------------------------------------- 121 | float cubicPulse( float c, float w, float x ) 122 | { 123 | x = abs(x - c); 124 | if( x>w ) return 0.0; 125 | x /= w; 126 | return 1.0 - x*x*(3.0-2.0*x); 127 | } 128 | 129 | // -------------------------------------- 130 | float expStep( float x, float k, float n ) 131 | { 132 | return exp( -k*pow(x,n) ); 133 | } 134 | 135 | // -------------------------------------- 136 | float parabola( float x, float k ) 137 | { 138 | return pow( 4.0*x*(1.0-x), k ); 139 | } 140 | 141 | // -------------------------------------- 142 | float pcurve( float x, float a, float b ) 143 | { 144 | float k = pow(a+b,a+b) / (pow(a,a)*pow(b,b)); 145 | return k * pow( x, a ) * pow( 1.0-x, b ); 146 | } 147 | 148 | // -------------------------------------- 149 | float impulse( float k, float x ) 150 | { 151 | float h = k*x; 152 | return h*exp(1.0-h); 153 | } 154 | 155 | 156 | /* 157 | // ----------------------------- 158 | // Coefficients for Matrix M 159 | // 160 | 161 | #define CM_SPLINE_M11 0.0 162 | #define CM_SPLINE_M12 1.0 163 | #define CM_SPLINE_M13 0.0 164 | #define CM_SPLINE_M14 0.0 165 | #define CM_SPLINE_M21 -0.5 166 | #define CM_SPLINE_M22 0.0 167 | #define CM_SPLINE_M23 0.5 168 | #define CM_SPLINE_M24 0.0 169 | #define CM_SPLINE_M31 1.0 170 | #define CM_SPLINE_M32 -2.5 171 | #define CM_SPLINE_M33 2.0 172 | #define CM_SPLINE_M34 -0.5 173 | #define CM_SPLINE_M41 -0.5 174 | #define CM_SPLINE_M42 1.5 175 | #define CM_SPLINE_M43 -1.5 176 | #define CM_SPLINE_M44 0.5 177 | 178 | // ----------------------------- 179 | float catmullRomSpline(float x, float v0,float v1, 180 | float v2,float v3) 181 | { 182 | 183 | float c1,c2,c3,c4; 184 | 185 | c1 = CM_SPLINE_M12*v1; 186 | c2 = CM_SPLINE_M21*v0 + CM_SPLINE_M23*v2; 187 | c3 = CM_SPLINE_M31*v0 + CM_SPLINE_M32*v1 + CM_SPLINE_M33*v2 + CM_SPLINE_M34*v3; 188 | c4 = CM_SPLINE_M41*v0 + CM_SPLINE_M42*v1 + CM_SPLINE_M43*v2 + CM_SPLINE_M44*v3; 189 | 190 | return(((c4*x + c3)*x +c2)*x + c1); 191 | } 192 | */ 193 | 194 | vec4 grad4(float j, vec4 ip) 195 | { 196 | const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); 197 | vec4 p,s; 198 | 199 | p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; 200 | p.w = 1.5 - dot(abs(p.xyz), ones.xyz); 201 | s = vec4(lessThan(p, vec4(0.0))); 202 | p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; 203 | 204 | return p; 205 | } 206 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/Common/SimplexNoiseDerivatives4D.glslinc: -------------------------------------------------------------------------------- 1 | #define F4 0.309016994374947451 2 | 3 | // ------------------------------------------------------------------------------------- 4 | // 5 | vec4 simplexNoiseDerivatives (vec4 v) 6 | { 7 | const vec4 C = vec4( 0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958); 8 | 9 | vec4 i = floor(v + dot(v, vec4(F4)) ); 10 | vec4 x0 = v - i + dot(i, C.xxxx); 11 | 12 | vec4 i0; 13 | vec3 isX = step( x0.yzw, x0.xxx ); 14 | vec3 isYZ = step( x0.zww, x0.yyz ); 15 | i0.x = isX.x + isX.y + isX.z; 16 | i0.yzw = 1.0 - isX; 17 | i0.y += isYZ.x + isYZ.y; 18 | i0.zw += 1.0 - isYZ.xy; 19 | i0.z += isYZ.z; 20 | i0.w += 1.0 - isYZ.z; 21 | 22 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 23 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 24 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 25 | 26 | vec4 x1 = x0 - i1 + C.xxxx; 27 | vec4 x2 = x0 - i2 + C.yyyy; 28 | vec4 x3 = x0 - i3 + C.zzzz; 29 | vec4 x4 = x0 + C.wwww; 30 | 31 | i = mod289(i); 32 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 33 | vec4 j1 = permute( permute( permute( permute ( i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 34 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 35 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 36 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 37 | 38 | 39 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 40 | 41 | vec4 p0 = grad4(j0, ip); 42 | vec4 p1 = grad4(j1.x, ip); 43 | vec4 p2 = grad4(j1.y, ip); 44 | vec4 p3 = grad4(j1.z, ip); 45 | vec4 p4 = grad4(j1.w, ip); 46 | 47 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 48 | p0 *= norm.x; 49 | p1 *= norm.y; 50 | p2 *= norm.z; 51 | p3 *= norm.w; 52 | p4 *= taylorInvSqrt(dot(p4,p4)); 53 | 54 | vec3 values0 = vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)); //value of contributions from each corner at point 55 | vec2 values1 = vec2(dot(p3, x3), dot(p4, x4)); 56 | 57 | vec3 m0 = max(0.5 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); //(0.5 - x^2) where x is the distance 58 | vec2 m1 = max(0.5 - vec2(dot(x3,x3), dot(x4,x4)), 0.0); 59 | 60 | vec3 temp0 = -6.0 * m0 * m0 * values0; 61 | vec2 temp1 = -6.0 * m1 * m1 * values1; 62 | 63 | vec3 mmm0 = m0 * m0 * m0; 64 | vec2 mmm1 = m1 * m1 * m1; 65 | 66 | float dx = temp0[0] * x0.x + temp0[1] * x1.x + temp0[2] * x2.x + temp1[0] * x3.x + temp1[1] * x4.x + mmm0[0] * p0.x + mmm0[1] * p1.x + mmm0[2] * p2.x + mmm1[0] * p3.x + mmm1[1] * p4.x; 67 | float dy = temp0[0] * x0.y + temp0[1] * x1.y + temp0[2] * x2.y + temp1[0] * x3.y + temp1[1] * x4.y + mmm0[0] * p0.y + mmm0[1] * p1.y + mmm0[2] * p2.y + mmm1[0] * p3.y + mmm1[1] * p4.y; 68 | float dz = temp0[0] * x0.z + temp0[1] * x1.z + temp0[2] * x2.z + temp1[0] * x3.z + temp1[1] * x4.z + mmm0[0] * p0.z + mmm0[1] * p1.z + mmm0[2] * p2.z + mmm1[0] * p3.z + mmm1[1] * p4.z; 69 | float dw = temp0[0] * x0.w + temp0[1] * x1.w + temp0[2] * x2.w + temp1[0] * x3.w + temp1[1] * x4.w + mmm0[0] * p0.w + mmm0[1] * p1.w + mmm0[2] * p2.w + mmm1[0] * p3.w + mmm1[1] * p4.w; 70 | 71 | return vec4(dx, dy, dz, dw) * 49.0; 72 | } 73 | 74 | 75 | // ------------------------------------------------------------------------------------- 76 | // 77 | vec3 curlNoise( vec3 _p, float _time, int _octaves, float _persistence ) 78 | { 79 | vec4 xNoisePotentialDerivatives = vec4(0.0); 80 | vec4 yNoisePotentialDerivatives = vec4(0.0); 81 | vec4 zNoisePotentialDerivatives = vec4(0.0); 82 | 83 | float tmpPersistence = _persistence; 84 | 85 | for (int i = 0; i < _octaves; ++i) 86 | { 87 | float scale = (1.0 / 2.0) * pow(2.0, float(i)); 88 | 89 | float noiseScale = pow(tmpPersistence, float(i)); 90 | if (tmpPersistence == 0.0 && i == 0) //fix undefined behaviour 91 | { 92 | noiseScale = 1.0; 93 | } 94 | 95 | xNoisePotentialDerivatives += simplexNoiseDerivatives(vec4( _p * pow(2.0, float(i)), _time)) * noiseScale * scale; 96 | yNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(123.4, 129845.6, -1239.1)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 97 | zNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(-9519.0, 9051.0, -123.0)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 98 | } 99 | 100 | //compute curl 101 | vec3 curlVal = vec3( zNoisePotentialDerivatives[1] - yNoisePotentialDerivatives[2], 102 | xNoisePotentialDerivatives[2] - zNoisePotentialDerivatives[0], 103 | yNoisePotentialDerivatives[0] - xNoisePotentialDerivatives[1] ); 104 | 105 | 106 | return curlVal; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example-computeshader/bin/data/compute.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | version: 430 3 | 4 | -- compute 5 | 6 | #pragma include "Common/ShaderHelpers.glslinc" 7 | #pragma include "Common/Noise4D.glslinc" 8 | #pragma include "Common/SimplexNoiseDerivatives4D.glslinc" 9 | 10 | struct Particle{ 11 | vec4 pos; 12 | }; 13 | 14 | layout(std140, binding=0) buffer inOutData { 15 | Particle data[]; 16 | }; 17 | 18 | layout(local_size_x = 8, local_size_y = 1, local_size_z = 1) in; 19 | 20 | uniform float Time; 21 | uniform float TimeInc; 22 | 23 | void main() 24 | { 25 | Particle p = data[gl_GlobalInvocationID.x]; 26 | 27 | float S = fract(Time * 0.01) * 0.01; 28 | vec3 V = curlNoise(p.pos.xyz * S, Time * 0.01, 2, 0.5); 29 | 30 | p.pos.xyz += V * TimeInc * 60; 31 | 32 | p.pos.w += 0.1 * TimeInc; 33 | if (p.pos.w > 1) 34 | { 35 | p.pos.w = rand(p.pos.xy * 0.01) * -0.2; 36 | 37 | p.pos.x = rand(p.pos.xy) - 0.5; 38 | p.pos.y = rand(p.pos.yz) - 0.5; 39 | p.pos.z = rand(p.pos.zx) - 0.5; 40 | p.pos *= 3; 41 | 42 | vec3 V0 = fbmvec3(vec4(0, 0, 0, Time * 0.2), 3, 2, 0.5); 43 | vec3 V1 = fbmvec3(vec4(0, 0, 0, (Time - TimeInc) * 0.2), 3, 2, 0.5); 44 | 45 | p.pos.xyz += mix(V0, V1, rand(p.pos.zx)) * 1000; 46 | } 47 | 48 | data[gl_GlobalInvocationID.x] = p; 49 | } -------------------------------------------------------------------------------- /example-computeshader/example-computeshader.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 14 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-computeshader", "example-computeshader.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 17 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 18 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 23 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 25 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 26 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 28 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 29 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 30 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /example-computeshader/example-computeshader.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A} 23 | Win32Proj 24 | example-computeshader 25 | 26 | 27 | 28 | Application 29 | Unicode 30 | v140 31 | 32 | 33 | Application 34 | Unicode 35 | v140 36 | 37 | 38 | Application 39 | Unicode 40 | true 41 | v140 42 | 43 | 44 | Application 45 | Unicode 46 | true 47 | v140 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | bin\ 69 | obj\$(Configuration)\ 70 | $(ProjectName)_debug 71 | true 72 | true 73 | 74 | 75 | bin\ 76 | obj\$(Configuration)\ 77 | $(ProjectName)_debug 78 | true 79 | true 80 | 81 | 82 | bin\ 83 | obj\$(Configuration)\ 84 | false 85 | 86 | 87 | bin\ 88 | obj\$(Configuration)\ 89 | false 90 | 91 | 92 | 93 | Disabled 94 | EnableFastChecks 95 | %(PreprocessorDefinitions) 96 | MultiThreadedDebugDLL 97 | Level3 98 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 99 | CompileAsCpp 100 | 101 | 102 | true 103 | Console 104 | false 105 | %(AdditionalDependencies) 106 | %(AdditionalLibraryDirectories) 107 | 108 | 109 | 110 | 111 | 112 | Disabled 113 | EnableFastChecks 114 | %(PreprocessorDefinitions) 115 | MultiThreadedDebugDLL 116 | Level3 117 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 118 | CompileAsCpp 119 | true 120 | 121 | 122 | true 123 | Console 124 | false 125 | %(AdditionalDependencies) 126 | %(AdditionalLibraryDirectories) 127 | 128 | 129 | 130 | 131 | 132 | false 133 | %(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | Level3 136 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 137 | CompileAsCpp 138 | true 139 | 140 | 141 | false 142 | false 143 | Console 144 | true 145 | true 146 | false 147 | %(AdditionalDependencies) 148 | %(AdditionalLibraryDirectories) 149 | 150 | 151 | 152 | 153 | 154 | false 155 | %(PreprocessorDefinitions) 156 | MultiThreadedDLL 157 | Level3 158 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 159 | CompileAsCpp 160 | 161 | 162 | false 163 | false 164 | Console 165 | true 166 | true 167 | false 168 | %(AdditionalDependencies) 169 | %(AdditionalLibraryDirectories) 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | {5837595d-aca9-485c-8e76-729040ce4b0b} 182 | 183 | 184 | 185 | 186 | /D_DEBUG %(AdditionalOptions) 187 | /D_DEBUG %(AdditionalOptions) 188 | $(OF_ROOT)\libs\openFrameworksCompiled\project\vs 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /example-computeshader/example-computeshader.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | src 6 | 7 | 8 | src 9 | 10 | 11 | 12 | 13 | {d8376475-7454-4a24-b08a-aac121d3ad6f} 14 | 15 | 16 | {71834F65-F3A9-211E-73B8-DC85} 17 | 18 | 19 | {CD60902F-C905-86E8-6E9D-BB17} 20 | 21 | 22 | {20F1F5CE-83F5-6111-D1EE-C15F} 23 | 24 | 25 | 26 | 27 | addons\ofxShaderRunner\src 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /example-computeshader/icon.rc: -------------------------------------------------------------------------------- 1 | // Icon Resource Definition 2 | #define MAIN_ICON 102 3 | 4 | #if defined(_DEBUG) 5 | MAIN_ICON ICON "icon_debug.ico" 6 | #else 7 | MAIN_ICON ICON "icon.ico" 8 | #endif 9 | -------------------------------------------------------------------------------- /example-computeshader/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | 3 | #include "ofxShaderRunner.h" 4 | 5 | class ofApp : public ofBaseApp 6 | { 7 | public: 8 | 9 | ofEasyCam cam; 10 | ofxShaderRunner shader; 11 | 12 | ofVbo vbo; 13 | ofBufferObject buffer; 14 | 15 | int N = 100000; 16 | 17 | struct Particle { 18 | ofVec4f pos; 19 | }; 20 | 21 | void setup() 22 | { 23 | ofSetFrameRate(0); 24 | ofSetVerticalSync(false); 25 | ofBackground(0); 26 | 27 | shader.load("compute.glsl"); 28 | 29 | vector data(N); 30 | for (int i = 0; i < N; i++) 31 | { 32 | float R = 1000; 33 | data[i].pos.x = ofRandom(-R, R); 34 | data[i].pos.y = ofRandom(-R, R); 35 | data[i].pos.z = ofRandom(-R, R); 36 | data[i].pos.w = ofRandom(1); 37 | } 38 | 39 | buffer.allocate(data, GL_DYNAMIC_DRAW); 40 | buffer.bindBase(GL_SHADER_STORAGE_BUFFER, 0); 41 | 42 | vbo.setVertexBuffer(buffer, 3, sizeof(Particle), 0); 43 | } 44 | 45 | void update() 46 | { 47 | ofSetWindowTitle(ofToString(ofGetFrameRate())); 48 | 49 | shader.begin(); 50 | shader.dispatchCompute(N, 1, 1); 51 | shader.end(); 52 | } 53 | 54 | 55 | void draw() 56 | { 57 | ofEnableBlendMode(OF_BLENDMODE_ADD); 58 | 59 | cam.begin(); 60 | ofDrawAxis(10); 61 | ofSetColor(255, 32); 62 | vbo.draw(GL_POINTS, 0, N); 63 | cam.end(); 64 | } 65 | 66 | void keyPressed(int key) 67 | { 68 | } 69 | 70 | void keyReleased(int key) 71 | { 72 | } 73 | 74 | void mouseMoved(int x, int y) 75 | { 76 | } 77 | 78 | void mouseDragged(int x, int y, int button) 79 | { 80 | } 81 | 82 | void mousePressed(int x, int y, int button) 83 | { 84 | } 85 | 86 | void mouseReleased(int x, int y, int button) 87 | { 88 | } 89 | 90 | void windowResized(int w, int h) 91 | { 92 | } 93 | }; 94 | 95 | 96 | int main(int argc, const char** argv) 97 | { 98 | ofGLWindowSettings settings; 99 | settings.setGLVersion(4, 3); 100 | settings.width = 1280; 101 | settings.height = 720; 102 | ofCreateWindow(settings); 103 | ofRunApp(new ofApp); 104 | return 0; 105 | } -------------------------------------------------------------------------------- /example-glslify/.gitignore: -------------------------------------------------------------------------------- 1 | .svn 2 | .hg 3 | .cvs 4 | 5 | # osx 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | Icon 10 | *.app 11 | ._* 12 | DerivedData 13 | 14 | # xcode3 15 | *.mode1v3 16 | *.pbxuser 17 | build/ 18 | 19 | # xcode4 20 | *.xcodeproj/* 21 | !*.xcodeproj/project.pbxproj 22 | !*.xcodeproj/default.* 23 | **/*.xcodeproj/* 24 | !**/*.xcodeproj/project.pbxproj 25 | !**/*.xcodeproj/default.* 26 | *.xcworkspace/* 27 | !*.xcworkspace/contents.xcworkspacedata 28 | 29 | # windows 30 | *.exe 31 | Thumbs.db 32 | ehthumbs.db 33 | 34 | # vs 35 | ipch/ 36 | [Bb]in/ 37 | [Oo]bj/ 38 | *.aps 39 | *.ncb 40 | *.opensdf 41 | *.sdf 42 | *.cachefile 43 | *.suo 44 | *.user 45 | *.sln.docstates 46 | *.opendb 47 | 48 | # Object files 49 | *.o 50 | 51 | # Libraries 52 | *.lib 53 | *.a 54 | 55 | # Shared objects (inc. Windows DLLs) 56 | *.dll 57 | *.so 58 | *.so.* 59 | *.dylib 60 | -------------------------------------------------------------------------------- /example-glslify/Makefile: -------------------------------------------------------------------------------- 1 | # Attempt to load a config.make file. 2 | # If none is found, project defaults in config.project.make will be used. 3 | ifneq ($(wildcard config.make),) 4 | include config.make 5 | endif 6 | 7 | # make sure the the OF_ROOT location is defined 8 | ifndef OF_ROOT 9 | OF_ROOT=$(realpath ../../..) 10 | endif 11 | 12 | # call the project makefile! 13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk 14 | -------------------------------------------------------------------------------- /example-glslify/Project.xcconfig: -------------------------------------------------------------------------------- 1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. 2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED 3 | OF_PATH = ../../.. 4 | 5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE 6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" 7 | 8 | //ICONS - NEW IN 0072 9 | ICON_NAME_DEBUG = icon-debug.icns 10 | ICON_NAME_RELEASE = icon.icns 11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ 12 | 13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: 14 | //ICON_FILE_PATH = bin/data/ 15 | 16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS) 17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) 18 | -------------------------------------------------------------------------------- /example-glslify/addons.make: -------------------------------------------------------------------------------- 1 | ofxShaderRunner 2 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/Common.glslinc: -------------------------------------------------------------------------------- 1 | vec2 grid(int x, int y) 2 | { 3 | return vec2(mod(gl_VertexID, x) / x, float(gl_VertexID / x) / y); 4 | } 5 | 6 | vec3 grid(int x, int y, int z) 7 | { 8 | int vid = gl_VertexID; 9 | vec3 id; 10 | float T = gl_VertexID / (x * y); 11 | float TT = mod(gl_VertexID, x * y); 12 | id.z = T / (z - 1); 13 | id.y = floor(TT / y) / (y - 1); 14 | id.x = (mod(TT, y)) / (x - 1); 15 | return id; 16 | } 17 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/Noise2D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D simplex noise function. 3 | // Author : Ian McEwan, Ashima Arts. 4 | // Maintainer : ijm 5 | // Lastmod : 20110822 (ijm) 6 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 7 | // Distributed under the MIT License. See LICENSE file. 8 | // https://github.com/ashima/webgl-noise 9 | // 10 | 11 | // ------------------------------------------------------------------------------------- 12 | // 13 | float snoise(vec2 v) 14 | { 15 | const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 16 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 17 | -0.577350269189626, // -1.0 + 2.0 * C.x 18 | 0.024390243902439); // 1.0 / 41.0 19 | // First corner 20 | vec2 i = floor(v + dot(v, C.yy) ); 21 | vec2 x0 = v - i + dot(i, C.xx); 22 | 23 | // Other corners 24 | vec2 i1; 25 | //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 26 | //i1.y = 1.0 - i1.x; 27 | i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); 28 | // x0 = x0 - 0.0 + 0.0 * C.xx ; 29 | // x1 = x0 - i1 + 1.0 * C.xx ; 30 | // x2 = x0 - 1.0 + 2.0 * C.xx ; 31 | vec4 x12 = x0.xyxy + C.xxzz; 32 | x12.xy -= i1; 33 | 34 | // Permutations 35 | i = mod289(i); // Avoid truncation effects in permutation 36 | vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) 37 | + i.x + vec3(0.0, i1.x, 1.0 )); 38 | 39 | vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); 40 | m = m*m ; 41 | m = m*m ; 42 | 43 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 44 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 45 | 46 | vec3 x = 2.0 * fract(p * C.www) - 1.0; 47 | vec3 h = abs(x) - 0.5; 48 | vec3 ox = floor(x + 0.5); 49 | vec3 a0 = x - ox; 50 | 51 | // Normalise gradients implicitly by scaling m 52 | // Approximation of: m *= inversesqrt( a0*a0 + h*h ); 53 | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); 54 | 55 | // Compute final noise value at P 56 | vec3 g; 57 | g.x = a0.x * x0.x + h.x * x0.y; 58 | g.yz = a0.yz * x12.xz + h.yz * x12.yw; 59 | return 130.0 * dot(m, g); 60 | } 61 | 62 | // ------------------------------------------------------------------------------------- 63 | // 64 | float snoiseu(vec2 v) 65 | { 66 | return (snoise( v ) + 1.0) * 0.5; 67 | } 68 | 69 | // ------------------------------------------------------------------------------------- 70 | // 71 | float fbm_5oct( vec2 p ) 72 | { 73 | float f = 0.0; 74 | f += 0.50000*snoise( p ); p = p*2.02; 75 | f += 0.25000*snoise( p ); p = p*2.03; 76 | f += 0.12500*snoise( p ); p = p*2.01; 77 | f += 0.06250*snoise( p ); p = p*2.04; 78 | f += 0.03125*snoise( p ); 79 | return f/0.984375; 80 | } 81 | 82 | // ------------------------------------------------------------------------------------- 83 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 84 | // 85 | float fbm(vec2 P, int octaves, float lacunarity, float gain) 86 | { 87 | float sum = 0.0; 88 | float amp = 1.0; 89 | vec2 pp = P; 90 | 91 | for( int i = 0; i < octaves; i+=1) 92 | { 93 | amp *= gain; 94 | sum += amp * snoise(pp); 95 | pp *= lacunarity; 96 | } 97 | 98 | return sum; 99 | } 100 | 101 | // ------------------------------------------------------------------------------------- 102 | // Returns the FBM in the range 0..1 103 | // 104 | float fbmu(vec2 _p, int _octaves, float _lacunarity, float _persistence ) 105 | { 106 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/Noise3D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // ------------------------------------------------------------------------------------- 13 | // 14 | float snoise(vec3 v) 15 | { 16 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 17 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 18 | 19 | // First corner 20 | vec3 i = floor(v + dot(v, C.yyy) ); 21 | vec3 x0 = v - i + dot(i, C.xxx) ; 22 | 23 | // Other corners 24 | vec3 g = step(x0.yzx, x0.xyz); 25 | vec3 l = 1.0 - g; 26 | vec3 i1 = min( g.xyz, l.zxy ); 27 | vec3 i2 = max( g.xyz, l.zxy ); 28 | 29 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 30 | // x1 = x0 - i1 + 1.0 * C.xxx; 31 | // x2 = x0 - i2 + 2.0 * C.xxx; 32 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 33 | vec3 x1 = x0 - i1 + C.xxx; 34 | vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 35 | vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 36 | 37 | // Permutations 38 | i = mod289(i); 39 | vec4 p = permute( permute( permute( 40 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 41 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 42 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 43 | 44 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 45 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 46 | float n_ = 0.142857142857; // 1.0/7.0 47 | vec3 ns = n_ * D.wyz - D.xzx; 48 | 49 | vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 50 | 51 | vec4 x_ = floor(j * ns.z); 52 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 53 | 54 | vec4 x = x_ *ns.x + ns.yyyy; 55 | vec4 y = y_ *ns.x + ns.yyyy; 56 | vec4 h = 1.0 - abs(x) - abs(y); 57 | 58 | vec4 b0 = vec4( x.xy, y.xy ); 59 | vec4 b1 = vec4( x.zw, y.zw ); 60 | 61 | //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; 62 | //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; 63 | vec4 s0 = floor(b0)*2.0 + 1.0; 64 | vec4 s1 = floor(b1)*2.0 + 1.0; 65 | vec4 sh = -step(h, vec4(0.0)); 66 | 67 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 68 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 69 | 70 | vec3 p0 = vec3(a0.xy,h.x); 71 | vec3 p1 = vec3(a0.zw,h.y); 72 | vec3 p2 = vec3(a1.xy,h.z); 73 | vec3 p3 = vec3(a1.zw,h.w); 74 | 75 | //Normalise gradients 76 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 77 | p0 *= norm.x; 78 | p1 *= norm.y; 79 | p2 *= norm.z; 80 | p3 *= norm.w; 81 | 82 | // Mix final noise value 83 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 84 | m = m * m; 85 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 86 | dot(p2,x2), dot(p3,x3) ) ); 87 | } 88 | 89 | // ------------------------------------------------------------------------------------- 90 | // 91 | float fbm_2oct(vec3 p) 92 | { 93 | float final = snoise(p); 94 | p *= 1.94; 95 | final += snoise(p) * 0.5; 96 | return final / 1.5; 97 | } 98 | 99 | // ------------------------------------------------------------------------------------- 100 | // 101 | float fbm_3oct(vec3 p) 102 | { 103 | float final = snoise(p); 104 | p *= 1.94; 105 | final += snoise(p) * 0.5; 106 | p *= 3.75; 107 | final += snoise(p) * 0.25; 108 | return final / 1.75; 109 | 110 | } 111 | 112 | // ------------------------------------------------------------------------------------- 113 | // 114 | float fbm_5oct( vec3 p ) 115 | { 116 | float f = 0.0; 117 | f += 0.50000*snoise( p ); p = p*2.02; 118 | f += 0.25000*snoise( p ); p = p*2.03; 119 | f += 0.12500*snoise( p ); p = p*2.01; 120 | f += 0.06250*snoise( p ); p = p*2.04; 121 | f += 0.03125*snoise( p ); 122 | return f/0.984375; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 127 | // 128 | float fbm(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 129 | { 130 | float sum = 0.0; 131 | float amp = 1.0; 132 | vec3 pp = _p; 133 | float totalAmp = 0.0; 134 | 135 | for( int i = 0; i < _octaves; i++) 136 | { 137 | amp *= _persistence; 138 | totalAmp += amp; 139 | sum += amp * snoise(pp); 140 | pp *= _lacunarity; 141 | } 142 | 143 | return sum / totalAmp; 144 | } 145 | 146 | // ------------------------------------------------------------------------------------- 147 | // Returns the FBM in the range 0..1 148 | // 149 | float fbmu(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 150 | { 151 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 152 | } 153 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/Noise4D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // (sqrt(5) - 1)/4 = F4, used once below 13 | #define F4 0.309016994374947451 14 | 15 | // ------------------------------------------------------------------------------------- 16 | // 17 | float snoise(vec4 v) 18 | { 19 | const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4 20 | 0.276393202250021, // 2 * G4 21 | 0.414589803375032, // 3 * G4 22 | -0.447213595499958); // -1 + 4 * G4 23 | 24 | // First corner 25 | vec4 i = floor(v + dot(v, vec4(F4)) ); 26 | vec4 x0 = v - i + dot(i, C.xxxx); 27 | 28 | // Other corners 29 | 30 | // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) 31 | vec4 i0; 32 | vec3 isX = step( x0.yzw, x0.xxx ); 33 | vec3 isYZ = step( x0.zww, x0.yyz ); 34 | // i0.x = dot( isX, vec3( 1.0 ) ); 35 | i0.x = isX.x + isX.y + isX.z; 36 | i0.yzw = 1.0 - isX; 37 | // i0.y += dot( isYZ.xy, vec2( 1.0 ) ); 38 | i0.y += isYZ.x + isYZ.y; 39 | i0.zw += 1.0 - isYZ.xy; 40 | i0.z += isYZ.z; 41 | i0.w += 1.0 - isYZ.z; 42 | 43 | // i0 now contains the unique values 0,1,2,3 in each channel 44 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 45 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 46 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 47 | 48 | // x0 = x0 - 0.0 + 0.0 * C.xxxx 49 | // x1 = x0 - i1 + 1.0 * C.xxxx 50 | // x2 = x0 - i2 + 2.0 * C.xxxx 51 | // x3 = x0 - i3 + 3.0 * C.xxxx 52 | // x4 = x0 - 1.0 + 4.0 * C.xxxx 53 | vec4 x1 = x0 - i1 + C.xxxx; 54 | vec4 x2 = x0 - i2 + C.yyyy; 55 | vec4 x3 = x0 - i3 + C.zzzz; 56 | vec4 x4 = x0 + C.wwww; 57 | 58 | // Permutations 59 | i = mod289(i); 60 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 61 | vec4 j1 = permute( permute( permute( permute ( 62 | i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 63 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 64 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 65 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 66 | 67 | // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope 68 | // 7*7*6 = 294, which is close to the ring size 17*17 = 289. 69 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 70 | 71 | vec4 p0 = grad4(j0, ip); 72 | vec4 p1 = grad4(j1.x, ip); 73 | vec4 p2 = grad4(j1.y, ip); 74 | vec4 p3 = grad4(j1.z, ip); 75 | vec4 p4 = grad4(j1.w, ip); 76 | 77 | // Normalise gradients 78 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 79 | p0 *= norm.x; 80 | p1 *= norm.y; 81 | p2 *= norm.z; 82 | p3 *= norm.w; 83 | p4 *= taylorInvSqrt(dot(p4,p4)); 84 | 85 | // Mix contributions from the five corners 86 | vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); 87 | vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); 88 | m0 = m0 * m0; 89 | m1 = m1 * m1; 90 | return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) 91 | + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; 92 | 93 | } 94 | 95 | 96 | // ------------------------------------------------------------------------------------- 97 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 98 | // 99 | float fbm(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 100 | { 101 | float sum = 0.0; 102 | float amp = 1.0; 103 | vec4 pp = _p; 104 | float totalAmp = 0.0; 105 | 106 | for( int i = 0; i < _octaves; i++) 107 | { 108 | amp *= _persistence; 109 | totalAmp += amp; 110 | sum += amp * snoise(pp); 111 | pp *= _lacunarity; 112 | } 113 | 114 | return sum / totalAmp; 115 | } 116 | 117 | // ------------------------------------------------------------------------------------- 118 | // Returns the FBM in the range 0..1 119 | // 120 | float fbmu(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 121 | { 122 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // 127 | vec3 fbmvec3(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 128 | { 129 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 130 | tmp.x = fbm( vec4( _p.x, _p.y, _p.z, _p.w ), _octaves, _lacunarity, _persistence ); 131 | tmp.y = fbm( vec4( _p.y + 3.422, _p.x + 21.13, _p.w + 312.2, _p.z + 132.32 ), _octaves, _lacunarity, _persistence ); 132 | tmp.z = fbm( vec4( _p.w + 1.234, _p.z + 87.31, _p.y + 2367.1, _p.x + 894.21 ), _octaves, _lacunarity, _persistence ); 133 | return tmp; 134 | } 135 | 136 | // ------------------------------------------------------------------------------------- 137 | vec3 snoisevec3( vec4 _p ) 138 | { 139 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 140 | tmp.x = snoise( vec4( _p.x, _p.y, _p.z, _p.w ) ); 141 | tmp.y = snoise( vec4( _p.y, _p.x, _p.w, _p.z ) ); 142 | tmp.z = snoise( vec4( _p.w, _p.z, _p.y, _p.x ) ); 143 | return tmp; 144 | } -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/PhotoshopBlendModes.glslinc: -------------------------------------------------------------------------------- 1 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 2 | // 3 | // 25 of the layer blending modes from Photoshop. 4 | // 5 | // The ones I couldn't figure out are from Nvidia's advanced blend equations extension spec - 6 | // http://www.opengl.org/registry/specs/NV/blend_equation_advanced.txt 7 | // 8 | // ~bj.2013 9 | // 10 | 11 | vec3 darken( vec3 s, vec3 d ) 12 | { 13 | return min(s,d); 14 | } 15 | 16 | vec3 multiply( vec3 s, vec3 d ) 17 | { 18 | return s*d; 19 | } 20 | 21 | vec3 colorBurn( vec3 s, vec3 d ) 22 | { 23 | return 1.0 - (1.0 - d) / s; 24 | } 25 | 26 | vec3 linearBurn( vec3 s, vec3 d ) 27 | { 28 | return s + d - 1.0; 29 | } 30 | 31 | vec3 darkerColor( vec3 s, vec3 d ) 32 | { 33 | return (s.x + s.y + s.z < d.x + d.y + d.z) ? s : d; 34 | } 35 | 36 | vec3 lighten( vec3 s, vec3 d ) 37 | { 38 | return max(s,d); 39 | } 40 | 41 | vec3 screen( vec3 s, vec3 d ) 42 | { 43 | return s + d - s * d; 44 | } 45 | 46 | vec3 colorDodge( vec3 s, vec3 d ) 47 | { 48 | return d / (1.0 - s); 49 | } 50 | 51 | vec3 linearDodge( vec3 s, vec3 d ) 52 | { 53 | return s + d; 54 | } 55 | 56 | vec3 lighterColor( vec3 s, vec3 d ) 57 | { 58 | return (s.x + s.y + s.z > d.x + d.y + d.z) ? s : d; 59 | } 60 | 61 | float overlay( float s, float d ) 62 | { 63 | return (d < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 64 | } 65 | 66 | vec3 overlay( vec3 s, vec3 d ) 67 | { 68 | vec3 c; 69 | c.x = overlay(s.x,d.x); 70 | c.y = overlay(s.y,d.y); 71 | c.z = overlay(s.z,d.z); 72 | return c; 73 | } 74 | 75 | float softLight( float s, float d ) 76 | { 77 | return (s < 0.5) ? d - (1.0 - 2.0 * s) * d * (1.0 - d) 78 | : (d < 0.25) ? d + (2.0 * s - 1.0) * d * ((16.0 * d - 12.0) * d + 3.0) 79 | : d + (2.0 * s - 1.0) * (sqrt(d) - d); 80 | } 81 | 82 | vec3 softLight( vec3 s, vec3 d ) 83 | { 84 | vec3 c; 85 | c.x = softLight(s.x,d.x); 86 | c.y = softLight(s.y,d.y); 87 | c.z = softLight(s.z,d.z); 88 | return c; 89 | } 90 | 91 | float hardLight( float s, float d ) 92 | { 93 | return (s < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 94 | } 95 | 96 | vec3 hardLight( vec3 s, vec3 d ) 97 | { 98 | vec3 c; 99 | c.x = hardLight(s.x,d.x); 100 | c.y = hardLight(s.y,d.y); 101 | c.z = hardLight(s.z,d.z); 102 | return c; 103 | } 104 | 105 | float vividLight( float s, float d ) 106 | { 107 | return (s < 0.5) ? 1.0 - (1.0 - d) / (2.0 * s) : d / (2.0 * (1.0 - s)); 108 | } 109 | 110 | vec3 vividLight( vec3 s, vec3 d ) 111 | { 112 | vec3 c; 113 | c.x = vividLight(s.x,d.x); 114 | c.y = vividLight(s.y,d.y); 115 | c.z = vividLight(s.z,d.z); 116 | return c; 117 | } 118 | 119 | vec3 linearLight( vec3 s, vec3 d ) 120 | { 121 | return 2.0 * s + d - 1.0; 122 | } 123 | 124 | float pinLight( float s, float d ) 125 | { 126 | return (2.0 * s - 1.0 > d) ? 2.0 * s - 1.0 : (s < 0.5 * d) ? 2.0 * s : d; 127 | } 128 | 129 | vec3 pinLight( vec3 s, vec3 d ) 130 | { 131 | vec3 c; 132 | c.x = pinLight(s.x,d.x); 133 | c.y = pinLight(s.y,d.y); 134 | c.z = pinLight(s.z,d.z); 135 | return c; 136 | } 137 | 138 | vec3 hardMix( vec3 s, vec3 d ) 139 | { 140 | return floor(s + d); 141 | } 142 | 143 | vec3 difference( vec3 s, vec3 d ) 144 | { 145 | return abs(d - s); 146 | } 147 | 148 | vec3 exclusion( vec3 s, vec3 d ) 149 | { 150 | return s + d - 2.0 * s * d; 151 | } 152 | 153 | vec3 subtract( vec3 s, vec3 d ) 154 | { 155 | return s - d; 156 | } 157 | 158 | vec3 divide( vec3 s, vec3 d ) 159 | { 160 | return s / d; 161 | } 162 | 163 | // rgb<-->hsv functions by Sam Hocevar 164 | // http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl 165 | vec3 rgb2hsv(vec3 c) 166 | { 167 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 168 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 169 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 170 | 171 | float d = q.x - min(q.w, q.y); 172 | float e = 1.0e-10; 173 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 174 | } 175 | 176 | vec3 hsv2rgb(vec3 c) 177 | { 178 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 179 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 180 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 181 | } 182 | 183 | vec3 hue( vec3 s, vec3 d ) 184 | { 185 | d = rgb2hsv(d); 186 | d.x = rgb2hsv(s).x; 187 | return hsv2rgb(d); 188 | } 189 | 190 | vec3 color( vec3 s, vec3 d ) 191 | { 192 | s = rgb2hsv(s); 193 | s.z = rgb2hsv(d).z; 194 | return hsv2rgb(s); 195 | } 196 | 197 | vec3 saturation( vec3 s, vec3 d ) 198 | { 199 | d = rgb2hsv(d); 200 | d.y = rgb2hsv(s).y; 201 | return hsv2rgb(d); 202 | } 203 | 204 | vec3 luminosity( vec3 s, vec3 d ) 205 | { 206 | float dLum = dot(d, vec3(0.3, 0.59, 0.11)); 207 | float sLum = dot(s, vec3(0.3, 0.59, 0.11)); 208 | float lum = sLum - dLum; 209 | vec3 c = d + lum; 210 | float minC = min(min(c.x, c.y), c.z); 211 | float maxC = max(max(c.x, c.y), c.z); 212 | if(minC < 0.0) return sLum + ((c - sLum) * sLum) / (sLum - minC); 213 | else if(maxC > 1.0) return sLum + ((c - sLum) * (1.0 - sLum)) / (maxC - sLum); 214 | else return c; 215 | } 216 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/ShaderHelpers.glslinc: -------------------------------------------------------------------------------- 1 | #define HALF_PI 1.57079632679489661923 2 | #define PI 3.14159265358979323846 3 | #define TWO_PI 6.28318530717958647693 4 | 5 | float map( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 6 | float mapClamped( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return clamp( ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin), outputMin, outputMax ); } 7 | 8 | vec3 map( vec3 value, vec3 inputMin, vec3 inputMax, vec3 outputMin, vec3 outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 9 | 10 | float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } 11 | float stepInOut( float _edge1, float _edge2, float _val ) { return step(_edge1, _val) - step(_edge2,_val); } 12 | float smoothStepInOut( float _low0, float _high0, float _high1, float _low1, float _t ) { return smoothstep( _low0, _high0, _t ) * (1.0 - smoothstep( _high1, _low1, _t )); } 13 | 14 | float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 15 | vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 16 | vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 17 | vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 18 | 19 | float permute(float x) { return mod289(((x*34.0)+1.0)*x); } 20 | vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); } 21 | vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); } 22 | 23 | float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; } 24 | vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; } 25 | 26 | 27 | // ------------------------------------------------------------ 28 | mat4 makeLookAt(vec3 eye, vec3 center, vec3 up) 29 | { 30 | mat4 M; 31 | 32 | vec3 zaxis = normalize(eye - center); 33 | vec3 xaxis = normalize( cross(up, zaxis) ); 34 | vec3 yaxis = cross(zaxis,xaxis); 35 | 36 | M[0] = vec4(xaxis,0); 37 | M[1] = vec4(yaxis,0); 38 | M[2] = vec4(zaxis,0); 39 | M[3] = vec4(eye,1); 40 | 41 | return M; 42 | } 43 | 44 | // ------------------------------------------------------------ 45 | mat4 rotationMatrix(vec3 axis, float angle) 46 | { 47 | axis = normalize(axis); 48 | float s = sin(angle); 49 | float c = cos(angle); 50 | float oc = 1.0 - c; 51 | 52 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 53 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 54 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 55 | 0.0, 0.0, 0.0, 1.0); 56 | } 57 | 58 | 59 | // -------------------------------------- 60 | vec3 randomPointOnSphere( vec3 _random ) 61 | { 62 | float lambda = _random.x; 63 | float u = map( _random.y, 0.0, 1.0, -1.0, 1.0 ); 64 | float phi = _random.z * (2.0 * PI ); 65 | 66 | vec3 p; 67 | p.x = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * cos(phi); 68 | p.y = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * sin(phi); 69 | p.z = pow(lambda, 1.0/3.0) * u; 70 | 71 | return p; 72 | } 73 | 74 | // -------------------------------------- 75 | vec3 opTwistX( vec3 _p, float _angPerUnit ) 76 | { 77 | float c = cos( _angPerUnit * _p.x); 78 | float s = sin( _angPerUnit * _p.x); 79 | mat2 m = mat2(c,-s,s,c); 80 | return vec3( _p.x, m * _p.yz ); 81 | } 82 | 83 | // -------------------------------------- 84 | vec3 opTwistY( vec3 _p, float _angPerUnit ) 85 | { 86 | float c = cos( _angPerUnit * _p.y); 87 | float s = sin( _angPerUnit * _p.y); 88 | mat2 m = mat2(c,-s,s,c); 89 | 90 | vec2 rotXZ = m * _p.xz; 91 | 92 | return vec3( rotXZ.x, _p.y, rotXZ.y ); 93 | } 94 | 95 | // -------------------------------------- 96 | vec3 opTwistZ( vec3 _p, float _angPerUnit ) 97 | { 98 | float c = cos( _angPerUnit * _p.z); 99 | float s = sin( _angPerUnit * _p.z); 100 | mat2 m = mat2(c,-s,s,c); 101 | 102 | vec2 rotXY = m * _p.xy; 103 | 104 | return vec3( rotXY.x, rotXY.y, _p.z ); 105 | } 106 | 107 | // -------------------------------------- 108 | float CatmullRom( float u, float x0, float x1, float x2, float x3 ) 109 | { 110 | float u2 = u * u; 111 | float u3 = u2 * u; 112 | return ((2 * x1) + 113 | (-x0 + x2) * u + 114 | (2*x0 - 5*x1 + 4*x2 - x3) * u2 + 115 | (-x0 + 3*x1 - 3*x2 + x3) * u3) * 0.5; 116 | } 117 | 118 | // http://www.iquilezles.org/www/articles/functions/functions.htm 119 | 120 | // -------------------------------------- 121 | float cubicPulse( float c, float w, float x ) 122 | { 123 | x = abs(x - c); 124 | if( x>w ) return 0.0; 125 | x /= w; 126 | return 1.0 - x*x*(3.0-2.0*x); 127 | } 128 | 129 | // -------------------------------------- 130 | float expStep( float x, float k, float n ) 131 | { 132 | return exp( -k*pow(x,n) ); 133 | } 134 | 135 | // -------------------------------------- 136 | float parabola( float x, float k ) 137 | { 138 | return pow( 4.0*x*(1.0-x), k ); 139 | } 140 | 141 | // -------------------------------------- 142 | float pcurve( float x, float a, float b ) 143 | { 144 | float k = pow(a+b,a+b) / (pow(a,a)*pow(b,b)); 145 | return k * pow( x, a ) * pow( 1.0-x, b ); 146 | } 147 | 148 | // -------------------------------------- 149 | float impulse( float k, float x ) 150 | { 151 | float h = k*x; 152 | return h*exp(1.0-h); 153 | } 154 | 155 | 156 | /* 157 | // ----------------------------- 158 | // Coefficients for Matrix M 159 | // 160 | 161 | #define CM_SPLINE_M11 0.0 162 | #define CM_SPLINE_M12 1.0 163 | #define CM_SPLINE_M13 0.0 164 | #define CM_SPLINE_M14 0.0 165 | #define CM_SPLINE_M21 -0.5 166 | #define CM_SPLINE_M22 0.0 167 | #define CM_SPLINE_M23 0.5 168 | #define CM_SPLINE_M24 0.0 169 | #define CM_SPLINE_M31 1.0 170 | #define CM_SPLINE_M32 -2.5 171 | #define CM_SPLINE_M33 2.0 172 | #define CM_SPLINE_M34 -0.5 173 | #define CM_SPLINE_M41 -0.5 174 | #define CM_SPLINE_M42 1.5 175 | #define CM_SPLINE_M43 -1.5 176 | #define CM_SPLINE_M44 0.5 177 | 178 | // ----------------------------- 179 | float catmullRomSpline(float x, float v0,float v1, 180 | float v2,float v3) 181 | { 182 | 183 | float c1,c2,c3,c4; 184 | 185 | c1 = CM_SPLINE_M12*v1; 186 | c2 = CM_SPLINE_M21*v0 + CM_SPLINE_M23*v2; 187 | c3 = CM_SPLINE_M31*v0 + CM_SPLINE_M32*v1 + CM_SPLINE_M33*v2 + CM_SPLINE_M34*v3; 188 | c4 = CM_SPLINE_M41*v0 + CM_SPLINE_M42*v1 + CM_SPLINE_M43*v2 + CM_SPLINE_M44*v3; 189 | 190 | return(((c4*x + c3)*x +c2)*x + c1); 191 | } 192 | */ 193 | 194 | vec4 grad4(float j, vec4 ip) 195 | { 196 | const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); 197 | vec4 p,s; 198 | 199 | p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; 200 | p.w = 1.5 - dot(abs(p.xyz), ones.xyz); 201 | s = vec4(lessThan(p, vec4(0.0))); 202 | p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; 203 | 204 | return p; 205 | } 206 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/SimplexNoiseDerivatives4D.glslinc: -------------------------------------------------------------------------------- 1 | #define F4 0.309016994374947451 2 | 3 | // ------------------------------------------------------------------------------------- 4 | // 5 | vec4 simplexNoiseDerivatives (vec4 v) 6 | { 7 | const vec4 C = vec4( 0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958); 8 | 9 | vec4 i = floor(v + dot(v, vec4(F4)) ); 10 | vec4 x0 = v - i + dot(i, C.xxxx); 11 | 12 | vec4 i0; 13 | vec3 isX = step( x0.yzw, x0.xxx ); 14 | vec3 isYZ = step( x0.zww, x0.yyz ); 15 | i0.x = isX.x + isX.y + isX.z; 16 | i0.yzw = 1.0 - isX; 17 | i0.y += isYZ.x + isYZ.y; 18 | i0.zw += 1.0 - isYZ.xy; 19 | i0.z += isYZ.z; 20 | i0.w += 1.0 - isYZ.z; 21 | 22 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 23 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 24 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 25 | 26 | vec4 x1 = x0 - i1 + C.xxxx; 27 | vec4 x2 = x0 - i2 + C.yyyy; 28 | vec4 x3 = x0 - i3 + C.zzzz; 29 | vec4 x4 = x0 + C.wwww; 30 | 31 | i = mod289(i); 32 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 33 | vec4 j1 = permute( permute( permute( permute ( i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 34 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 35 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 36 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 37 | 38 | 39 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 40 | 41 | vec4 p0 = grad4(j0, ip); 42 | vec4 p1 = grad4(j1.x, ip); 43 | vec4 p2 = grad4(j1.y, ip); 44 | vec4 p3 = grad4(j1.z, ip); 45 | vec4 p4 = grad4(j1.w, ip); 46 | 47 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 48 | p0 *= norm.x; 49 | p1 *= norm.y; 50 | p2 *= norm.z; 51 | p3 *= norm.w; 52 | p4 *= taylorInvSqrt(dot(p4,p4)); 53 | 54 | vec3 values0 = vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)); //value of contributions from each corner at point 55 | vec2 values1 = vec2(dot(p3, x3), dot(p4, x4)); 56 | 57 | vec3 m0 = max(0.5 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); //(0.5 - x^2) where x is the distance 58 | vec2 m1 = max(0.5 - vec2(dot(x3,x3), dot(x4,x4)), 0.0); 59 | 60 | vec3 temp0 = -6.0 * m0 * m0 * values0; 61 | vec2 temp1 = -6.0 * m1 * m1 * values1; 62 | 63 | vec3 mmm0 = m0 * m0 * m0; 64 | vec2 mmm1 = m1 * m1 * m1; 65 | 66 | float dx = temp0[0] * x0.x + temp0[1] * x1.x + temp0[2] * x2.x + temp1[0] * x3.x + temp1[1] * x4.x + mmm0[0] * p0.x + mmm0[1] * p1.x + mmm0[2] * p2.x + mmm1[0] * p3.x + mmm1[1] * p4.x; 67 | float dy = temp0[0] * x0.y + temp0[1] * x1.y + temp0[2] * x2.y + temp1[0] * x3.y + temp1[1] * x4.y + mmm0[0] * p0.y + mmm0[1] * p1.y + mmm0[2] * p2.y + mmm1[0] * p3.y + mmm1[1] * p4.y; 68 | float dz = temp0[0] * x0.z + temp0[1] * x1.z + temp0[2] * x2.z + temp1[0] * x3.z + temp1[1] * x4.z + mmm0[0] * p0.z + mmm0[1] * p1.z + mmm0[2] * p2.z + mmm1[0] * p3.z + mmm1[1] * p4.z; 69 | float dw = temp0[0] * x0.w + temp0[1] * x1.w + temp0[2] * x2.w + temp1[0] * x3.w + temp1[1] * x4.w + mmm0[0] * p0.w + mmm0[1] * p1.w + mmm0[2] * p2.w + mmm1[0] * p3.w + mmm1[1] * p4.w; 70 | 71 | return vec4(dx, dy, dz, dw) * 49.0; 72 | } 73 | 74 | 75 | // ------------------------------------------------------------------------------------- 76 | // 77 | vec3 curlNoise( vec3 _p, float _time, int _octaves, float _persistence ) 78 | { 79 | vec4 xNoisePotentialDerivatives = vec4(0.0); 80 | vec4 yNoisePotentialDerivatives = vec4(0.0); 81 | vec4 zNoisePotentialDerivatives = vec4(0.0); 82 | 83 | float tmpPersistence = _persistence; 84 | 85 | for (int i = 0; i < _octaves; ++i) 86 | { 87 | float scale = (1.0 / 2.0) * pow(2.0, float(i)); 88 | 89 | float noiseScale = pow(tmpPersistence, float(i)); 90 | if (tmpPersistence == 0.0 && i == 0) //fix undefined behaviour 91 | { 92 | noiseScale = 1.0; 93 | } 94 | 95 | xNoisePotentialDerivatives += simplexNoiseDerivatives(vec4( _p * pow(2.0, float(i)), _time)) * noiseScale * scale; 96 | yNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(123.4, 129845.6, -1239.1)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 97 | zNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(-9519.0, 9051.0, -123.0)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 98 | } 99 | 100 | //compute curl 101 | vec3 curlVal = vec3( zNoisePotentialDerivatives[1] - yNoisePotentialDerivatives[2], 102 | xNoisePotentialDerivatives[2] - zNoisePotentialDerivatives[0], 103 | yNoisePotentialDerivatives[0] - xNoisePotentialDerivatives[1] ); 104 | 105 | 106 | return curlVal; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example-glslify/bin/data/Common/ofCommon.glslinc: -------------------------------------------------------------------------------- 1 | in vec4 position; 2 | in vec4 color; 3 | in vec3 normal; 4 | in vec2 texcoord; 5 | 6 | uniform mat4 viewMatrix; 7 | uniform mat4 modelViewMatrix; 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 textureMatrix; 10 | uniform mat4 modelViewProjectionMatrix; 11 | uniform vec4 globalColor = vec4(1); 12 | 13 | uniform float usingTexture; 14 | uniform float usingColors; 15 | uniform float bitmapText; 16 | -------------------------------------------------------------------------------- /example-glslify/bin/data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "data", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "glsl-noise": "0.0.0", 13 | "glslify": "^5.0.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example-glslify/bin/data/shader.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | mode: POINTS 3 | count: 8000 4 | 5 | geom_count: 4 6 | geom_mode: TRIANGLE_STRIP 7 | 8 | -- vertex 9 | 10 | #pragma include "Common/Common.glslinc" 11 | 12 | #pragma glslify: snoise4 = require(glsl-noise/simplex/4d) 13 | 14 | uniform float Time = 0; 15 | 16 | #define v4(fn, v) vec3(fn(v), \ 17 | fn(v + vec4(134, 235, 523, 123)), \ 18 | fn(v + vec4(948, 1245, 123, -024))) 19 | 20 | void main() 21 | { 22 | vec3 P = gl_Vertex.xyz; 23 | P += v4(snoise4, vec4(P * 1, Time)) * 0.2; 24 | gl_Position = gl_ModelViewProjectionMatrix * vec4(P, 1); 25 | } 26 | 27 | -- fragment 28 | 29 | void main() 30 | { 31 | gl_FragColor = vec4(1); 32 | } 33 | -------------------------------------------------------------------------------- /example-glslify/config.make: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CONFIGURE PROJECT MAKEFILE (optional) 3 | # This file is where we make project specific configurations. 4 | ################################################################################ 5 | 6 | ################################################################################ 7 | # OF ROOT 8 | # The location of your root openFrameworks installation 9 | # (default) OF_ROOT = ../../.. 10 | ################################################################################ 11 | # OF_ROOT = ../../.. 12 | 13 | ################################################################################ 14 | # PROJECT ROOT 15 | # The location of the project - a starting place for searching for files 16 | # (default) PROJECT_ROOT = . (this directory) 17 | # 18 | ################################################################################ 19 | # PROJECT_ROOT = . 20 | 21 | ################################################################################ 22 | # PROJECT SPECIFIC CHECKS 23 | # This is a project defined section to create internal makefile flags to 24 | # conditionally enable or disable the addition of various features within 25 | # this makefile. For instance, if you want to make changes based on whether 26 | # GTK is installed, one might test that here and create a variable to check. 27 | ################################################################################ 28 | # None 29 | 30 | ################################################################################ 31 | # PROJECT EXTERNAL SOURCE PATHS 32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder. 33 | # Like source folders in the PROJECT_ROOT, these paths are subject to 34 | # exlclusion via the PROJECT_EXLCUSIONS list. 35 | # 36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) 37 | # 38 | # Note: Leave a leading space when adding list items with the += operator 39 | ################################################################################ 40 | # PROJECT_EXTERNAL_SOURCE_PATHS = 41 | 42 | ################################################################################ 43 | # PROJECT EXCLUSIONS 44 | # These makefiles assume that all folders in your current project directory 45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations 46 | # to look for source code. The any folders or files that match any of the 47 | # items in the PROJECT_EXCLUSIONS list below will be ignored. 48 | # 49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete 50 | # string unless teh user adds a wildcard (%) operator to match subdirectories. 51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is 52 | # treated literally. 53 | # 54 | # (default) PROJECT_EXCLUSIONS = (blank) 55 | # 56 | # Will automatically exclude the following: 57 | # 58 | # $(PROJECT_ROOT)/bin% 59 | # $(PROJECT_ROOT)/obj% 60 | # $(PROJECT_ROOT)/%.xcodeproj 61 | # 62 | # Note: Leave a leading space when adding list items with the += operator 63 | ################################################################################ 64 | # PROJECT_EXCLUSIONS = 65 | 66 | ################################################################################ 67 | # PROJECT LINKER FLAGS 68 | # These flags will be sent to the linker when compiling the executable. 69 | # 70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs 71 | # 72 | # Note: Leave a leading space when adding list items with the += operator 73 | ################################################################################ 74 | 75 | # Currently, shared libraries that are needed are copied to the 76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to 77 | # add a runtime path to search for those shared libraries, since they aren't 78 | # incorporated directly into the final executable application binary. 79 | # TODO: should this be a default setting? 80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs 81 | 82 | ################################################################################ 83 | # PROJECT DEFINES 84 | # Create a space-delimited list of DEFINES. The list will be converted into 85 | # CFLAGS with the "-D" flag later in the makefile. 86 | # 87 | # (default) PROJECT_DEFINES = (blank) 88 | # 89 | # Note: Leave a leading space when adding list items with the += operator 90 | ################################################################################ 91 | # PROJECT_DEFINES = 92 | 93 | ################################################################################ 94 | # PROJECT CFLAGS 95 | # This is a list of fully qualified CFLAGS required when compiling for this 96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS 97 | # defined in your platform specific core configuration files. These flags are 98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. 99 | # 100 | # (default) PROJECT_CFLAGS = (blank) 101 | # 102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in 103 | # your platform specific configuration file will be applied by default and 104 | # further flags here may not be needed. 105 | # 106 | # Note: Leave a leading space when adding list items with the += operator 107 | ################################################################################ 108 | # PROJECT_CFLAGS = 109 | 110 | ################################################################################ 111 | # PROJECT OPTIMIZATION CFLAGS 112 | # These are lists of CFLAGS that are target-specific. While any flags could 113 | # be conditionally added, they are usually limited to optimization flags. 114 | # These flags are added BEFORE the PROJECT_CFLAGS. 115 | # 116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. 117 | # 118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) 119 | # 120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. 121 | # 122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) 123 | # 124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the 125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration 126 | # file will be applied by default and further optimization flags here may not 127 | # be needed. 128 | # 129 | # Note: Leave a leading space when adding list items with the += operator 130 | ################################################################################ 131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE = 132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG = 133 | 134 | ################################################################################ 135 | # PROJECT COMPILERS 136 | # Custom compilers can be set for CC and CXX 137 | # (default) PROJECT_CXX = (blank) 138 | # (default) PROJECT_CC = (blank) 139 | # Note: Leave a leading space when adding list items with the += operator 140 | ################################################################################ 141 | # PROJECT_CXX = 142 | # PROJECT_CC = 143 | -------------------------------------------------------------------------------- /example-glslify/example.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 14 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 17 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 18 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 23 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 25 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 26 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 28 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 29 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 30 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /example-glslify/example.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A} 23 | Win32Proj 24 | example 25 | 26 | 27 | 28 | Application 29 | Unicode 30 | v140 31 | 32 | 33 | Application 34 | Unicode 35 | v140 36 | 37 | 38 | Application 39 | Unicode 40 | true 41 | v140 42 | 43 | 44 | Application 45 | Unicode 46 | true 47 | v140 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | bin\ 69 | obj\$(Configuration)\ 70 | $(ProjectName)_debug 71 | true 72 | true 73 | 74 | 75 | bin\ 76 | obj\$(Configuration)\ 77 | $(ProjectName)_debug 78 | true 79 | true 80 | 81 | 82 | bin\ 83 | obj\$(Configuration)\ 84 | false 85 | 86 | 87 | bin\ 88 | obj\$(Configuration)\ 89 | false 90 | 91 | 92 | 93 | Disabled 94 | EnableFastChecks 95 | %(PreprocessorDefinitions) 96 | MultiThreadedDebugDLL 97 | Level3 98 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 99 | CompileAsCpp 100 | 101 | 102 | true 103 | Console 104 | false 105 | %(AdditionalDependencies) 106 | %(AdditionalLibraryDirectories) 107 | 108 | 109 | 110 | 111 | 112 | Disabled 113 | EnableFastChecks 114 | %(PreprocessorDefinitions) 115 | MultiThreadedDebugDLL 116 | Level3 117 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 118 | CompileAsCpp 119 | true 120 | 121 | 122 | true 123 | Console 124 | false 125 | %(AdditionalDependencies) 126 | %(AdditionalLibraryDirectories) 127 | 128 | 129 | 130 | 131 | 132 | false 133 | %(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | Level3 136 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 137 | CompileAsCpp 138 | true 139 | 140 | 141 | false 142 | false 143 | Console 144 | true 145 | true 146 | false 147 | %(AdditionalDependencies) 148 | %(AdditionalLibraryDirectories) 149 | 150 | 151 | 152 | 153 | 154 | false 155 | %(PreprocessorDefinitions) 156 | MultiThreadedDLL 157 | Level3 158 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 159 | CompileAsCpp 160 | 161 | 162 | false 163 | false 164 | Console 165 | true 166 | true 167 | false 168 | %(AdditionalDependencies) 169 | %(AdditionalLibraryDirectories) 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | {5837595d-aca9-485c-8e76-729040ce4b0b} 182 | 183 | 184 | 185 | 186 | /D_DEBUG %(AdditionalOptions) 187 | /D_DEBUG %(AdditionalOptions) 188 | $(OF_ROOT)\libs\openFrameworksCompiled\project\vs 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /example-glslify/example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | src 6 | 7 | 8 | src 9 | 10 | 11 | 12 | 13 | {d8376475-7454-4a24-b08a-aac121d3ad6f} 14 | 15 | 16 | {71834F65-F3A9-211E-73B8-DC85} 17 | 18 | 19 | {CD60902F-C905-86E8-6E9D-BB17} 20 | 21 | 22 | {20F1F5CE-83F5-6111-D1EE-C15F} 23 | 24 | 25 | 26 | 27 | addons\ofxShaderRunner\src 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /example-glslify/icon.rc: -------------------------------------------------------------------------------- 1 | // Icon Resource Definition 2 | #define MAIN_ICON 102 3 | 4 | #if defined(_DEBUG) 5 | MAIN_ICON ICON "icon_debug.ico" 6 | #else 7 | MAIN_ICON ICON "icon.ico" 8 | #endif 9 | -------------------------------------------------------------------------------- /example-glslify/openFrameworks-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | cc.openFrameworks.ofapp 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | CFBundleIconFile 20 | ${ICON} 21 | 22 | 23 | -------------------------------------------------------------------------------- /example-glslify/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | 3 | #include "ofxShaderRunner.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class ofApp : public ofBaseApp 12 | { 13 | public: 14 | 15 | ofEasyCam cam; 16 | 17 | ofxShaderRunner S; 18 | 19 | void setup() 20 | { 21 | ofSetFrameRate(60); 22 | ofSetVerticalSync(true); 23 | ofBackground(0); 24 | 25 | S.load("shader.glsl"); 26 | } 27 | 28 | void update() 29 | { 30 | ofSetWindowTitle(ofToString(ofGetFrameRate())); 31 | } 32 | 33 | void draw() 34 | { 35 | ofEnableDepthTest(); 36 | glPointSize(4); 37 | 38 | cam.begin(); 39 | { 40 | S.begin(); 41 | 42 | ofNoFill(); 43 | ofDrawSphere(100); 44 | 45 | S.end(); 46 | } 47 | cam.end(); 48 | } 49 | 50 | void keyPressed(int key) 51 | { 52 | } 53 | 54 | void keyReleased(int key) 55 | { 56 | } 57 | 58 | void mouseMoved(int x, int y) 59 | { 60 | } 61 | 62 | void mouseDragged(int x, int y, int button) 63 | { 64 | } 65 | 66 | void mousePressed(int x, int y, int button) 67 | { 68 | } 69 | 70 | void mouseReleased(int x, int y, int button) 71 | { 72 | } 73 | 74 | void windowResized(int w, int h) 75 | { 76 | } 77 | }; 78 | 79 | 80 | int main(int argc, const char** argv) 81 | { 82 | ofSetupOpenGL(640, 480, OF_WINDOW); 83 | ofRunApp(new ofApp); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | .svn 2 | .hg 3 | .cvs 4 | 5 | # osx 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | Icon 10 | *.app 11 | ._* 12 | DerivedData 13 | 14 | # xcode3 15 | *.mode1v3 16 | *.pbxuser 17 | build/ 18 | 19 | # xcode4 20 | *.xcodeproj/* 21 | !*.xcodeproj/project.pbxproj 22 | !*.xcodeproj/default.* 23 | **/*.xcodeproj/* 24 | !**/*.xcodeproj/project.pbxproj 25 | !**/*.xcodeproj/default.* 26 | *.xcworkspace/* 27 | !*.xcworkspace/contents.xcworkspacedata 28 | 29 | # windows 30 | *.exe 31 | Thumbs.db 32 | ehthumbs.db 33 | 34 | # vs 35 | ipch/ 36 | [Bb]in/ 37 | [Oo]bj/ 38 | *.aps 39 | *.ncb 40 | *.opensdf 41 | *.sdf 42 | *.cachefile 43 | *.suo 44 | *.user 45 | *.sln.docstates 46 | *.opendb 47 | 48 | # Object files 49 | *.o 50 | 51 | # Libraries 52 | *.lib 53 | *.a 54 | 55 | # Shared objects (inc. Windows DLLs) 56 | *.dll 57 | *.so 58 | *.so.* 59 | *.dylib 60 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | # Attempt to load a config.make file. 2 | # If none is found, project defaults in config.project.make will be used. 3 | ifneq ($(wildcard config.make),) 4 | include config.make 5 | endif 6 | 7 | # make sure the the OF_ROOT location is defined 8 | ifndef OF_ROOT 9 | OF_ROOT=$(realpath ../../..) 10 | endif 11 | 12 | # call the project makefile! 13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk 14 | -------------------------------------------------------------------------------- /example/Project.xcconfig: -------------------------------------------------------------------------------- 1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. 2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED 3 | OF_PATH = ../../.. 4 | 5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE 6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" 7 | 8 | //ICONS - NEW IN 0072 9 | ICON_NAME_DEBUG = icon-debug.icns 10 | ICON_NAME_RELEASE = icon.icns 11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ 12 | 13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: 14 | //ICON_FILE_PATH = bin/data/ 15 | 16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS) 17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) 18 | -------------------------------------------------------------------------------- /example/addons.make: -------------------------------------------------------------------------------- 1 | ofxShaderRunner 2 | -------------------------------------------------------------------------------- /example/bin/data/Common/Common.glslinc: -------------------------------------------------------------------------------- 1 | vec2 grid(int x, int y) 2 | { 3 | return vec2(mod(gl_VertexID, x) / x, float(gl_VertexID / x) / y); 4 | } 5 | 6 | vec3 grid(int x, int y, int z) 7 | { 8 | int vid = gl_VertexID; 9 | vec3 id; 10 | float T = gl_VertexID / (x * y); 11 | float TT = mod(gl_VertexID, x * y); 12 | id.z = T / (z - 1); 13 | id.y = floor(TT / y) / (y - 1); 14 | id.x = (mod(TT, y)) / (x - 1); 15 | return id; 16 | } 17 | -------------------------------------------------------------------------------- /example/bin/data/Common/Noise2D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D simplex noise function. 3 | // Author : Ian McEwan, Ashima Arts. 4 | // Maintainer : ijm 5 | // Lastmod : 20110822 (ijm) 6 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 7 | // Distributed under the MIT License. See LICENSE file. 8 | // https://github.com/ashima/webgl-noise 9 | // 10 | 11 | // ------------------------------------------------------------------------------------- 12 | // 13 | float snoise(vec2 v) 14 | { 15 | const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 16 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 17 | -0.577350269189626, // -1.0 + 2.0 * C.x 18 | 0.024390243902439); // 1.0 / 41.0 19 | // First corner 20 | vec2 i = floor(v + dot(v, C.yy) ); 21 | vec2 x0 = v - i + dot(i, C.xx); 22 | 23 | // Other corners 24 | vec2 i1; 25 | //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 26 | //i1.y = 1.0 - i1.x; 27 | i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); 28 | // x0 = x0 - 0.0 + 0.0 * C.xx ; 29 | // x1 = x0 - i1 + 1.0 * C.xx ; 30 | // x2 = x0 - 1.0 + 2.0 * C.xx ; 31 | vec4 x12 = x0.xyxy + C.xxzz; 32 | x12.xy -= i1; 33 | 34 | // Permutations 35 | i = mod289(i); // Avoid truncation effects in permutation 36 | vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) 37 | + i.x + vec3(0.0, i1.x, 1.0 )); 38 | 39 | vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); 40 | m = m*m ; 41 | m = m*m ; 42 | 43 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 44 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 45 | 46 | vec3 x = 2.0 * fract(p * C.www) - 1.0; 47 | vec3 h = abs(x) - 0.5; 48 | vec3 ox = floor(x + 0.5); 49 | vec3 a0 = x - ox; 50 | 51 | // Normalise gradients implicitly by scaling m 52 | // Approximation of: m *= inversesqrt( a0*a0 + h*h ); 53 | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); 54 | 55 | // Compute final noise value at P 56 | vec3 g; 57 | g.x = a0.x * x0.x + h.x * x0.y; 58 | g.yz = a0.yz * x12.xz + h.yz * x12.yw; 59 | return 130.0 * dot(m, g); 60 | } 61 | 62 | // ------------------------------------------------------------------------------------- 63 | // 64 | float snoiseu(vec2 v) 65 | { 66 | return (snoise( v ) + 1.0) * 0.5; 67 | } 68 | 69 | // ------------------------------------------------------------------------------------- 70 | // 71 | float fbm_5oct( vec2 p ) 72 | { 73 | float f = 0.0; 74 | f += 0.50000*snoise( p ); p = p*2.02; 75 | f += 0.25000*snoise( p ); p = p*2.03; 76 | f += 0.12500*snoise( p ); p = p*2.01; 77 | f += 0.06250*snoise( p ); p = p*2.04; 78 | f += 0.03125*snoise( p ); 79 | return f/0.984375; 80 | } 81 | 82 | // ------------------------------------------------------------------------------------- 83 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 84 | // 85 | float fbm(vec2 P, int octaves, float lacunarity, float gain) 86 | { 87 | float sum = 0.0; 88 | float amp = 1.0; 89 | vec2 pp = P; 90 | 91 | for( int i = 0; i < octaves; i+=1) 92 | { 93 | amp *= gain; 94 | sum += amp * snoise(pp); 95 | pp *= lacunarity; 96 | } 97 | 98 | return sum; 99 | } 100 | 101 | // ------------------------------------------------------------------------------------- 102 | // Returns the FBM in the range 0..1 103 | // 104 | float fbmu(vec2 _p, int _octaves, float _lacunarity, float _persistence ) 105 | { 106 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example/bin/data/Common/Noise3D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // ------------------------------------------------------------------------------------- 13 | // 14 | float snoise(vec3 v) 15 | { 16 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 17 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 18 | 19 | // First corner 20 | vec3 i = floor(v + dot(v, C.yyy) ); 21 | vec3 x0 = v - i + dot(i, C.xxx) ; 22 | 23 | // Other corners 24 | vec3 g = step(x0.yzx, x0.xyz); 25 | vec3 l = 1.0 - g; 26 | vec3 i1 = min( g.xyz, l.zxy ); 27 | vec3 i2 = max( g.xyz, l.zxy ); 28 | 29 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 30 | // x1 = x0 - i1 + 1.0 * C.xxx; 31 | // x2 = x0 - i2 + 2.0 * C.xxx; 32 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 33 | vec3 x1 = x0 - i1 + C.xxx; 34 | vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 35 | vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 36 | 37 | // Permutations 38 | i = mod289(i); 39 | vec4 p = permute( permute( permute( 40 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 41 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 42 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 43 | 44 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 45 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 46 | float n_ = 0.142857142857; // 1.0/7.0 47 | vec3 ns = n_ * D.wyz - D.xzx; 48 | 49 | vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 50 | 51 | vec4 x_ = floor(j * ns.z); 52 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 53 | 54 | vec4 x = x_ *ns.x + ns.yyyy; 55 | vec4 y = y_ *ns.x + ns.yyyy; 56 | vec4 h = 1.0 - abs(x) - abs(y); 57 | 58 | vec4 b0 = vec4( x.xy, y.xy ); 59 | vec4 b1 = vec4( x.zw, y.zw ); 60 | 61 | //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; 62 | //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; 63 | vec4 s0 = floor(b0)*2.0 + 1.0; 64 | vec4 s1 = floor(b1)*2.0 + 1.0; 65 | vec4 sh = -step(h, vec4(0.0)); 66 | 67 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 68 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 69 | 70 | vec3 p0 = vec3(a0.xy,h.x); 71 | vec3 p1 = vec3(a0.zw,h.y); 72 | vec3 p2 = vec3(a1.xy,h.z); 73 | vec3 p3 = vec3(a1.zw,h.w); 74 | 75 | //Normalise gradients 76 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 77 | p0 *= norm.x; 78 | p1 *= norm.y; 79 | p2 *= norm.z; 80 | p3 *= norm.w; 81 | 82 | // Mix final noise value 83 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 84 | m = m * m; 85 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 86 | dot(p2,x2), dot(p3,x3) ) ); 87 | } 88 | 89 | // ------------------------------------------------------------------------------------- 90 | // 91 | float fbm_2oct(vec3 p) 92 | { 93 | float final = snoise(p); 94 | p *= 1.94; 95 | final += snoise(p) * 0.5; 96 | return final / 1.5; 97 | } 98 | 99 | // ------------------------------------------------------------------------------------- 100 | // 101 | float fbm_3oct(vec3 p) 102 | { 103 | float final = snoise(p); 104 | p *= 1.94; 105 | final += snoise(p) * 0.5; 106 | p *= 3.75; 107 | final += snoise(p) * 0.25; 108 | return final / 1.75; 109 | 110 | } 111 | 112 | // ------------------------------------------------------------------------------------- 113 | // 114 | float fbm_5oct( vec3 p ) 115 | { 116 | float f = 0.0; 117 | f += 0.50000*snoise( p ); p = p*2.02; 118 | f += 0.25000*snoise( p ); p = p*2.03; 119 | f += 0.12500*snoise( p ); p = p*2.01; 120 | f += 0.06250*snoise( p ); p = p*2.04; 121 | f += 0.03125*snoise( p ); 122 | return f/0.984375; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 127 | // 128 | float fbm(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 129 | { 130 | float sum = 0.0; 131 | float amp = 1.0; 132 | vec3 pp = _p; 133 | float totalAmp = 0.0; 134 | 135 | for( int i = 0; i < _octaves; i++) 136 | { 137 | amp *= _persistence; 138 | totalAmp += amp; 139 | sum += amp * snoise(pp); 140 | pp *= _lacunarity; 141 | } 142 | 143 | return sum / totalAmp; 144 | } 145 | 146 | // ------------------------------------------------------------------------------------- 147 | // Returns the FBM in the range 0..1 148 | // 149 | float fbmu(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 150 | { 151 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 152 | } 153 | -------------------------------------------------------------------------------- /example/bin/data/Common/Noise4D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // (sqrt(5) - 1)/4 = F4, used once below 13 | #define F4 0.309016994374947451 14 | 15 | // ------------------------------------------------------------------------------------- 16 | // 17 | float snoise(vec4 v) 18 | { 19 | const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4 20 | 0.276393202250021, // 2 * G4 21 | 0.414589803375032, // 3 * G4 22 | -0.447213595499958); // -1 + 4 * G4 23 | 24 | // First corner 25 | vec4 i = floor(v + dot(v, vec4(F4)) ); 26 | vec4 x0 = v - i + dot(i, C.xxxx); 27 | 28 | // Other corners 29 | 30 | // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) 31 | vec4 i0; 32 | vec3 isX = step( x0.yzw, x0.xxx ); 33 | vec3 isYZ = step( x0.zww, x0.yyz ); 34 | // i0.x = dot( isX, vec3( 1.0 ) ); 35 | i0.x = isX.x + isX.y + isX.z; 36 | i0.yzw = 1.0 - isX; 37 | // i0.y += dot( isYZ.xy, vec2( 1.0 ) ); 38 | i0.y += isYZ.x + isYZ.y; 39 | i0.zw += 1.0 - isYZ.xy; 40 | i0.z += isYZ.z; 41 | i0.w += 1.0 - isYZ.z; 42 | 43 | // i0 now contains the unique values 0,1,2,3 in each channel 44 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 45 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 46 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 47 | 48 | // x0 = x0 - 0.0 + 0.0 * C.xxxx 49 | // x1 = x0 - i1 + 1.0 * C.xxxx 50 | // x2 = x0 - i2 + 2.0 * C.xxxx 51 | // x3 = x0 - i3 + 3.0 * C.xxxx 52 | // x4 = x0 - 1.0 + 4.0 * C.xxxx 53 | vec4 x1 = x0 - i1 + C.xxxx; 54 | vec4 x2 = x0 - i2 + C.yyyy; 55 | vec4 x3 = x0 - i3 + C.zzzz; 56 | vec4 x4 = x0 + C.wwww; 57 | 58 | // Permutations 59 | i = mod289(i); 60 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 61 | vec4 j1 = permute( permute( permute( permute ( 62 | i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 63 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 64 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 65 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 66 | 67 | // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope 68 | // 7*7*6 = 294, which is close to the ring size 17*17 = 289. 69 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 70 | 71 | vec4 p0 = grad4(j0, ip); 72 | vec4 p1 = grad4(j1.x, ip); 73 | vec4 p2 = grad4(j1.y, ip); 74 | vec4 p3 = grad4(j1.z, ip); 75 | vec4 p4 = grad4(j1.w, ip); 76 | 77 | // Normalise gradients 78 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 79 | p0 *= norm.x; 80 | p1 *= norm.y; 81 | p2 *= norm.z; 82 | p3 *= norm.w; 83 | p4 *= taylorInvSqrt(dot(p4,p4)); 84 | 85 | // Mix contributions from the five corners 86 | vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); 87 | vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); 88 | m0 = m0 * m0; 89 | m1 = m1 * m1; 90 | return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) 91 | + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; 92 | 93 | } 94 | 95 | 96 | // ------------------------------------------------------------------------------------- 97 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 98 | // 99 | float fbm(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 100 | { 101 | float sum = 0.0; 102 | float amp = 1.0; 103 | vec4 pp = _p; 104 | float totalAmp = 0.0; 105 | 106 | for( int i = 0; i < _octaves; i++) 107 | { 108 | amp *= _persistence; 109 | totalAmp += amp; 110 | sum += amp * snoise(pp); 111 | pp *= _lacunarity; 112 | } 113 | 114 | return sum / totalAmp; 115 | } 116 | 117 | // ------------------------------------------------------------------------------------- 118 | // Returns the FBM in the range 0..1 119 | // 120 | float fbmu(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 121 | { 122 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // 127 | vec3 fbmvec3(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 128 | { 129 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 130 | tmp.x = fbm( vec4( _p.x, _p.y, _p.z, _p.w ), _octaves, _lacunarity, _persistence ); 131 | tmp.y = fbm( vec4( _p.y + 3.422, _p.x + 21.13, _p.w + 312.2, _p.z + 132.32 ), _octaves, _lacunarity, _persistence ); 132 | tmp.z = fbm( vec4( _p.w + 1.234, _p.z + 87.31, _p.y + 2367.1, _p.x + 894.21 ), _octaves, _lacunarity, _persistence ); 133 | return tmp; 134 | } 135 | 136 | // ------------------------------------------------------------------------------------- 137 | vec3 snoisevec3( vec4 _p ) 138 | { 139 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 140 | tmp.x = snoise( vec4( _p.x, _p.y, _p.z, _p.w ) ); 141 | tmp.y = snoise( vec4( _p.y, _p.x, _p.w, _p.z ) ); 142 | tmp.z = snoise( vec4( _p.w, _p.z, _p.y, _p.x ) ); 143 | return tmp; 144 | } -------------------------------------------------------------------------------- /example/bin/data/Common/PhotoshopBlendModes.glslinc: -------------------------------------------------------------------------------- 1 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 2 | // 3 | // 25 of the layer blending modes from Photoshop. 4 | // 5 | // The ones I couldn't figure out are from Nvidia's advanced blend equations extension spec - 6 | // http://www.opengl.org/registry/specs/NV/blend_equation_advanced.txt 7 | // 8 | // ~bj.2013 9 | // 10 | 11 | vec3 darken( vec3 s, vec3 d ) 12 | { 13 | return min(s,d); 14 | } 15 | 16 | vec3 multiply( vec3 s, vec3 d ) 17 | { 18 | return s*d; 19 | } 20 | 21 | vec3 colorBurn( vec3 s, vec3 d ) 22 | { 23 | return 1.0 - (1.0 - d) / s; 24 | } 25 | 26 | vec3 linearBurn( vec3 s, vec3 d ) 27 | { 28 | return s + d - 1.0; 29 | } 30 | 31 | vec3 darkerColor( vec3 s, vec3 d ) 32 | { 33 | return (s.x + s.y + s.z < d.x + d.y + d.z) ? s : d; 34 | } 35 | 36 | vec3 lighten( vec3 s, vec3 d ) 37 | { 38 | return max(s,d); 39 | } 40 | 41 | vec3 screen( vec3 s, vec3 d ) 42 | { 43 | return s + d - s * d; 44 | } 45 | 46 | vec3 colorDodge( vec3 s, vec3 d ) 47 | { 48 | return d / (1.0 - s); 49 | } 50 | 51 | vec3 linearDodge( vec3 s, vec3 d ) 52 | { 53 | return s + d; 54 | } 55 | 56 | vec3 lighterColor( vec3 s, vec3 d ) 57 | { 58 | return (s.x + s.y + s.z > d.x + d.y + d.z) ? s : d; 59 | } 60 | 61 | float overlay( float s, float d ) 62 | { 63 | return (d < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 64 | } 65 | 66 | vec3 overlay( vec3 s, vec3 d ) 67 | { 68 | vec3 c; 69 | c.x = overlay(s.x,d.x); 70 | c.y = overlay(s.y,d.y); 71 | c.z = overlay(s.z,d.z); 72 | return c; 73 | } 74 | 75 | float softLight( float s, float d ) 76 | { 77 | return (s < 0.5) ? d - (1.0 - 2.0 * s) * d * (1.0 - d) 78 | : (d < 0.25) ? d + (2.0 * s - 1.0) * d * ((16.0 * d - 12.0) * d + 3.0) 79 | : d + (2.0 * s - 1.0) * (sqrt(d) - d); 80 | } 81 | 82 | vec3 softLight( vec3 s, vec3 d ) 83 | { 84 | vec3 c; 85 | c.x = softLight(s.x,d.x); 86 | c.y = softLight(s.y,d.y); 87 | c.z = softLight(s.z,d.z); 88 | return c; 89 | } 90 | 91 | float hardLight( float s, float d ) 92 | { 93 | return (s < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 94 | } 95 | 96 | vec3 hardLight( vec3 s, vec3 d ) 97 | { 98 | vec3 c; 99 | c.x = hardLight(s.x,d.x); 100 | c.y = hardLight(s.y,d.y); 101 | c.z = hardLight(s.z,d.z); 102 | return c; 103 | } 104 | 105 | float vividLight( float s, float d ) 106 | { 107 | return (s < 0.5) ? 1.0 - (1.0 - d) / (2.0 * s) : d / (2.0 * (1.0 - s)); 108 | } 109 | 110 | vec3 vividLight( vec3 s, vec3 d ) 111 | { 112 | vec3 c; 113 | c.x = vividLight(s.x,d.x); 114 | c.y = vividLight(s.y,d.y); 115 | c.z = vividLight(s.z,d.z); 116 | return c; 117 | } 118 | 119 | vec3 linearLight( vec3 s, vec3 d ) 120 | { 121 | return 2.0 * s + d - 1.0; 122 | } 123 | 124 | float pinLight( float s, float d ) 125 | { 126 | return (2.0 * s - 1.0 > d) ? 2.0 * s - 1.0 : (s < 0.5 * d) ? 2.0 * s : d; 127 | } 128 | 129 | vec3 pinLight( vec3 s, vec3 d ) 130 | { 131 | vec3 c; 132 | c.x = pinLight(s.x,d.x); 133 | c.y = pinLight(s.y,d.y); 134 | c.z = pinLight(s.z,d.z); 135 | return c; 136 | } 137 | 138 | vec3 hardMix( vec3 s, vec3 d ) 139 | { 140 | return floor(s + d); 141 | } 142 | 143 | vec3 difference( vec3 s, vec3 d ) 144 | { 145 | return abs(d - s); 146 | } 147 | 148 | vec3 exclusion( vec3 s, vec3 d ) 149 | { 150 | return s + d - 2.0 * s * d; 151 | } 152 | 153 | vec3 subtract( vec3 s, vec3 d ) 154 | { 155 | return s - d; 156 | } 157 | 158 | vec3 divide( vec3 s, vec3 d ) 159 | { 160 | return s / d; 161 | } 162 | 163 | // rgb<-->hsv functions by Sam Hocevar 164 | // http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl 165 | vec3 rgb2hsv(vec3 c) 166 | { 167 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 168 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 169 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 170 | 171 | float d = q.x - min(q.w, q.y); 172 | float e = 1.0e-10; 173 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 174 | } 175 | 176 | vec3 hsv2rgb(vec3 c) 177 | { 178 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 179 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 180 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 181 | } 182 | 183 | vec3 hue( vec3 s, vec3 d ) 184 | { 185 | d = rgb2hsv(d); 186 | d.x = rgb2hsv(s).x; 187 | return hsv2rgb(d); 188 | } 189 | 190 | vec3 color( vec3 s, vec3 d ) 191 | { 192 | s = rgb2hsv(s); 193 | s.z = rgb2hsv(d).z; 194 | return hsv2rgb(s); 195 | } 196 | 197 | vec3 saturation( vec3 s, vec3 d ) 198 | { 199 | d = rgb2hsv(d); 200 | d.y = rgb2hsv(s).y; 201 | return hsv2rgb(d); 202 | } 203 | 204 | vec3 luminosity( vec3 s, vec3 d ) 205 | { 206 | float dLum = dot(d, vec3(0.3, 0.59, 0.11)); 207 | float sLum = dot(s, vec3(0.3, 0.59, 0.11)); 208 | float lum = sLum - dLum; 209 | vec3 c = d + lum; 210 | float minC = min(min(c.x, c.y), c.z); 211 | float maxC = max(max(c.x, c.y), c.z); 212 | if(minC < 0.0) return sLum + ((c - sLum) * sLum) / (sLum - minC); 213 | else if(maxC > 1.0) return sLum + ((c - sLum) * (1.0 - sLum)) / (maxC - sLum); 214 | else return c; 215 | } 216 | -------------------------------------------------------------------------------- /example/bin/data/Common/ShaderHelpers.glslinc: -------------------------------------------------------------------------------- 1 | #define HALF_PI 1.57079632679489661923 2 | #define PI 3.14159265358979323846 3 | #define TWO_PI 6.28318530717958647693 4 | 5 | float map( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 6 | float mapClamped( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return clamp( ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin), outputMin, outputMax ); } 7 | 8 | vec3 map( vec3 value, vec3 inputMin, vec3 inputMax, vec3 outputMin, vec3 outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 9 | 10 | float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } 11 | float stepInOut( float _edge1, float _edge2, float _val ) { return step(_edge1, _val) - step(_edge2,_val); } 12 | float smoothStepInOut( float _low0, float _high0, float _high1, float _low1, float _t ) { return smoothstep( _low0, _high0, _t ) * (1.0 - smoothstep( _high1, _low1, _t )); } 13 | 14 | float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 15 | vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 16 | vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 17 | vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 18 | 19 | float permute(float x) { return mod289(((x*34.0)+1.0)*x); } 20 | vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); } 21 | vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); } 22 | 23 | float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; } 24 | vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; } 25 | 26 | 27 | // ------------------------------------------------------------ 28 | mat4 makeLookAt(vec3 eye, vec3 center, vec3 up) 29 | { 30 | mat4 M; 31 | 32 | vec3 zaxis = normalize(eye - center); 33 | vec3 xaxis = normalize( cross(up, zaxis) ); 34 | vec3 yaxis = cross(zaxis,xaxis); 35 | 36 | M[0] = vec4(xaxis,0); 37 | M[1] = vec4(yaxis,0); 38 | M[2] = vec4(zaxis,0); 39 | M[3] = vec4(eye,1); 40 | 41 | return M; 42 | } 43 | 44 | // ------------------------------------------------------------ 45 | mat4 rotationMatrix(vec3 axis, float angle) 46 | { 47 | axis = normalize(axis); 48 | float s = sin(angle); 49 | float c = cos(angle); 50 | float oc = 1.0 - c; 51 | 52 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 53 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 54 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 55 | 0.0, 0.0, 0.0, 1.0); 56 | } 57 | 58 | 59 | // -------------------------------------- 60 | vec3 randomPointOnSphere( vec3 _random ) 61 | { 62 | float lambda = _random.x; 63 | float u = map( _random.y, 0.0, 1.0, -1.0, 1.0 ); 64 | float phi = _random.z * (2.0 * PI ); 65 | 66 | vec3 p; 67 | p.x = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * cos(phi); 68 | p.y = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * sin(phi); 69 | p.z = pow(lambda, 1.0/3.0) * u; 70 | 71 | return p; 72 | } 73 | 74 | // -------------------------------------- 75 | vec3 opTwistX( vec3 _p, float _angPerUnit ) 76 | { 77 | float c = cos( _angPerUnit * _p.x); 78 | float s = sin( _angPerUnit * _p.x); 79 | mat2 m = mat2(c,-s,s,c); 80 | return vec3( _p.x, m * _p.yz ); 81 | } 82 | 83 | // -------------------------------------- 84 | vec3 opTwistY( vec3 _p, float _angPerUnit ) 85 | { 86 | float c = cos( _angPerUnit * _p.y); 87 | float s = sin( _angPerUnit * _p.y); 88 | mat2 m = mat2(c,-s,s,c); 89 | 90 | vec2 rotXZ = m * _p.xz; 91 | 92 | return vec3( rotXZ.x, _p.y, rotXZ.y ); 93 | } 94 | 95 | // -------------------------------------- 96 | vec3 opTwistZ( vec3 _p, float _angPerUnit ) 97 | { 98 | float c = cos( _angPerUnit * _p.z); 99 | float s = sin( _angPerUnit * _p.z); 100 | mat2 m = mat2(c,-s,s,c); 101 | 102 | vec2 rotXY = m * _p.xy; 103 | 104 | return vec3( rotXY.x, rotXY.y, _p.z ); 105 | } 106 | 107 | // -------------------------------------- 108 | float CatmullRom( float u, float x0, float x1, float x2, float x3 ) 109 | { 110 | float u2 = u * u; 111 | float u3 = u2 * u; 112 | return ((2 * x1) + 113 | (-x0 + x2) * u + 114 | (2*x0 - 5*x1 + 4*x2 - x3) * u2 + 115 | (-x0 + 3*x1 - 3*x2 + x3) * u3) * 0.5; 116 | } 117 | 118 | // http://www.iquilezles.org/www/articles/functions/functions.htm 119 | 120 | // -------------------------------------- 121 | float cubicPulse( float c, float w, float x ) 122 | { 123 | x = abs(x - c); 124 | if( x>w ) return 0.0; 125 | x /= w; 126 | return 1.0 - x*x*(3.0-2.0*x); 127 | } 128 | 129 | // -------------------------------------- 130 | float expStep( float x, float k, float n ) 131 | { 132 | return exp( -k*pow(x,n) ); 133 | } 134 | 135 | // -------------------------------------- 136 | float parabola( float x, float k ) 137 | { 138 | return pow( 4.0*x*(1.0-x), k ); 139 | } 140 | 141 | // -------------------------------------- 142 | float pcurve( float x, float a, float b ) 143 | { 144 | float k = pow(a+b,a+b) / (pow(a,a)*pow(b,b)); 145 | return k * pow( x, a ) * pow( 1.0-x, b ); 146 | } 147 | 148 | // -------------------------------------- 149 | float impulse( float k, float x ) 150 | { 151 | float h = k*x; 152 | return h*exp(1.0-h); 153 | } 154 | 155 | 156 | /* 157 | // ----------------------------- 158 | // Coefficients for Matrix M 159 | // 160 | 161 | #define CM_SPLINE_M11 0.0 162 | #define CM_SPLINE_M12 1.0 163 | #define CM_SPLINE_M13 0.0 164 | #define CM_SPLINE_M14 0.0 165 | #define CM_SPLINE_M21 -0.5 166 | #define CM_SPLINE_M22 0.0 167 | #define CM_SPLINE_M23 0.5 168 | #define CM_SPLINE_M24 0.0 169 | #define CM_SPLINE_M31 1.0 170 | #define CM_SPLINE_M32 -2.5 171 | #define CM_SPLINE_M33 2.0 172 | #define CM_SPLINE_M34 -0.5 173 | #define CM_SPLINE_M41 -0.5 174 | #define CM_SPLINE_M42 1.5 175 | #define CM_SPLINE_M43 -1.5 176 | #define CM_SPLINE_M44 0.5 177 | 178 | // ----------------------------- 179 | float catmullRomSpline(float x, float v0,float v1, 180 | float v2,float v3) 181 | { 182 | 183 | float c1,c2,c3,c4; 184 | 185 | c1 = CM_SPLINE_M12*v1; 186 | c2 = CM_SPLINE_M21*v0 + CM_SPLINE_M23*v2; 187 | c3 = CM_SPLINE_M31*v0 + CM_SPLINE_M32*v1 + CM_SPLINE_M33*v2 + CM_SPLINE_M34*v3; 188 | c4 = CM_SPLINE_M41*v0 + CM_SPLINE_M42*v1 + CM_SPLINE_M43*v2 + CM_SPLINE_M44*v3; 189 | 190 | return(((c4*x + c3)*x +c2)*x + c1); 191 | } 192 | */ 193 | 194 | vec4 grad4(float j, vec4 ip) 195 | { 196 | const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); 197 | vec4 p,s; 198 | 199 | p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; 200 | p.w = 1.5 - dot(abs(p.xyz), ones.xyz); 201 | s = vec4(lessThan(p, vec4(0.0))); 202 | p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; 203 | 204 | return p; 205 | } 206 | -------------------------------------------------------------------------------- /example/bin/data/Common/SimplexNoiseDerivatives4D.glslinc: -------------------------------------------------------------------------------- 1 | #define F4 0.309016994374947451 2 | 3 | // ------------------------------------------------------------------------------------- 4 | // 5 | vec4 simplexNoiseDerivatives (vec4 v) 6 | { 7 | const vec4 C = vec4( 0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958); 8 | 9 | vec4 i = floor(v + dot(v, vec4(F4)) ); 10 | vec4 x0 = v - i + dot(i, C.xxxx); 11 | 12 | vec4 i0; 13 | vec3 isX = step( x0.yzw, x0.xxx ); 14 | vec3 isYZ = step( x0.zww, x0.yyz ); 15 | i0.x = isX.x + isX.y + isX.z; 16 | i0.yzw = 1.0 - isX; 17 | i0.y += isYZ.x + isYZ.y; 18 | i0.zw += 1.0 - isYZ.xy; 19 | i0.z += isYZ.z; 20 | i0.w += 1.0 - isYZ.z; 21 | 22 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 23 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 24 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 25 | 26 | vec4 x1 = x0 - i1 + C.xxxx; 27 | vec4 x2 = x0 - i2 + C.yyyy; 28 | vec4 x3 = x0 - i3 + C.zzzz; 29 | vec4 x4 = x0 + C.wwww; 30 | 31 | i = mod289(i); 32 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 33 | vec4 j1 = permute( permute( permute( permute ( i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 34 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 35 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 36 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 37 | 38 | 39 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 40 | 41 | vec4 p0 = grad4(j0, ip); 42 | vec4 p1 = grad4(j1.x, ip); 43 | vec4 p2 = grad4(j1.y, ip); 44 | vec4 p3 = grad4(j1.z, ip); 45 | vec4 p4 = grad4(j1.w, ip); 46 | 47 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 48 | p0 *= norm.x; 49 | p1 *= norm.y; 50 | p2 *= norm.z; 51 | p3 *= norm.w; 52 | p4 *= taylorInvSqrt(dot(p4,p4)); 53 | 54 | vec3 values0 = vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)); //value of contributions from each corner at point 55 | vec2 values1 = vec2(dot(p3, x3), dot(p4, x4)); 56 | 57 | vec3 m0 = max(0.5 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); //(0.5 - x^2) where x is the distance 58 | vec2 m1 = max(0.5 - vec2(dot(x3,x3), dot(x4,x4)), 0.0); 59 | 60 | vec3 temp0 = -6.0 * m0 * m0 * values0; 61 | vec2 temp1 = -6.0 * m1 * m1 * values1; 62 | 63 | vec3 mmm0 = m0 * m0 * m0; 64 | vec2 mmm1 = m1 * m1 * m1; 65 | 66 | float dx = temp0[0] * x0.x + temp0[1] * x1.x + temp0[2] * x2.x + temp1[0] * x3.x + temp1[1] * x4.x + mmm0[0] * p0.x + mmm0[1] * p1.x + mmm0[2] * p2.x + mmm1[0] * p3.x + mmm1[1] * p4.x; 67 | float dy = temp0[0] * x0.y + temp0[1] * x1.y + temp0[2] * x2.y + temp1[0] * x3.y + temp1[1] * x4.y + mmm0[0] * p0.y + mmm0[1] * p1.y + mmm0[2] * p2.y + mmm1[0] * p3.y + mmm1[1] * p4.y; 68 | float dz = temp0[0] * x0.z + temp0[1] * x1.z + temp0[2] * x2.z + temp1[0] * x3.z + temp1[1] * x4.z + mmm0[0] * p0.z + mmm0[1] * p1.z + mmm0[2] * p2.z + mmm1[0] * p3.z + mmm1[1] * p4.z; 69 | float dw = temp0[0] * x0.w + temp0[1] * x1.w + temp0[2] * x2.w + temp1[0] * x3.w + temp1[1] * x4.w + mmm0[0] * p0.w + mmm0[1] * p1.w + mmm0[2] * p2.w + mmm1[0] * p3.w + mmm1[1] * p4.w; 70 | 71 | return vec4(dx, dy, dz, dw) * 49.0; 72 | } 73 | 74 | 75 | // ------------------------------------------------------------------------------------- 76 | // 77 | vec3 curlNoise( vec3 _p, float _time, int _octaves, float _persistence ) 78 | { 79 | vec4 xNoisePotentialDerivatives = vec4(0.0); 80 | vec4 yNoisePotentialDerivatives = vec4(0.0); 81 | vec4 zNoisePotentialDerivatives = vec4(0.0); 82 | 83 | float tmpPersistence = _persistence; 84 | 85 | for (int i = 0; i < _octaves; ++i) 86 | { 87 | float scale = (1.0 / 2.0) * pow(2.0, float(i)); 88 | 89 | float noiseScale = pow(tmpPersistence, float(i)); 90 | if (tmpPersistence == 0.0 && i == 0) //fix undefined behaviour 91 | { 92 | noiseScale = 1.0; 93 | } 94 | 95 | xNoisePotentialDerivatives += simplexNoiseDerivatives(vec4( _p * pow(2.0, float(i)), _time)) * noiseScale * scale; 96 | yNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(123.4, 129845.6, -1239.1)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 97 | zNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(-9519.0, 9051.0, -123.0)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 98 | } 99 | 100 | //compute curl 101 | vec3 curlVal = vec3( zNoisePotentialDerivatives[1] - yNoisePotentialDerivatives[2], 102 | xNoisePotentialDerivatives[2] - zNoisePotentialDerivatives[0], 103 | yNoisePotentialDerivatives[0] - xNoisePotentialDerivatives[1] ); 104 | 105 | 106 | return curlVal; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /example/bin/data/Common/ofCommon.glslinc: -------------------------------------------------------------------------------- 1 | in vec4 position; 2 | in vec4 color; 3 | in vec3 normal; 4 | in vec2 texcoord; 5 | 6 | uniform mat4 viewMatrix; 7 | uniform mat4 modelViewMatrix; 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 textureMatrix; 10 | uniform mat4 modelViewProjectionMatrix; 11 | uniform vec4 globalColor = vec4(1); 12 | 13 | uniform float usingTexture; 14 | uniform float usingColors; 15 | uniform float bitmapText; 16 | -------------------------------------------------------------------------------- /example/bin/data/shader.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | mode: POINTS 3 | count: 8000 4 | 5 | geom_count: 4 6 | geom_mode: TRIANGLE_STRIP 7 | 8 | -- vertex 9 | 10 | #pragma include "Common/Common.glslinc" 11 | #pragma include "Common/ShaderHelpers.glslinc" 12 | #pragma include "Common/Noise4D.glslinc" 13 | 14 | uniform float Time = 0; 15 | 16 | void main() 17 | { 18 | vec3 G = grid(20, 20, 20); 19 | vec3 V = snoisevec3(vec4(Time * 0.1, 0, 0, 0)) + vec3(0, 0, Time * 0.1); 20 | vec3 C = G + V; 21 | G = fract(C); 22 | 23 | vec3 P = G - 0.5; 24 | P = (rotationMatrix(vec3(0, 1, 0), Time * 0.5) * vec4(P, 1)).xyz; 25 | 26 | P *= 2500; 27 | 28 | P += fbmvec3(vec4(C, Time * 0.5), 5, 1, 1) * 500 * map(sin(Time * 0.1), -1, 1, 0, 1); 29 | 30 | gl_Position = gl_ModelViewProjectionMatrix * vec4(P, 1); 31 | gl_FrontColor = vec4(abs(sin(C * 10)), 1); 32 | } 33 | 34 | -- geometry 35 | 36 | void main() 37 | { 38 | vec3 S = vec3(10, 10, 0); 39 | 40 | float a = length(gl_FrontColorIn[0]); 41 | 42 | gl_FrontColor = gl_FrontColorIn[0]; 43 | gl_Position = gl_PositionIn[0]; 44 | gl_Position.xyz += S * vec3(-1, -1, 0) * a; 45 | EmitVertex(); 46 | 47 | gl_FrontColor = gl_FrontColorIn[0]; 48 | gl_Position = gl_PositionIn[0]; 49 | gl_Position.xyz += S * vec3(1, -1, 0) * a; 50 | EmitVertex(); 51 | 52 | gl_FrontColor = gl_FrontColorIn[0]; 53 | gl_Position = gl_PositionIn[0]; 54 | gl_Position.xyz += S * vec3(-1, 1, 0) * a; 55 | EmitVertex(); 56 | 57 | gl_FrontColor = gl_FrontColorIn[0]; 58 | gl_Position = gl_PositionIn[0]; 59 | gl_Position.xyz += S * vec3(1, 1, 0) * a; 60 | EmitVertex(); 61 | 62 | EndPrimitive(); 63 | } 64 | 65 | -- fragment 66 | 67 | void main() 68 | { 69 | gl_FragColor = gl_Color; 70 | } 71 | -------------------------------------------------------------------------------- /example/config.make: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CONFIGURE PROJECT MAKEFILE (optional) 3 | # This file is where we make project specific configurations. 4 | ################################################################################ 5 | 6 | ################################################################################ 7 | # OF ROOT 8 | # The location of your root openFrameworks installation 9 | # (default) OF_ROOT = ../../.. 10 | ################################################################################ 11 | # OF_ROOT = ../../.. 12 | 13 | ################################################################################ 14 | # PROJECT ROOT 15 | # The location of the project - a starting place for searching for files 16 | # (default) PROJECT_ROOT = . (this directory) 17 | # 18 | ################################################################################ 19 | # PROJECT_ROOT = . 20 | 21 | ################################################################################ 22 | # PROJECT SPECIFIC CHECKS 23 | # This is a project defined section to create internal makefile flags to 24 | # conditionally enable or disable the addition of various features within 25 | # this makefile. For instance, if you want to make changes based on whether 26 | # GTK is installed, one might test that here and create a variable to check. 27 | ################################################################################ 28 | # None 29 | 30 | ################################################################################ 31 | # PROJECT EXTERNAL SOURCE PATHS 32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder. 33 | # Like source folders in the PROJECT_ROOT, these paths are subject to 34 | # exlclusion via the PROJECT_EXLCUSIONS list. 35 | # 36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) 37 | # 38 | # Note: Leave a leading space when adding list items with the += operator 39 | ################################################################################ 40 | # PROJECT_EXTERNAL_SOURCE_PATHS = 41 | 42 | ################################################################################ 43 | # PROJECT EXCLUSIONS 44 | # These makefiles assume that all folders in your current project directory 45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations 46 | # to look for source code. The any folders or files that match any of the 47 | # items in the PROJECT_EXCLUSIONS list below will be ignored. 48 | # 49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete 50 | # string unless teh user adds a wildcard (%) operator to match subdirectories. 51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is 52 | # treated literally. 53 | # 54 | # (default) PROJECT_EXCLUSIONS = (blank) 55 | # 56 | # Will automatically exclude the following: 57 | # 58 | # $(PROJECT_ROOT)/bin% 59 | # $(PROJECT_ROOT)/obj% 60 | # $(PROJECT_ROOT)/%.xcodeproj 61 | # 62 | # Note: Leave a leading space when adding list items with the += operator 63 | ################################################################################ 64 | # PROJECT_EXCLUSIONS = 65 | 66 | ################################################################################ 67 | # PROJECT LINKER FLAGS 68 | # These flags will be sent to the linker when compiling the executable. 69 | # 70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs 71 | # 72 | # Note: Leave a leading space when adding list items with the += operator 73 | ################################################################################ 74 | 75 | # Currently, shared libraries that are needed are copied to the 76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to 77 | # add a runtime path to search for those shared libraries, since they aren't 78 | # incorporated directly into the final executable application binary. 79 | # TODO: should this be a default setting? 80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs 81 | 82 | ################################################################################ 83 | # PROJECT DEFINES 84 | # Create a space-delimited list of DEFINES. The list will be converted into 85 | # CFLAGS with the "-D" flag later in the makefile. 86 | # 87 | # (default) PROJECT_DEFINES = (blank) 88 | # 89 | # Note: Leave a leading space when adding list items with the += operator 90 | ################################################################################ 91 | # PROJECT_DEFINES = 92 | 93 | ################################################################################ 94 | # PROJECT CFLAGS 95 | # This is a list of fully qualified CFLAGS required when compiling for this 96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS 97 | # defined in your platform specific core configuration files. These flags are 98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. 99 | # 100 | # (default) PROJECT_CFLAGS = (blank) 101 | # 102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in 103 | # your platform specific configuration file will be applied by default and 104 | # further flags here may not be needed. 105 | # 106 | # Note: Leave a leading space when adding list items with the += operator 107 | ################################################################################ 108 | # PROJECT_CFLAGS = 109 | 110 | ################################################################################ 111 | # PROJECT OPTIMIZATION CFLAGS 112 | # These are lists of CFLAGS that are target-specific. While any flags could 113 | # be conditionally added, they are usually limited to optimization flags. 114 | # These flags are added BEFORE the PROJECT_CFLAGS. 115 | # 116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. 117 | # 118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) 119 | # 120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. 121 | # 122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) 123 | # 124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the 125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration 126 | # file will be applied by default and further optimization flags here may not 127 | # be needed. 128 | # 129 | # Note: Leave a leading space when adding list items with the += operator 130 | ################################################################################ 131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE = 132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG = 133 | 134 | ################################################################################ 135 | # PROJECT COMPILERS 136 | # Custom compilers can be set for CC and CXX 137 | # (default) PROJECT_CXX = (blank) 138 | # (default) PROJECT_CC = (blank) 139 | # Note: Leave a leading space when adding list items with the += operator 140 | ################################################################################ 141 | # PROJECT_CXX = 142 | # PROJECT_CC = 143 | -------------------------------------------------------------------------------- /example/example.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 14 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 17 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 18 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 23 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 25 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 26 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 28 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 29 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 30 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /example/example.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A} 23 | Win32Proj 24 | example 25 | 26 | 27 | 28 | Application 29 | Unicode 30 | v140 31 | 32 | 33 | Application 34 | Unicode 35 | v140 36 | 37 | 38 | Application 39 | Unicode 40 | true 41 | v140 42 | 43 | 44 | Application 45 | Unicode 46 | true 47 | v140 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | bin\ 69 | obj\$(Configuration)\ 70 | $(ProjectName)_debug 71 | true 72 | true 73 | 74 | 75 | bin\ 76 | obj\$(Configuration)\ 77 | $(ProjectName)_debug 78 | true 79 | true 80 | 81 | 82 | bin\ 83 | obj\$(Configuration)\ 84 | false 85 | 86 | 87 | bin\ 88 | obj\$(Configuration)\ 89 | false 90 | 91 | 92 | 93 | Disabled 94 | EnableFastChecks 95 | %(PreprocessorDefinitions) 96 | MultiThreadedDebugDLL 97 | Level3 98 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 99 | CompileAsCpp 100 | 101 | 102 | true 103 | Console 104 | false 105 | %(AdditionalDependencies) 106 | %(AdditionalLibraryDirectories) 107 | 108 | 109 | 110 | 111 | 112 | Disabled 113 | EnableFastChecks 114 | %(PreprocessorDefinitions) 115 | MultiThreadedDebugDLL 116 | Level3 117 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 118 | CompileAsCpp 119 | true 120 | 121 | 122 | true 123 | Console 124 | false 125 | %(AdditionalDependencies) 126 | %(AdditionalLibraryDirectories) 127 | 128 | 129 | 130 | 131 | 132 | false 133 | %(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | Level3 136 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 137 | CompileAsCpp 138 | true 139 | 140 | 141 | false 142 | false 143 | Console 144 | true 145 | true 146 | false 147 | %(AdditionalDependencies) 148 | %(AdditionalLibraryDirectories) 149 | 150 | 151 | 152 | 153 | 154 | false 155 | %(PreprocessorDefinitions) 156 | MultiThreadedDLL 157 | Level3 158 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxShaderRunner\src 159 | CompileAsCpp 160 | 161 | 162 | false 163 | false 164 | Console 165 | true 166 | true 167 | false 168 | %(AdditionalDependencies) 169 | %(AdditionalLibraryDirectories) 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | {5837595d-aca9-485c-8e76-729040ce4b0b} 182 | 183 | 184 | 185 | 186 | /D_DEBUG %(AdditionalOptions) 187 | /D_DEBUG %(AdditionalOptions) 188 | $(OF_ROOT)\libs\openFrameworksCompiled\project\vs 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /example/example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | src 6 | 7 | 8 | src 9 | 10 | 11 | 12 | 13 | {d8376475-7454-4a24-b08a-aac121d3ad6f} 14 | 15 | 16 | {71834F65-F3A9-211E-73B8-DC85} 17 | 18 | 19 | {CD60902F-C905-86E8-6E9D-BB17} 20 | 21 | 22 | {20F1F5CE-83F5-6111-D1EE-C15F} 23 | 24 | 25 | 26 | 27 | addons\ofxShaderRunner\src 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/icon.rc: -------------------------------------------------------------------------------- 1 | // Icon Resource Definition 2 | #define MAIN_ICON 102 3 | 4 | #if defined(_DEBUG) 5 | MAIN_ICON ICON "icon_debug.ico" 6 | #else 7 | MAIN_ICON ICON "icon.ico" 8 | #endif 9 | -------------------------------------------------------------------------------- /example/openFrameworks-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | cc.openFrameworks.ofapp 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | CFBundleIconFile 20 | ${ICON} 21 | 22 | 23 | -------------------------------------------------------------------------------- /example/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | 3 | #include "ofxShaderRunner.h" 4 | 5 | class ofApp : public ofBaseApp 6 | { 7 | public: 8 | 9 | ofEasyCam cam; 10 | 11 | ofxShaderRunner S; 12 | 13 | void setup() 14 | { 15 | ofSetFrameRate(60); 16 | ofSetVerticalSync(true); 17 | ofBackground(0); 18 | 19 | S.load("shader.glsl"); 20 | } 21 | 22 | void update() 23 | { 24 | ofSetWindowTitle(ofToString(ofGetFrameRate())); 25 | } 26 | 27 | void draw() 28 | { 29 | ofEnableDepthTest(); 30 | glPointSize(4); 31 | 32 | cam.begin(); 33 | { 34 | S.draw(); 35 | } 36 | cam.end(); 37 | } 38 | 39 | void keyPressed(int key) 40 | { 41 | } 42 | 43 | void keyReleased(int key) 44 | { 45 | } 46 | 47 | void mouseMoved(int x, int y) 48 | { 49 | } 50 | 51 | void mouseDragged(int x, int y, int button) 52 | { 53 | } 54 | 55 | void mousePressed(int x, int y, int button) 56 | { 57 | } 58 | 59 | void mouseReleased(int x, int y, int button) 60 | { 61 | } 62 | 63 | void windowResized(int w, int h) 64 | { 65 | } 66 | }; 67 | 68 | 69 | int main(int argc, const char** argv) 70 | { 71 | ofSetupOpenGL(640, 480, OF_WINDOW); 72 | ofRunApp(new ofApp); 73 | return 0; 74 | } -------------------------------------------------------------------------------- /shader/Common/Common.glslinc: -------------------------------------------------------------------------------- 1 | vec2 grid(int x, int y) 2 | { 3 | return vec2(mod(gl_VertexID, x) / x, float(gl_VertexID / x) / y); 4 | } 5 | 6 | vec3 grid(int x, int y, int z) 7 | { 8 | int vid = gl_VertexID; 9 | vec3 id; 10 | float T = gl_VertexID / (x * y); 11 | float TT = mod(gl_VertexID, x * y); 12 | id.z = T / (z - 1); 13 | id.y = floor(TT / y) / (y - 1); 14 | id.x = (mod(TT, y)) / (x - 1); 15 | return id; 16 | } 17 | -------------------------------------------------------------------------------- /shader/Common/Noise2D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D simplex noise function. 3 | // Author : Ian McEwan, Ashima Arts. 4 | // Maintainer : ijm 5 | // Lastmod : 20110822 (ijm) 6 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 7 | // Distributed under the MIT License. See LICENSE file. 8 | // https://github.com/ashima/webgl-noise 9 | // 10 | 11 | // ------------------------------------------------------------------------------------- 12 | // 13 | float snoise(vec2 v) 14 | { 15 | const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 16 | 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) 17 | -0.577350269189626, // -1.0 + 2.0 * C.x 18 | 0.024390243902439); // 1.0 / 41.0 19 | // First corner 20 | vec2 i = floor(v + dot(v, C.yy) ); 21 | vec2 x0 = v - i + dot(i, C.xx); 22 | 23 | // Other corners 24 | vec2 i1; 25 | //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 26 | //i1.y = 1.0 - i1.x; 27 | i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); 28 | // x0 = x0 - 0.0 + 0.0 * C.xx ; 29 | // x1 = x0 - i1 + 1.0 * C.xx ; 30 | // x2 = x0 - 1.0 + 2.0 * C.xx ; 31 | vec4 x12 = x0.xyxy + C.xxzz; 32 | x12.xy -= i1; 33 | 34 | // Permutations 35 | i = mod289(i); // Avoid truncation effects in permutation 36 | vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) 37 | + i.x + vec3(0.0, i1.x, 1.0 )); 38 | 39 | vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); 40 | m = m*m ; 41 | m = m*m ; 42 | 43 | // Gradients: 41 points uniformly over a line, mapped onto a diamond. 44 | // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 45 | 46 | vec3 x = 2.0 * fract(p * C.www) - 1.0; 47 | vec3 h = abs(x) - 0.5; 48 | vec3 ox = floor(x + 0.5); 49 | vec3 a0 = x - ox; 50 | 51 | // Normalise gradients implicitly by scaling m 52 | // Approximation of: m *= inversesqrt( a0*a0 + h*h ); 53 | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); 54 | 55 | // Compute final noise value at P 56 | vec3 g; 57 | g.x = a0.x * x0.x + h.x * x0.y; 58 | g.yz = a0.yz * x12.xz + h.yz * x12.yw; 59 | return 130.0 * dot(m, g); 60 | } 61 | 62 | // ------------------------------------------------------------------------------------- 63 | // 64 | float snoiseu(vec2 v) 65 | { 66 | return (snoise( v ) + 1.0) * 0.5; 67 | } 68 | 69 | // ------------------------------------------------------------------------------------- 70 | // 71 | float fbm_5oct( vec2 p ) 72 | { 73 | float f = 0.0; 74 | f += 0.50000*snoise( p ); p = p*2.02; 75 | f += 0.25000*snoise( p ); p = p*2.03; 76 | f += 0.12500*snoise( p ); p = p*2.01; 77 | f += 0.06250*snoise( p ); p = p*2.04; 78 | f += 0.03125*snoise( p ); 79 | return f/0.984375; 80 | } 81 | 82 | // ------------------------------------------------------------------------------------- 83 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 84 | // 85 | float fbm(vec2 P, int octaves, float lacunarity, float gain) 86 | { 87 | float sum = 0.0; 88 | float amp = 1.0; 89 | vec2 pp = P; 90 | 91 | for( int i = 0; i < octaves; i+=1) 92 | { 93 | amp *= gain; 94 | sum += amp * snoise(pp); 95 | pp *= lacunarity; 96 | } 97 | 98 | return sum; 99 | } 100 | 101 | // ------------------------------------------------------------------------------------- 102 | // Returns the FBM in the range 0..1 103 | // 104 | float fbmu(vec2 _p, int _octaves, float _lacunarity, float _persistence ) 105 | { 106 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /shader/Common/Noise3D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // ------------------------------------------------------------------------------------- 13 | // 14 | float snoise(vec3 v) 15 | { 16 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 17 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 18 | 19 | // First corner 20 | vec3 i = floor(v + dot(v, C.yyy) ); 21 | vec3 x0 = v - i + dot(i, C.xxx) ; 22 | 23 | // Other corners 24 | vec3 g = step(x0.yzx, x0.xyz); 25 | vec3 l = 1.0 - g; 26 | vec3 i1 = min( g.xyz, l.zxy ); 27 | vec3 i2 = max( g.xyz, l.zxy ); 28 | 29 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 30 | // x1 = x0 - i1 + 1.0 * C.xxx; 31 | // x2 = x0 - i2 + 2.0 * C.xxx; 32 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 33 | vec3 x1 = x0 - i1 + C.xxx; 34 | vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 35 | vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 36 | 37 | // Permutations 38 | i = mod289(i); 39 | vec4 p = permute( permute( permute( 40 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 41 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 42 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 43 | 44 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 45 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 46 | float n_ = 0.142857142857; // 1.0/7.0 47 | vec3 ns = n_ * D.wyz - D.xzx; 48 | 49 | vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 50 | 51 | vec4 x_ = floor(j * ns.z); 52 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 53 | 54 | vec4 x = x_ *ns.x + ns.yyyy; 55 | vec4 y = y_ *ns.x + ns.yyyy; 56 | vec4 h = 1.0 - abs(x) - abs(y); 57 | 58 | vec4 b0 = vec4( x.xy, y.xy ); 59 | vec4 b1 = vec4( x.zw, y.zw ); 60 | 61 | //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; 62 | //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; 63 | vec4 s0 = floor(b0)*2.0 + 1.0; 64 | vec4 s1 = floor(b1)*2.0 + 1.0; 65 | vec4 sh = -step(h, vec4(0.0)); 66 | 67 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 68 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 69 | 70 | vec3 p0 = vec3(a0.xy,h.x); 71 | vec3 p1 = vec3(a0.zw,h.y); 72 | vec3 p2 = vec3(a1.xy,h.z); 73 | vec3 p3 = vec3(a1.zw,h.w); 74 | 75 | //Normalise gradients 76 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 77 | p0 *= norm.x; 78 | p1 *= norm.y; 79 | p2 *= norm.z; 80 | p3 *= norm.w; 81 | 82 | // Mix final noise value 83 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 84 | m = m * m; 85 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 86 | dot(p2,x2), dot(p3,x3) ) ); 87 | } 88 | 89 | // ------------------------------------------------------------------------------------- 90 | // 91 | float fbm_2oct(vec3 p) 92 | { 93 | float final = snoise(p); 94 | p *= 1.94; 95 | final += snoise(p) * 0.5; 96 | return final / 1.5; 97 | } 98 | 99 | // ------------------------------------------------------------------------------------- 100 | // 101 | float fbm_3oct(vec3 p) 102 | { 103 | float final = snoise(p); 104 | p *= 1.94; 105 | final += snoise(p) * 0.5; 106 | p *= 3.75; 107 | final += snoise(p) * 0.25; 108 | return final / 1.75; 109 | 110 | } 111 | 112 | // ------------------------------------------------------------------------------------- 113 | // 114 | float fbm_5oct( vec3 p ) 115 | { 116 | float f = 0.0; 117 | f += 0.50000*snoise( p ); p = p*2.02; 118 | f += 0.25000*snoise( p ); p = p*2.03; 119 | f += 0.12500*snoise( p ); p = p*2.01; 120 | f += 0.06250*snoise( p ); p = p*2.04; 121 | f += 0.03125*snoise( p ); 122 | return f/0.984375; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 127 | // 128 | float fbm(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 129 | { 130 | float sum = 0.0; 131 | float amp = 1.0; 132 | vec3 pp = _p; 133 | float totalAmp = 0.0; 134 | 135 | for( int i = 0; i < _octaves; i++) 136 | { 137 | amp *= _persistence; 138 | totalAmp += amp; 139 | sum += amp * snoise(pp); 140 | pp *= _lacunarity; 141 | } 142 | 143 | return sum / totalAmp; 144 | } 145 | 146 | // ------------------------------------------------------------------------------------- 147 | // Returns the FBM in the range 0..1 148 | // 149 | float fbmu(vec3 _p, int _octaves, float _lacunarity, float _persistence ) 150 | { 151 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 152 | } 153 | -------------------------------------------------------------------------------- /shader/Common/Noise4D.glslinc: -------------------------------------------------------------------------------- 1 | // 2 | // Description : Array and textureless GLSL 2D/3D/4D simplex 3 | // noise functions. 4 | // Author : Ian McEwan, Ashima Arts. 5 | // Maintainer : ijm 6 | // Lastmod : 20110822 (ijm) 7 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 8 | // Distributed under the MIT License. See LICENSE file. 9 | // https://github.com/ashima/webgl-noise 10 | // 11 | 12 | // (sqrt(5) - 1)/4 = F4, used once below 13 | #define F4 0.309016994374947451 14 | 15 | // ------------------------------------------------------------------------------------- 16 | // 17 | float snoise(vec4 v) 18 | { 19 | const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4 20 | 0.276393202250021, // 2 * G4 21 | 0.414589803375032, // 3 * G4 22 | -0.447213595499958); // -1 + 4 * G4 23 | 24 | // First corner 25 | vec4 i = floor(v + dot(v, vec4(F4)) ); 26 | vec4 x0 = v - i + dot(i, C.xxxx); 27 | 28 | // Other corners 29 | 30 | // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) 31 | vec4 i0; 32 | vec3 isX = step( x0.yzw, x0.xxx ); 33 | vec3 isYZ = step( x0.zww, x0.yyz ); 34 | // i0.x = dot( isX, vec3( 1.0 ) ); 35 | i0.x = isX.x + isX.y + isX.z; 36 | i0.yzw = 1.0 - isX; 37 | // i0.y += dot( isYZ.xy, vec2( 1.0 ) ); 38 | i0.y += isYZ.x + isYZ.y; 39 | i0.zw += 1.0 - isYZ.xy; 40 | i0.z += isYZ.z; 41 | i0.w += 1.0 - isYZ.z; 42 | 43 | // i0 now contains the unique values 0,1,2,3 in each channel 44 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 45 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 46 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 47 | 48 | // x0 = x0 - 0.0 + 0.0 * C.xxxx 49 | // x1 = x0 - i1 + 1.0 * C.xxxx 50 | // x2 = x0 - i2 + 2.0 * C.xxxx 51 | // x3 = x0 - i3 + 3.0 * C.xxxx 52 | // x4 = x0 - 1.0 + 4.0 * C.xxxx 53 | vec4 x1 = x0 - i1 + C.xxxx; 54 | vec4 x2 = x0 - i2 + C.yyyy; 55 | vec4 x3 = x0 - i3 + C.zzzz; 56 | vec4 x4 = x0 + C.wwww; 57 | 58 | // Permutations 59 | i = mod289(i); 60 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 61 | vec4 j1 = permute( permute( permute( permute ( 62 | i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 63 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 64 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 65 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 66 | 67 | // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope 68 | // 7*7*6 = 294, which is close to the ring size 17*17 = 289. 69 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 70 | 71 | vec4 p0 = grad4(j0, ip); 72 | vec4 p1 = grad4(j1.x, ip); 73 | vec4 p2 = grad4(j1.y, ip); 74 | vec4 p3 = grad4(j1.z, ip); 75 | vec4 p4 = grad4(j1.w, ip); 76 | 77 | // Normalise gradients 78 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 79 | p0 *= norm.x; 80 | p1 *= norm.y; 81 | p2 *= norm.z; 82 | p3 *= norm.w; 83 | p4 *= taylorInvSqrt(dot(p4,p4)); 84 | 85 | // Mix contributions from the five corners 86 | vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); 87 | vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); 88 | m0 = m0 * m0; 89 | m1 = m1 * m1; 90 | return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) 91 | + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; 92 | 93 | } 94 | 95 | 96 | // ------------------------------------------------------------------------------------- 97 | // Standard is _lacunarity = 2.0 and _persistence = 0.5 98 | // 99 | float fbm(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 100 | { 101 | float sum = 0.0; 102 | float amp = 1.0; 103 | vec4 pp = _p; 104 | float totalAmp = 0.0; 105 | 106 | for( int i = 0; i < _octaves; i++) 107 | { 108 | amp *= _persistence; 109 | totalAmp += amp; 110 | sum += amp * snoise(pp); 111 | pp *= _lacunarity; 112 | } 113 | 114 | return sum / totalAmp; 115 | } 116 | 117 | // ------------------------------------------------------------------------------------- 118 | // Returns the FBM in the range 0..1 119 | // 120 | float fbmu(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 121 | { 122 | return (fbm( _p, _octaves, _lacunarity, _persistence ) + 1.0) * 0.5; 123 | } 124 | 125 | // ------------------------------------------------------------------------------------- 126 | // 127 | vec3 fbmvec3(vec4 _p, int _octaves, float _lacunarity, float _persistence ) 128 | { 129 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 130 | tmp.x = fbm( vec4( _p.x, _p.y, _p.z, _p.w ), _octaves, _lacunarity, _persistence ); 131 | tmp.y = fbm( vec4( _p.y + 3.422, _p.x + 21.13, _p.w + 312.2, _p.z + 132.32 ), _octaves, _lacunarity, _persistence ); 132 | tmp.z = fbm( vec4( _p.w + 1.234, _p.z + 87.31, _p.y + 2367.1, _p.x + 894.21 ), _octaves, _lacunarity, _persistence ); 133 | return tmp; 134 | } 135 | 136 | // ------------------------------------------------------------------------------------- 137 | vec3 snoisevec3( vec4 _p ) 138 | { 139 | vec3 tmp = vec3( 0.0, 0.0, 0.0 ); 140 | tmp.x = snoise( vec4( _p.x, _p.y, _p.z, _p.w ) ); 141 | tmp.y = snoise( vec4( _p.y, _p.x, _p.w, _p.z ) ); 142 | tmp.z = snoise( vec4( _p.w, _p.z, _p.y, _p.x ) ); 143 | return tmp; 144 | } -------------------------------------------------------------------------------- /shader/Common/PhotoshopBlendModes.glslinc: -------------------------------------------------------------------------------- 1 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 2 | // 3 | // 25 of the layer blending modes from Photoshop. 4 | // 5 | // The ones I couldn't figure out are from Nvidia's advanced blend equations extension spec - 6 | // http://www.opengl.org/registry/specs/NV/blend_equation_advanced.txt 7 | // 8 | // ~bj.2013 9 | // 10 | 11 | vec3 darken( vec3 s, vec3 d ) 12 | { 13 | return min(s,d); 14 | } 15 | 16 | vec3 multiply( vec3 s, vec3 d ) 17 | { 18 | return s*d; 19 | } 20 | 21 | vec3 colorBurn( vec3 s, vec3 d ) 22 | { 23 | return 1.0 - (1.0 - d) / s; 24 | } 25 | 26 | vec3 linearBurn( vec3 s, vec3 d ) 27 | { 28 | return s + d - 1.0; 29 | } 30 | 31 | vec3 darkerColor( vec3 s, vec3 d ) 32 | { 33 | return (s.x + s.y + s.z < d.x + d.y + d.z) ? s : d; 34 | } 35 | 36 | vec3 lighten( vec3 s, vec3 d ) 37 | { 38 | return max(s,d); 39 | } 40 | 41 | vec3 screen( vec3 s, vec3 d ) 42 | { 43 | return s + d - s * d; 44 | } 45 | 46 | vec3 colorDodge( vec3 s, vec3 d ) 47 | { 48 | return d / (1.0 - s); 49 | } 50 | 51 | vec3 linearDodge( vec3 s, vec3 d ) 52 | { 53 | return s + d; 54 | } 55 | 56 | vec3 lighterColor( vec3 s, vec3 d ) 57 | { 58 | return (s.x + s.y + s.z > d.x + d.y + d.z) ? s : d; 59 | } 60 | 61 | float overlay( float s, float d ) 62 | { 63 | return (d < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 64 | } 65 | 66 | vec3 overlay( vec3 s, vec3 d ) 67 | { 68 | vec3 c; 69 | c.x = overlay(s.x,d.x); 70 | c.y = overlay(s.y,d.y); 71 | c.z = overlay(s.z,d.z); 72 | return c; 73 | } 74 | 75 | float softLight( float s, float d ) 76 | { 77 | return (s < 0.5) ? d - (1.0 - 2.0 * s) * d * (1.0 - d) 78 | : (d < 0.25) ? d + (2.0 * s - 1.0) * d * ((16.0 * d - 12.0) * d + 3.0) 79 | : d + (2.0 * s - 1.0) * (sqrt(d) - d); 80 | } 81 | 82 | vec3 softLight( vec3 s, vec3 d ) 83 | { 84 | vec3 c; 85 | c.x = softLight(s.x,d.x); 86 | c.y = softLight(s.y,d.y); 87 | c.z = softLight(s.z,d.z); 88 | return c; 89 | } 90 | 91 | float hardLight( float s, float d ) 92 | { 93 | return (s < 0.5) ? 2.0 * s * d : 1.0 - 2.0 * (1.0 - s) * (1.0 - d); 94 | } 95 | 96 | vec3 hardLight( vec3 s, vec3 d ) 97 | { 98 | vec3 c; 99 | c.x = hardLight(s.x,d.x); 100 | c.y = hardLight(s.y,d.y); 101 | c.z = hardLight(s.z,d.z); 102 | return c; 103 | } 104 | 105 | float vividLight( float s, float d ) 106 | { 107 | return (s < 0.5) ? 1.0 - (1.0 - d) / (2.0 * s) : d / (2.0 * (1.0 - s)); 108 | } 109 | 110 | vec3 vividLight( vec3 s, vec3 d ) 111 | { 112 | vec3 c; 113 | c.x = vividLight(s.x,d.x); 114 | c.y = vividLight(s.y,d.y); 115 | c.z = vividLight(s.z,d.z); 116 | return c; 117 | } 118 | 119 | vec3 linearLight( vec3 s, vec3 d ) 120 | { 121 | return 2.0 * s + d - 1.0; 122 | } 123 | 124 | float pinLight( float s, float d ) 125 | { 126 | return (2.0 * s - 1.0 > d) ? 2.0 * s - 1.0 : (s < 0.5 * d) ? 2.0 * s : d; 127 | } 128 | 129 | vec3 pinLight( vec3 s, vec3 d ) 130 | { 131 | vec3 c; 132 | c.x = pinLight(s.x,d.x); 133 | c.y = pinLight(s.y,d.y); 134 | c.z = pinLight(s.z,d.z); 135 | return c; 136 | } 137 | 138 | vec3 hardMix( vec3 s, vec3 d ) 139 | { 140 | return floor(s + d); 141 | } 142 | 143 | vec3 difference( vec3 s, vec3 d ) 144 | { 145 | return abs(d - s); 146 | } 147 | 148 | vec3 exclusion( vec3 s, vec3 d ) 149 | { 150 | return s + d - 2.0 * s * d; 151 | } 152 | 153 | vec3 subtract( vec3 s, vec3 d ) 154 | { 155 | return s - d; 156 | } 157 | 158 | vec3 divide( vec3 s, vec3 d ) 159 | { 160 | return s / d; 161 | } 162 | 163 | // rgb<-->hsv functions by Sam Hocevar 164 | // http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl 165 | vec3 rgb2hsv(vec3 c) 166 | { 167 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 168 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 169 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 170 | 171 | float d = q.x - min(q.w, q.y); 172 | float e = 1.0e-10; 173 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 174 | } 175 | 176 | vec3 hsv2rgb(vec3 c) 177 | { 178 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 179 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 180 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 181 | } 182 | 183 | vec3 hue( vec3 s, vec3 d ) 184 | { 185 | d = rgb2hsv(d); 186 | d.x = rgb2hsv(s).x; 187 | return hsv2rgb(d); 188 | } 189 | 190 | vec3 color( vec3 s, vec3 d ) 191 | { 192 | s = rgb2hsv(s); 193 | s.z = rgb2hsv(d).z; 194 | return hsv2rgb(s); 195 | } 196 | 197 | vec3 saturation( vec3 s, vec3 d ) 198 | { 199 | d = rgb2hsv(d); 200 | d.y = rgb2hsv(s).y; 201 | return hsv2rgb(d); 202 | } 203 | 204 | vec3 luminosity( vec3 s, vec3 d ) 205 | { 206 | float dLum = dot(d, vec3(0.3, 0.59, 0.11)); 207 | float sLum = dot(s, vec3(0.3, 0.59, 0.11)); 208 | float lum = sLum - dLum; 209 | vec3 c = d + lum; 210 | float minC = min(min(c.x, c.y), c.z); 211 | float maxC = max(max(c.x, c.y), c.z); 212 | if(minC < 0.0) return sLum + ((c - sLum) * sLum) / (sLum - minC); 213 | else if(maxC > 1.0) return sLum + ((c - sLum) * (1.0 - sLum)) / (maxC - sLum); 214 | else return c; 215 | } 216 | -------------------------------------------------------------------------------- /shader/Common/ShaderHelpers.glslinc: -------------------------------------------------------------------------------- 1 | #define HALF_PI 1.57079632679489661923 2 | #define PI 3.14159265358979323846 3 | #define TWO_PI 6.28318530717958647693 4 | 5 | float map( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 6 | float mapClamped( float value, float inputMin, float inputMax, float outputMin, float outputMax ) { return clamp( ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin), outputMin, outputMax ); } 7 | 8 | vec3 map( vec3 value, vec3 inputMin, vec3 inputMax, vec3 outputMin, vec3 outputMax ) { return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); } 9 | 10 | float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } 11 | float stepInOut( float _edge1, float _edge2, float _val ) { return step(_edge1, _val) - step(_edge2,_val); } 12 | float smoothStepInOut( float _low0, float _high0, float _high1, float _low1, float _t ) { return smoothstep( _low0, _high0, _t ) * (1.0 - smoothstep( _high1, _low1, _t )); } 13 | 14 | float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 15 | vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 16 | vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 17 | vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } 18 | 19 | float permute(float x) { return mod289(((x*34.0)+1.0)*x); } 20 | vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); } 21 | vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); } 22 | 23 | float taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; } 24 | vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; } 25 | 26 | 27 | // ------------------------------------------------------------ 28 | mat4 makeLookAt(vec3 eye, vec3 center, vec3 up) 29 | { 30 | mat4 M; 31 | 32 | vec3 zaxis = normalize(eye - center); 33 | vec3 xaxis = normalize( cross(up, zaxis) ); 34 | vec3 yaxis = cross(zaxis,xaxis); 35 | 36 | M[0] = vec4(xaxis,0); 37 | M[1] = vec4(yaxis,0); 38 | M[2] = vec4(zaxis,0); 39 | M[3] = vec4(eye,1); 40 | 41 | return M; 42 | } 43 | 44 | // ------------------------------------------------------------ 45 | mat4 rotationMatrix(vec3 axis, float angle) 46 | { 47 | axis = normalize(axis); 48 | float s = sin(angle); 49 | float c = cos(angle); 50 | float oc = 1.0 - c; 51 | 52 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 53 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 54 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 55 | 0.0, 0.0, 0.0, 1.0); 56 | } 57 | 58 | 59 | // -------------------------------------- 60 | vec3 randomPointOnSphere( vec3 _random ) 61 | { 62 | float lambda = _random.x; 63 | float u = map( _random.y, 0.0, 1.0, -1.0, 1.0 ); 64 | float phi = _random.z * (2.0 * PI ); 65 | 66 | vec3 p; 67 | p.x = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * cos(phi); 68 | p.y = pow(lambda, 1.0/3.0) * sqrt(1.0 - u * u) * sin(phi); 69 | p.z = pow(lambda, 1.0/3.0) * u; 70 | 71 | return p; 72 | } 73 | 74 | // -------------------------------------- 75 | vec3 opTwistX( vec3 _p, float _angPerUnit ) 76 | { 77 | float c = cos( _angPerUnit * _p.x); 78 | float s = sin( _angPerUnit * _p.x); 79 | mat2 m = mat2(c,-s,s,c); 80 | return vec3( _p.x, m * _p.yz ); 81 | } 82 | 83 | // -------------------------------------- 84 | vec3 opTwistY( vec3 _p, float _angPerUnit ) 85 | { 86 | float c = cos( _angPerUnit * _p.y); 87 | float s = sin( _angPerUnit * _p.y); 88 | mat2 m = mat2(c,-s,s,c); 89 | 90 | vec2 rotXZ = m * _p.xz; 91 | 92 | return vec3( rotXZ.x, _p.y, rotXZ.y ); 93 | } 94 | 95 | // -------------------------------------- 96 | vec3 opTwistZ( vec3 _p, float _angPerUnit ) 97 | { 98 | float c = cos( _angPerUnit * _p.z); 99 | float s = sin( _angPerUnit * _p.z); 100 | mat2 m = mat2(c,-s,s,c); 101 | 102 | vec2 rotXY = m * _p.xy; 103 | 104 | return vec3( rotXY.x, rotXY.y, _p.z ); 105 | } 106 | 107 | // -------------------------------------- 108 | float CatmullRom( float u, float x0, float x1, float x2, float x3 ) 109 | { 110 | float u2 = u * u; 111 | float u3 = u2 * u; 112 | return ((2 * x1) + 113 | (-x0 + x2) * u + 114 | (2*x0 - 5*x1 + 4*x2 - x3) * u2 + 115 | (-x0 + 3*x1 - 3*x2 + x3) * u3) * 0.5; 116 | } 117 | 118 | // http://www.iquilezles.org/www/articles/functions/functions.htm 119 | 120 | // -------------------------------------- 121 | float cubicPulse( float c, float w, float x ) 122 | { 123 | x = abs(x - c); 124 | if( x>w ) return 0.0; 125 | x /= w; 126 | return 1.0 - x*x*(3.0-2.0*x); 127 | } 128 | 129 | // -------------------------------------- 130 | float expStep( float x, float k, float n ) 131 | { 132 | return exp( -k*pow(x,n) ); 133 | } 134 | 135 | // -------------------------------------- 136 | float parabola( float x, float k ) 137 | { 138 | return pow( 4.0*x*(1.0-x), k ); 139 | } 140 | 141 | // -------------------------------------- 142 | float pcurve( float x, float a, float b ) 143 | { 144 | float k = pow(a+b,a+b) / (pow(a,a)*pow(b,b)); 145 | return k * pow( x, a ) * pow( 1.0-x, b ); 146 | } 147 | 148 | // -------------------------------------- 149 | float impulse( float k, float x ) 150 | { 151 | float h = k*x; 152 | return h*exp(1.0-h); 153 | } 154 | 155 | 156 | /* 157 | // ----------------------------- 158 | // Coefficients for Matrix M 159 | // 160 | 161 | #define CM_SPLINE_M11 0.0 162 | #define CM_SPLINE_M12 1.0 163 | #define CM_SPLINE_M13 0.0 164 | #define CM_SPLINE_M14 0.0 165 | #define CM_SPLINE_M21 -0.5 166 | #define CM_SPLINE_M22 0.0 167 | #define CM_SPLINE_M23 0.5 168 | #define CM_SPLINE_M24 0.0 169 | #define CM_SPLINE_M31 1.0 170 | #define CM_SPLINE_M32 -2.5 171 | #define CM_SPLINE_M33 2.0 172 | #define CM_SPLINE_M34 -0.5 173 | #define CM_SPLINE_M41 -0.5 174 | #define CM_SPLINE_M42 1.5 175 | #define CM_SPLINE_M43 -1.5 176 | #define CM_SPLINE_M44 0.5 177 | 178 | // ----------------------------- 179 | float catmullRomSpline(float x, float v0,float v1, 180 | float v2,float v3) 181 | { 182 | 183 | float c1,c2,c3,c4; 184 | 185 | c1 = CM_SPLINE_M12*v1; 186 | c2 = CM_SPLINE_M21*v0 + CM_SPLINE_M23*v2; 187 | c3 = CM_SPLINE_M31*v0 + CM_SPLINE_M32*v1 + CM_SPLINE_M33*v2 + CM_SPLINE_M34*v3; 188 | c4 = CM_SPLINE_M41*v0 + CM_SPLINE_M42*v1 + CM_SPLINE_M43*v2 + CM_SPLINE_M44*v3; 189 | 190 | return(((c4*x + c3)*x +c2)*x + c1); 191 | } 192 | */ 193 | 194 | vec4 grad4(float j, vec4 ip) 195 | { 196 | const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); 197 | vec4 p,s; 198 | 199 | p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; 200 | p.w = 1.5 - dot(abs(p.xyz), ones.xyz); 201 | s = vec4(lessThan(p, vec4(0.0))); 202 | p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; 203 | 204 | return p; 205 | } 206 | -------------------------------------------------------------------------------- /shader/Common/SimplexNoiseDerivatives4D.glslinc: -------------------------------------------------------------------------------- 1 | #define F4 0.309016994374947451 2 | 3 | // ------------------------------------------------------------------------------------- 4 | // 5 | vec4 simplexNoiseDerivatives (vec4 v) 6 | { 7 | const vec4 C = vec4( 0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958); 8 | 9 | vec4 i = floor(v + dot(v, vec4(F4)) ); 10 | vec4 x0 = v - i + dot(i, C.xxxx); 11 | 12 | vec4 i0; 13 | vec3 isX = step( x0.yzw, x0.xxx ); 14 | vec3 isYZ = step( x0.zww, x0.yyz ); 15 | i0.x = isX.x + isX.y + isX.z; 16 | i0.yzw = 1.0 - isX; 17 | i0.y += isYZ.x + isYZ.y; 18 | i0.zw += 1.0 - isYZ.xy; 19 | i0.z += isYZ.z; 20 | i0.w += 1.0 - isYZ.z; 21 | 22 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 23 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 24 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 25 | 26 | vec4 x1 = x0 - i1 + C.xxxx; 27 | vec4 x2 = x0 - i2 + C.yyyy; 28 | vec4 x3 = x0 - i3 + C.zzzz; 29 | vec4 x4 = x0 + C.wwww; 30 | 31 | i = mod289(i); 32 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 33 | vec4 j1 = permute( permute( permute( permute ( i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 34 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 35 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 36 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 37 | 38 | 39 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 40 | 41 | vec4 p0 = grad4(j0, ip); 42 | vec4 p1 = grad4(j1.x, ip); 43 | vec4 p2 = grad4(j1.y, ip); 44 | vec4 p3 = grad4(j1.z, ip); 45 | vec4 p4 = grad4(j1.w, ip); 46 | 47 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 48 | p0 *= norm.x; 49 | p1 *= norm.y; 50 | p2 *= norm.z; 51 | p3 *= norm.w; 52 | p4 *= taylorInvSqrt(dot(p4,p4)); 53 | 54 | vec3 values0 = vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)); //value of contributions from each corner at point 55 | vec2 values1 = vec2(dot(p3, x3), dot(p4, x4)); 56 | 57 | vec3 m0 = max(0.5 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); //(0.5 - x^2) where x is the distance 58 | vec2 m1 = max(0.5 - vec2(dot(x3,x3), dot(x4,x4)), 0.0); 59 | 60 | vec3 temp0 = -6.0 * m0 * m0 * values0; 61 | vec2 temp1 = -6.0 * m1 * m1 * values1; 62 | 63 | vec3 mmm0 = m0 * m0 * m0; 64 | vec2 mmm1 = m1 * m1 * m1; 65 | 66 | float dx = temp0[0] * x0.x + temp0[1] * x1.x + temp0[2] * x2.x + temp1[0] * x3.x + temp1[1] * x4.x + mmm0[0] * p0.x + mmm0[1] * p1.x + mmm0[2] * p2.x + mmm1[0] * p3.x + mmm1[1] * p4.x; 67 | float dy = temp0[0] * x0.y + temp0[1] * x1.y + temp0[2] * x2.y + temp1[0] * x3.y + temp1[1] * x4.y + mmm0[0] * p0.y + mmm0[1] * p1.y + mmm0[2] * p2.y + mmm1[0] * p3.y + mmm1[1] * p4.y; 68 | float dz = temp0[0] * x0.z + temp0[1] * x1.z + temp0[2] * x2.z + temp1[0] * x3.z + temp1[1] * x4.z + mmm0[0] * p0.z + mmm0[1] * p1.z + mmm0[2] * p2.z + mmm1[0] * p3.z + mmm1[1] * p4.z; 69 | float dw = temp0[0] * x0.w + temp0[1] * x1.w + temp0[2] * x2.w + temp1[0] * x3.w + temp1[1] * x4.w + mmm0[0] * p0.w + mmm0[1] * p1.w + mmm0[2] * p2.w + mmm1[0] * p3.w + mmm1[1] * p4.w; 70 | 71 | return vec4(dx, dy, dz, dw) * 49.0; 72 | } 73 | 74 | 75 | // ------------------------------------------------------------------------------------- 76 | // 77 | vec3 curlNoise( vec3 _p, float _time, int _octaves, float _persistence ) 78 | { 79 | vec4 xNoisePotentialDerivatives = vec4(0.0); 80 | vec4 yNoisePotentialDerivatives = vec4(0.0); 81 | vec4 zNoisePotentialDerivatives = vec4(0.0); 82 | 83 | float tmpPersistence = _persistence; 84 | 85 | for (int i = 0; i < _octaves; ++i) 86 | { 87 | float scale = (1.0 / 2.0) * pow(2.0, float(i)); 88 | 89 | float noiseScale = pow(tmpPersistence, float(i)); 90 | if (tmpPersistence == 0.0 && i == 0) //fix undefined behaviour 91 | { 92 | noiseScale = 1.0; 93 | } 94 | 95 | xNoisePotentialDerivatives += simplexNoiseDerivatives(vec4( _p * pow(2.0, float(i)), _time)) * noiseScale * scale; 96 | yNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(123.4, 129845.6, -1239.1)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 97 | zNoisePotentialDerivatives += simplexNoiseDerivatives(vec4(( _p + vec3(-9519.0, 9051.0, -123.0)) * pow(2.0, float(i)), _time)) * noiseScale * scale; 98 | } 99 | 100 | //compute curl 101 | vec3 curlVal = vec3( zNoisePotentialDerivatives[1] - yNoisePotentialDerivatives[2], 102 | xNoisePotentialDerivatives[2] - zNoisePotentialDerivatives[0], 103 | yNoisePotentialDerivatives[0] - xNoisePotentialDerivatives[1] ); 104 | 105 | 106 | return curlVal; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /shader/Common/ofCommon.glslinc: -------------------------------------------------------------------------------- 1 | in vec4 position; 2 | in vec4 color; 3 | in vec3 normal; 4 | in vec2 texcoord; 5 | 6 | uniform mat4 viewMatrix; 7 | uniform mat4 modelViewMatrix; 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 textureMatrix; 10 | uniform mat4 modelViewProjectionMatrix; 11 | uniform vec4 globalColor = vec4(1); 12 | 13 | uniform float usingTexture; 14 | uniform float usingColors; 15 | uniform float bitmapText; 16 | -------------------------------------------------------------------------------- /shader/passthrough120.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | version: 120 3 | mode: POINTS 4 | count: 1 5 | 6 | geom_count: 1 7 | geom_mode: POINTS 8 | 9 | -- vertex 10 | 11 | uniform float Time = 0; 12 | 13 | void main() 14 | { 15 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 16 | gl_FrontColor = gl_Color; 17 | } 18 | 19 | -- geometry 20 | 21 | void main() 22 | { 23 | gl_FrontColor = gl_FrontColorIn[0]; 24 | gl_Position = gl_PositionIn[0]; 25 | EmitVertex(); 26 | 27 | EndPrimitive(); 28 | } 29 | 30 | -- fragment 31 | 32 | void main() 33 | { 34 | gl_FragColor = gl_Color; 35 | } 36 | -------------------------------------------------------------------------------- /shader/passthrough150.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | version: 150 3 | mode: POINTS 4 | count: 1 5 | 6 | -- vertex 7 | 8 | #pragma include "Common/ofCommon.glslinc" 9 | 10 | uniform float Time = 0; 11 | 12 | out VS { 13 | vec4 color; 14 | } outData; 15 | 16 | void main() 17 | { 18 | gl_Position = modelViewProjectionMatrix * position; 19 | outData.color = (usingColors > 0) ? color : globalColor; 20 | } 21 | 22 | -- geometry 23 | 24 | layout(points) in; 25 | layout(points, max_vertices = 1) out; 26 | 27 | in VS { 28 | vec4 color; 29 | } inData[]; 30 | 31 | out GS { 32 | vec4 color; 33 | } outData; 34 | 35 | void main() 36 | { 37 | gl_Position = gl_in[0].gl_Position; 38 | outData.color = inData[0].color; 39 | EmitVertex(); 40 | 41 | EndPrimitive(); 42 | } 43 | 44 | -- fragment 45 | 46 | // in VS { 47 | // vec4 color; 48 | // } inData; 49 | 50 | in GS { 51 | vec4 color; 52 | } inData; 53 | 54 | out vec4 outColor; 55 | 56 | void main() 57 | { 58 | outColor = inData.color; 59 | } 60 | -------------------------------------------------------------------------------- /shader/passthrough430.glsl: -------------------------------------------------------------------------------- 1 | -- settings 2 | version: 430 3 | mode: POINTS 4 | count: 1 5 | 6 | -- vertex 7 | 8 | #pragma include "Common/ofCommon.glslinc" 9 | 10 | uniform float Time = 0; 11 | 12 | out VS { 13 | vec4 color; 14 | } outData; 15 | 16 | void main() 17 | { 18 | gl_Position = modelViewProjectionMatrix * position; 19 | outData.color = (usingColors > 0) ? color : globalColor; 20 | } 21 | 22 | -- geometry 23 | 24 | layout(points) in; 25 | layout(points, max_vertices = 1) out; 26 | 27 | in VS { 28 | vec4 color; 29 | } inData[]; 30 | 31 | out GS { 32 | vec4 color; 33 | } outData; 34 | 35 | void main() 36 | { 37 | gl_Position = gl_in[0].gl_Position; 38 | outData.color = inData[0].color; 39 | EmitVertex(); 40 | 41 | EndPrimitive(); 42 | } 43 | 44 | -- fragment 45 | 46 | // in VS { 47 | // vec4 color; 48 | // } inData; 49 | 50 | in GS { 51 | vec4 color; 52 | } inData; 53 | 54 | out vec4 outColor; 55 | 56 | void main() 57 | { 58 | outColor = inData.color; 59 | } 60 | -------------------------------------------------------------------------------- /src/ofxShaderRunner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class ofxShaderRunner : public ofShader 12 | { 13 | public: 14 | 15 | struct Arguments { 16 | string vertex; 17 | string fragment; 18 | string geometry; 19 | string compute; 20 | 21 | Arguments() 22 | : vertex("vertex") 23 | , fragment("fragment") 24 | , geometry("geometry") 25 | , compute("compute") 26 | {} 27 | }; 28 | 29 | ~ofxShaderRunner() 30 | { 31 | disableAutoReload(); 32 | } 33 | 34 | bool load(const string& glsl_path, 35 | const Arguments& args = Arguments()) 36 | { 37 | unload(); 38 | this->glsl_path = glsl_path; 39 | 40 | // set dummy vertex 41 | ofVec3f v(0); 42 | vbo.setVertexData(&v, 1, GL_STATIC_DRAW); 43 | 44 | if (ofFile::doesFileExist(glsl_path) == false) 45 | return false; 46 | 47 | this->args = args; 48 | 49 | ofBuffer buf = ofBufferFromFile(glsl_path); 50 | 51 | string tag; 52 | string code; 53 | 54 | codes.clear(); 55 | 56 | int line_no = 0; 57 | 58 | for (auto line : buf.getLines()) 59 | { 60 | if (line.substr(0, 2) == "--") 61 | { 62 | if (tag.empty() == false) 63 | { 64 | setCode(tag, code); 65 | } 66 | 67 | stringstream ss; 68 | ss << line; 69 | ss >> tag >> tag; 70 | 71 | code.clear(); 72 | 73 | code += "#version " + ofToString(version) + "\n"; 74 | code += "#line " + ofToString(line_no) + "\n"; 75 | 76 | if (tag == args.vertex) 77 | { 78 | if (ofGLCheckExtension("GL_EXT_gpu_shader4")) 79 | code += "#extension GL_EXT_gpu_shader4 : require\n"; // for gl_VertexID 80 | } 81 | else if (tag == args.geometry) 82 | { 83 | if (ofGLCheckExtension("GL_EXT_geometry_shader4")) 84 | code += "#extension GL_EXT_geometry_shader4 : enable\n"; 85 | } 86 | else if (tag == args.compute) 87 | { 88 | if (ofGLCheckExtension("GL_ARB_compute_shader")) 89 | code += "#extension GL_ARB_compute_shader : enable\n"; 90 | else throw; 91 | } 92 | } 93 | else 94 | { 95 | code += line + "\n"; 96 | } 97 | 98 | line_no++; 99 | } 100 | 101 | if (tag.empty() == false) 102 | { 103 | setCode(tag, code); 104 | } 105 | 106 | ofShader::setGeometryOutputCount(geom_count); 107 | ofShader::setGeometryInputType(mode); 108 | ofShader::setGeometryOutputType(geom_mode); 109 | 110 | bindDefaults(); 111 | 112 | GLuint clearErrors = glGetError(); 113 | 114 | auto rc = linkProgram(); 115 | glGetProgramiv(getProgram(), GL_LINK_STATUS, &status); 116 | 117 | last_check_time = ofGetElapsedTimeMillis(); 118 | last_modified_time = std::filesystem::last_write_time(ofToDataPath(this->glsl_path)); 119 | 120 | enableAutoReload(); 121 | 122 | return rc; 123 | } 124 | 125 | bool load(const string& glsl_path, 126 | const map& map_args) 127 | { 128 | Arguments args; 129 | 130 | if (map_args.find("vertex") != map_args.end()) 131 | args.vertex = map_args.at("vertex"); 132 | 133 | if (map_args.find("fragment") != map_args.end()) 134 | args.fragment = map_args.at("fragment"); 135 | 136 | if (map_args.find("geometry") != map_args.end()) 137 | args.geometry = map_args.at("geometry"); 138 | 139 | if (map_args.find("compute") != map_args.end()) 140 | args.compute = map_args.at("compute"); 141 | 142 | return load(glsl_path, args); 143 | } 144 | 145 | void setVersion(int version) { this->version = version; } 146 | 147 | void draw() 148 | { 149 | if (status && alpha > 0) 150 | { 151 | ofxShaderRunner::begin(); 152 | vbo.draw(mode, 0, count); 153 | ofxShaderRunner::end(); 154 | } 155 | } 156 | 157 | void begin() 158 | { 159 | if (use_point_size) 160 | { 161 | state.s_GL_PROGRAM_POINT_SIZE = glIsEnabled(GL_PROGRAM_POINT_SIZE); 162 | glEnable(GL_PROGRAM_POINT_SIZE); 163 | } 164 | 165 | ofShader::begin(); 166 | setUniform1f("Time", ofGetElapsedTimef()); 167 | setUniform1f("TimeInc", ofGetLastFrameTime()); 168 | setUniform1f("Alpha", alpha); 169 | } 170 | 171 | void end() 172 | { 173 | ofShader::end(); 174 | 175 | if (use_point_size && state.s_GL_PROGRAM_POINT_SIZE == false) 176 | glDisable(GL_PROGRAM_POINT_SIZE); 177 | } 178 | 179 | void setAlpha(float v) { alpha = v; } 180 | float getAlpha() const { return alpha; } 181 | 182 | void enableAutoReload() 183 | { 184 | if (autoreload) return; 185 | autoreload = true; 186 | 187 | ofAddListener(ofEvents().update, this, &ofxShaderRunner::_update); 188 | } 189 | 190 | void disableAutoReload() 191 | { 192 | if (!autoreload) return; 193 | autoreload = false; 194 | 195 | ofRemoveListener(ofEvents().update, this, &ofxShaderRunner::_update); 196 | } 197 | 198 | ofVbo& getVbo() { return vbo; } 199 | 200 | protected: 201 | 202 | int version = 120; 203 | string glsl_path; 204 | map codes; 205 | 206 | int count = 1; 207 | GLenum mode = GL_POINTS; 208 | int geom_count = 16; 209 | GLenum geom_mode = GL_POINTS; 210 | 211 | GLint status; 212 | 213 | int last_check_time = 0; 214 | bool autoreload = false; 215 | 216 | std::time_t last_modified_time; 217 | 218 | float alpha = 1; 219 | bool use_point_size = false; 220 | 221 | struct EnableState { 222 | bool s_GL_PROGRAM_POINT_SIZE; 223 | } state; 224 | 225 | ofVbo vbo; 226 | 227 | Arguments args; 228 | 229 | void setCode(const string& tag, string code) 230 | { 231 | if (tag == "settings") 232 | { 233 | auto buf = ofBuffer(code); 234 | 235 | for (auto line : buf.getLines()) 236 | { 237 | auto e = ofSplitString(line, ":", false, true); 238 | if (e.size() != 2) 239 | continue; 240 | 241 | if (e[0] == "count") 242 | { 243 | count = std::stoi(e[1]); 244 | } 245 | else if (e[0] == "mode") 246 | { 247 | if (e[1] == "POINTS") 248 | mode = GL_POINTS; 249 | else if (e[1] == "LINES") 250 | mode = GL_LINES; 251 | else if (e[1] == "LINE_STRIP") 252 | mode = GL_LINE_STRIP; 253 | else if (e[1] == "LINE_LOOP") 254 | mode = GL_LINE_LOOP; 255 | else if (e[1] == "TRIANGLES") 256 | mode = GL_TRIANGLES; 257 | else if (e[1] == "TRIANGLE_STRIP") 258 | mode = GL_TRIANGLE_STRIP; 259 | else if (e[1] == "TRIANGLE_FAN") 260 | mode = GL_TRIANGLE_FAN; 261 | else throw; 262 | } 263 | else if (e[0] == "version") 264 | { 265 | version = std::stoi(e[1]); 266 | } 267 | else if (e[0] == "geom_count") 268 | { 269 | geom_count = std::stoi(e[1]); 270 | } 271 | else if (e[0] == "geom_mode") 272 | { 273 | if (e[1] == "POINTS") 274 | geom_mode = GL_POINTS; 275 | else if (e[1] == "LINE_STRIP") 276 | geom_mode = GL_LINE_STRIP; 277 | else if (e[1] == "TRIANGLE_STRIP") 278 | geom_mode = GL_TRIANGLE_STRIP; 279 | else throw; 280 | } 281 | else if (e[0] == "use_point_size") 282 | { 283 | use_point_size = e[1] == "true" || e[1] == "1"; 284 | } 285 | } 286 | } 287 | else if (tag == args.vertex) 288 | { 289 | setupShaderFromSource(GL_VERTEX_SHADER, code); 290 | } 291 | else if (tag == args.fragment) 292 | { 293 | setupShaderFromSource(GL_FRAGMENT_SHADER, code); 294 | } 295 | else if (tag == args.geometry) 296 | { 297 | setupShaderFromSource(GL_GEOMETRY_SHADER, code); 298 | } 299 | else if (tag == args.compute) 300 | { 301 | setupShaderFromSource(GL_COMPUTE_SHADER, code); 302 | } 303 | 304 | codes[tag] = code; 305 | } 306 | 307 | void _update(ofEventArgs &e) 308 | { 309 | auto D = ofGetElapsedTimeMillis() - last_check_time; 310 | if (D > 300) 311 | { 312 | last_check_time = ofGetElapsedTimeMillis(); 313 | 314 | auto T = std::filesystem::last_write_time(ofToDataPath(glsl_path)); 315 | if (last_modified_time != T) 316 | { 317 | load(glsl_path, args); 318 | } 319 | } 320 | } 321 | 322 | public: 323 | 324 | template 325 | struct PingPong { 326 | T buffer[2]; 327 | 328 | T* front; 329 | T* back; 330 | 331 | std::function update; 332 | 333 | PingPong() 334 | : front(&buffer[0]) 335 | , back(&buffer[1]) 336 | {} 337 | 338 | void setup( 339 | std::function init_fn, 340 | std::function update_fn) 341 | { 342 | for (int i = 0; i < 2; i++) 343 | init_fn(buffer[i]); 344 | 345 | update_fn(*front, *back); 346 | 347 | update = update_fn; 348 | } 349 | 350 | void swap() 351 | { 352 | std::swap(front, back); 353 | update(*front, *back); 354 | } 355 | }; 356 | }; 357 | --------------------------------------------------------------------------------