ashton 0.0.1alpha → 0.0.2alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -21
- data/README.md +95 -68
- data/Rakefile +41 -23
- data/examples/bloom_example.rb +59 -0
- data/examples/lighting_example.rb +127 -0
- data/examples/media/SmallStar.png +0 -0
- data/examples/media/Starfighter.png +0 -0
- data/examples/media/simple.png +0 -0
- data/examples/noise_example.rb +94 -0
- data/examples/outline_example.rb +86 -0
- data/examples/particle_emitter_example.rb +114 -0
- data/examples/pixelate_example.rb +51 -49
- data/examples/pixelated_texture_example.rb +69 -0
- data/examples/radial_blur_example.rb +60 -62
- data/examples/shader_image_example.rb +74 -41
- data/examples/{shockwave2_example.rb → shockwave_example.rb} +74 -75
- data/examples/stencil_shader_example.rb +104 -0
- data/examples/{framebuffer_example.rb → texture_render_example.rb} +53 -49
- data/examples/{tv_screen_and_noise_example.rb → tv_screen_and_static_example.rb} +59 -59
- data/ext/ashton/GLee.c +18170 -0
- data/ext/ashton/GLee.h +17647 -0
- data/ext/ashton/ashton.c +42 -0
- data/ext/ashton/ashton.h +31 -0
- data/ext/ashton/color.c +45 -0
- data/ext/ashton/color.h +25 -0
- data/ext/ashton/common.h +41 -0
- data/ext/ashton/extconf.rb +42 -0
- data/ext/ashton/fast_math.c +30 -0
- data/ext/ashton/fast_math.h +30 -0
- data/ext/ashton/font.c +8 -0
- data/ext/ashton/font.h +16 -0
- data/ext/ashton/gosu.c +18 -0
- data/ext/ashton/gosu.h +19 -0
- data/ext/ashton/image.c +8 -0
- data/ext/ashton/image.h +16 -0
- data/ext/ashton/particle_emitter.c +788 -0
- data/ext/ashton/particle_emitter.h +171 -0
- data/ext/ashton/pixel_cache.c +237 -0
- data/ext/ashton/pixel_cache.h +58 -0
- data/ext/ashton/shader.c +9 -0
- data/ext/ashton/shader.h +16 -0
- data/ext/ashton/texture.c +442 -0
- data/ext/ashton/texture.h +63 -0
- data/ext/ashton/window.c +8 -0
- data/ext/ashton/window.h +16 -0
- data/lib/ashton.rb +38 -26
- data/lib/ashton/1.9/ashton.so +0 -0
- data/lib/ashton/gosu_ext/color.rb +24 -11
- data/lib/ashton/gosu_ext/font.rb +58 -0
- data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
- data/lib/ashton/gosu_ext/image.rb +95 -31
- data/lib/ashton/gosu_ext/window.rb +78 -35
- data/lib/ashton/image_stub.rb +32 -36
- data/lib/ashton/lighting/light_source.rb +146 -0
- data/lib/ashton/lighting/manager.rb +98 -0
- data/lib/ashton/mixins/version_checking.rb +23 -0
- data/lib/ashton/particle_emitter.rb +87 -0
- data/lib/ashton/pixel_cache.rb +24 -0
- data/lib/ashton/shader.rb +353 -35
- data/lib/ashton/shaders/bloom.frag +41 -0
- data/lib/ashton/shaders/color_inversion.frag +11 -0
- data/lib/ashton/{post_process → shaders}/contrast.frag +16 -16
- data/lib/ashton/{shader → shaders}/default.frag +22 -19
- data/lib/ashton/{shader → shaders}/default.vert +13 -13
- data/lib/ashton/shaders/fade.frag +14 -0
- data/lib/ashton/shaders/grayscale.frag +15 -0
- data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
- data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
- data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
- data/lib/ashton/{include/simplex.glsl → shaders/include/noise2d.glsl} +70 -63
- data/lib/ashton/shaders/include/noise3d.glsl +102 -0
- data/lib/ashton/shaders/include/noise4d.glsl +128 -0
- data/lib/ashton/shaders/include/rand.glsl +5 -0
- data/lib/ashton/shaders/lighting/distort.frag +57 -0
- data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
- data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
- data/lib/ashton/shaders/mezzotint.frag +22 -0
- data/lib/ashton/shaders/multitexture2.vert +19 -0
- data/lib/ashton/shaders/outline.frag +45 -0
- data/lib/ashton/{post_process → shaders}/pixelate.frag +48 -48
- data/lib/ashton/shaders/radial_blur.frag +63 -0
- data/lib/ashton/shaders/sepia.frag +26 -0
- data/lib/ashton/{post_process/shockwave2.frag → shaders/shockwave.frag} +38 -35
- data/lib/ashton/shaders/signed_distance_field.frag +80 -0
- data/lib/ashton/{post_process/noise.frag → shaders/static.frag} +25 -27
- data/lib/ashton/shaders/stencil.frag +27 -0
- data/lib/ashton/shaders/tv_screen.frag +23 -0
- data/lib/ashton/signed_distance_field.rb +151 -0
- data/lib/ashton/texture.rb +186 -0
- data/lib/ashton/version.rb +2 -2
- data/lib/ashton/window_buffer.rb +16 -0
- data/spec/ashton/ashton_spec.rb +22 -0
- data/spec/ashton/gosu_ext/color_spec.rb +34 -0
- data/spec/ashton/gosu_ext/font_spec.rb +57 -0
- data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
- data/spec/ashton/gosu_ext/image_spec.rb +66 -0
- data/spec/ashton/gosu_ext/window_spec.rb +71 -0
- data/spec/ashton/image_stub_spec.rb +46 -0
- data/spec/ashton/particle_emitter_spec.rb +123 -0
- data/spec/ashton/pixel_cache_spec.rb +153 -0
- data/spec/ashton/shader_spec.rb +152 -0
- data/spec/ashton/signed_distance_field_spec.rb +163 -0
- data/spec/ashton/texture_spec.rb +347 -0
- data/spec/helper.rb +12 -0
- metadata +159 -28
- data/examples/output/README.txt +0 -1
- data/lib/ashton/base_shader.rb +0 -172
- data/lib/ashton/framebuffer.rb +0 -183
- data/lib/ashton/post_process.rb +0 -83
- data/lib/ashton/post_process/default.vert +0 -9
- data/lib/ashton/post_process/fade.frag +0 -11
- data/lib/ashton/post_process/mezzotint.frag +0 -24
- data/lib/ashton/post_process/radial_blur.frag +0 -31
- data/lib/ashton/post_process/sepia.frag +0 -19
- data/lib/ashton/post_process/shockwave.frag +0 -40
- data/lib/ashton/post_process/tv_screen.frag +0 -32
|
@@ -1,63 +1,70 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
vec3
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
vec3
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
vec3
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
vec3 mod289(vec3 x) {
|
|
12
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
vec2 mod289(vec2 x) {
|
|
16
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
vec3 permute(vec3 x) {
|
|
20
|
+
return mod289(((x*34.0)+1.0)*x);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
float snoise(vec2 v)
|
|
24
|
+
{
|
|
25
|
+
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
|
|
26
|
+
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
|
|
27
|
+
-0.577350269189626, // -1.0 + 2.0 * C.x
|
|
28
|
+
0.024390243902439); // 1.0 / 41.0
|
|
29
|
+
// First corner
|
|
30
|
+
vec2 i = floor(v + dot(v, C.yy) );
|
|
31
|
+
vec2 x0 = v - i + dot(i, C.xx);
|
|
32
|
+
|
|
33
|
+
// Other corners
|
|
34
|
+
vec2 i1;
|
|
35
|
+
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
|
|
36
|
+
//i1.y = 1.0 - i1.x;
|
|
37
|
+
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
|
38
|
+
// x0 = x0 - 0.0 + 0.0 * C.xx ;
|
|
39
|
+
// x1 = x0 - i1 + 1.0 * C.xx ;
|
|
40
|
+
// x2 = x0 - 1.0 + 2.0 * C.xx ;
|
|
41
|
+
vec4 x12 = x0.xyxy + C.xxzz;
|
|
42
|
+
x12.xy -= i1;
|
|
43
|
+
|
|
44
|
+
// Permutations
|
|
45
|
+
i = mod289(i); // Avoid truncation effects in permutation
|
|
46
|
+
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
|
|
47
|
+
+ i.x + vec3(0.0, i1.x, 1.0 ));
|
|
48
|
+
|
|
49
|
+
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
|
|
50
|
+
m = m*m ;
|
|
51
|
+
m = m*m ;
|
|
52
|
+
|
|
53
|
+
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
|
|
54
|
+
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
|
|
55
|
+
|
|
56
|
+
vec3 x = 2.0 * fract(p * C.www) - 1.0;
|
|
57
|
+
vec3 h = abs(x) - 0.5;
|
|
58
|
+
vec3 ox = floor(x + 0.5);
|
|
59
|
+
vec3 a0 = x - ox;
|
|
60
|
+
|
|
61
|
+
// Normalise gradients implicitly by scaling m
|
|
62
|
+
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
|
|
63
|
+
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
|
|
64
|
+
|
|
65
|
+
// Compute final noise value at P
|
|
66
|
+
vec3 g;
|
|
67
|
+
g.x = a0.x * x0.x + h.x * x0.y;
|
|
68
|
+
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
|
|
69
|
+
return 130.0 * dot(m, g);
|
|
70
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
vec3 mod289(vec3 x) {
|
|
13
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
vec4 mod289(vec4 x) {
|
|
17
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
vec4 permute(vec4 x) {
|
|
21
|
+
return mod289(((x*34.0)+1.0)*x);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
vec4 taylorInvSqrt(vec4 r)
|
|
25
|
+
{
|
|
26
|
+
return 1.79284291400159 - 0.85373472095314 * r;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
float snoise(vec3 v)
|
|
30
|
+
{
|
|
31
|
+
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
|
|
32
|
+
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
|
|
33
|
+
|
|
34
|
+
// First corner
|
|
35
|
+
vec3 i = floor(v + dot(v, C.yyy) );
|
|
36
|
+
vec3 x0 = v - i + dot(i, C.xxx) ;
|
|
37
|
+
|
|
38
|
+
// Other corners
|
|
39
|
+
vec3 g = step(x0.yzx, x0.xyz);
|
|
40
|
+
vec3 l = 1.0 - g;
|
|
41
|
+
vec3 i1 = min( g.xyz, l.zxy );
|
|
42
|
+
vec3 i2 = max( g.xyz, l.zxy );
|
|
43
|
+
|
|
44
|
+
// x0 = x0 - 0.0 + 0.0 * C.xxx;
|
|
45
|
+
// x1 = x0 - i1 + 1.0 * C.xxx;
|
|
46
|
+
// x2 = x0 - i2 + 2.0 * C.xxx;
|
|
47
|
+
// x3 = x0 - 1.0 + 3.0 * C.xxx;
|
|
48
|
+
vec3 x1 = x0 - i1 + C.xxx;
|
|
49
|
+
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
|
|
50
|
+
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
|
|
51
|
+
|
|
52
|
+
// Permutations
|
|
53
|
+
i = mod289(i);
|
|
54
|
+
vec4 p = permute( permute( permute(
|
|
55
|
+
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
|
|
56
|
+
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
|
|
57
|
+
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
|
|
58
|
+
|
|
59
|
+
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
|
60
|
+
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
|
61
|
+
float n_ = 0.142857142857; // 1.0/7.0
|
|
62
|
+
vec3 ns = n_ * D.wyz - D.xzx;
|
|
63
|
+
|
|
64
|
+
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
|
|
65
|
+
|
|
66
|
+
vec4 x_ = floor(j * ns.z);
|
|
67
|
+
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
|
|
68
|
+
|
|
69
|
+
vec4 x = x_ *ns.x + ns.yyyy;
|
|
70
|
+
vec4 y = y_ *ns.x + ns.yyyy;
|
|
71
|
+
vec4 h = 1.0 - abs(x) - abs(y);
|
|
72
|
+
|
|
73
|
+
vec4 b0 = vec4( x.xy, y.xy );
|
|
74
|
+
vec4 b1 = vec4( x.zw, y.zw );
|
|
75
|
+
|
|
76
|
+
//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
|
|
77
|
+
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
|
|
78
|
+
vec4 s0 = floor(b0)*2.0 + 1.0;
|
|
79
|
+
vec4 s1 = floor(b1)*2.0 + 1.0;
|
|
80
|
+
vec4 sh = -step(h, vec4(0.0));
|
|
81
|
+
|
|
82
|
+
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
|
|
83
|
+
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
|
|
84
|
+
|
|
85
|
+
vec3 p0 = vec3(a0.xy,h.x);
|
|
86
|
+
vec3 p1 = vec3(a0.zw,h.y);
|
|
87
|
+
vec3 p2 = vec3(a1.xy,h.z);
|
|
88
|
+
vec3 p3 = vec3(a1.zw,h.w);
|
|
89
|
+
|
|
90
|
+
//Normalise gradients
|
|
91
|
+
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
|
92
|
+
p0 *= norm.x;
|
|
93
|
+
p1 *= norm.y;
|
|
94
|
+
p2 *= norm.z;
|
|
95
|
+
p3 *= norm.w;
|
|
96
|
+
|
|
97
|
+
// Mix final noise value
|
|
98
|
+
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
|
|
99
|
+
m = m * m;
|
|
100
|
+
return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
|
|
101
|
+
dot(p2,x2), dot(p3,x3) ) );
|
|
102
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
vec4 mod289(vec4 x) {
|
|
13
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
|
14
|
+
|
|
15
|
+
float mod289(float x) {
|
|
16
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
|
17
|
+
|
|
18
|
+
vec4 permute(vec4 x) {
|
|
19
|
+
return mod289(((x*34.0)+1.0)*x);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
float permute(float x) {
|
|
23
|
+
return mod289(((x*34.0)+1.0)*x);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
vec4 taylorInvSqrt(vec4 r)
|
|
27
|
+
{
|
|
28
|
+
return 1.79284291400159 - 0.85373472095314 * r;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
float taylorInvSqrt(float r)
|
|
32
|
+
{
|
|
33
|
+
return 1.79284291400159 - 0.85373472095314 * r;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
vec4 grad4(float j, vec4 ip)
|
|
37
|
+
{
|
|
38
|
+
const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
|
|
39
|
+
vec4 p,s;
|
|
40
|
+
|
|
41
|
+
p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
|
|
42
|
+
p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
|
|
43
|
+
s = vec4(lessThan(p, vec4(0.0)));
|
|
44
|
+
p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;
|
|
45
|
+
|
|
46
|
+
return p;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// (sqrt(5) - 1)/4 = F4, used once below
|
|
50
|
+
#define F4 0.309016994374947451
|
|
51
|
+
|
|
52
|
+
float snoise(vec4 v)
|
|
53
|
+
{
|
|
54
|
+
const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4
|
|
55
|
+
0.276393202250021, // 2 * G4
|
|
56
|
+
0.414589803375032, // 3 * G4
|
|
57
|
+
-0.447213595499958); // -1 + 4 * G4
|
|
58
|
+
|
|
59
|
+
// First corner
|
|
60
|
+
vec4 i = floor(v + dot(v, vec4(F4)) );
|
|
61
|
+
vec4 x0 = v - i + dot(i, C.xxxx);
|
|
62
|
+
|
|
63
|
+
// Other corners
|
|
64
|
+
|
|
65
|
+
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
|
|
66
|
+
vec4 i0;
|
|
67
|
+
vec3 isX = step( x0.yzw, x0.xxx );
|
|
68
|
+
vec3 isYZ = step( x0.zww, x0.yyz );
|
|
69
|
+
// i0.x = dot( isX, vec3( 1.0 ) );
|
|
70
|
+
i0.x = isX.x + isX.y + isX.z;
|
|
71
|
+
i0.yzw = 1.0 - isX;
|
|
72
|
+
// i0.y += dot( isYZ.xy, vec2( 1.0 ) );
|
|
73
|
+
i0.y += isYZ.x + isYZ.y;
|
|
74
|
+
i0.zw += 1.0 - isYZ.xy;
|
|
75
|
+
i0.z += isYZ.z;
|
|
76
|
+
i0.w += 1.0 - isYZ.z;
|
|
77
|
+
|
|
78
|
+
// i0 now contains the unique values 0,1,2,3 in each channel
|
|
79
|
+
vec4 i3 = clamp( i0, 0.0, 1.0 );
|
|
80
|
+
vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
|
|
81
|
+
vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
|
|
82
|
+
|
|
83
|
+
// x0 = x0 - 0.0 + 0.0 * C.xxxx
|
|
84
|
+
// x1 = x0 - i1 + 1.0 * C.xxxx
|
|
85
|
+
// x2 = x0 - i2 + 2.0 * C.xxxx
|
|
86
|
+
// x3 = x0 - i3 + 3.0 * C.xxxx
|
|
87
|
+
// x4 = x0 - 1.0 + 4.0 * C.xxxx
|
|
88
|
+
vec4 x1 = x0 - i1 + C.xxxx;
|
|
89
|
+
vec4 x2 = x0 - i2 + C.yyyy;
|
|
90
|
+
vec4 x3 = x0 - i3 + C.zzzz;
|
|
91
|
+
vec4 x4 = x0 + C.wwww;
|
|
92
|
+
|
|
93
|
+
// Permutations
|
|
94
|
+
i = mod289(i);
|
|
95
|
+
float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x);
|
|
96
|
+
vec4 j1 = permute( permute( permute( permute (
|
|
97
|
+
i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
|
|
98
|
+
+ i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
|
|
99
|
+
+ i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
|
|
100
|
+
+ i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));
|
|
101
|
+
|
|
102
|
+
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
|
|
103
|
+
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
|
|
104
|
+
vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;
|
|
105
|
+
|
|
106
|
+
vec4 p0 = grad4(j0, ip);
|
|
107
|
+
vec4 p1 = grad4(j1.x, ip);
|
|
108
|
+
vec4 p2 = grad4(j1.y, ip);
|
|
109
|
+
vec4 p3 = grad4(j1.z, ip);
|
|
110
|
+
vec4 p4 = grad4(j1.w, ip);
|
|
111
|
+
|
|
112
|
+
// Normalise gradients
|
|
113
|
+
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
|
114
|
+
p0 *= norm.x;
|
|
115
|
+
p1 *= norm.y;
|
|
116
|
+
p2 *= norm.z;
|
|
117
|
+
p3 *= norm.w;
|
|
118
|
+
p4 *= taylorInvSqrt(dot(p4,p4));
|
|
119
|
+
|
|
120
|
+
// Mix contributions from the five corners
|
|
121
|
+
vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
|
|
122
|
+
vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
|
|
123
|
+
m0 = m0 * m0;
|
|
124
|
+
m1 = m1 * m1;
|
|
125
|
+
return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
|
|
126
|
+
+ dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
|
|
127
|
+
|
|
128
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#version 110
|
|
2
|
+
|
|
3
|
+
// Based on Catalin Zima's shader based dynamic shadows system.
|
|
4
|
+
// http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/
|
|
5
|
+
|
|
6
|
+
// Distort the input (square) texture into sight-lines, then reduce horizontally into a 2-pixel wide shadow-map texture.
|
|
7
|
+
|
|
8
|
+
const float MIN_ALPHA_TO_CAST_SHADOW = 0.3; // Ignore mostly transparent pixels.
|
|
9
|
+
|
|
10
|
+
uniform sampler2D in_Texture; // Texture containing shadow-casting shapes.
|
|
11
|
+
uniform int in_TextureWidth; // Texture must be square, but can be any size divisible by 2.
|
|
12
|
+
|
|
13
|
+
varying vec2 var_TexCoord; // Pixel to process on this pass.
|
|
14
|
+
|
|
15
|
+
vec4 distort(in vec2 coord)
|
|
16
|
+
{
|
|
17
|
+
// Translate u and v into [-1 , 1] domain
|
|
18
|
+
float u0 = coord.x * 2.0 - 1.0;
|
|
19
|
+
float v0 = (1.0 - coord.y) * 2.0 - 1.0; // Inverted because Gosu Y-coordinate is "inverted".
|
|
20
|
+
|
|
21
|
+
// Then, as u0 approaches 0 (the center), v should also approach 0
|
|
22
|
+
v0 = v0 * abs(u0);
|
|
23
|
+
|
|
24
|
+
// Convert back from [-1,1] domain to [0,1] domain
|
|
25
|
+
v0 = (v0 + 1.0) / 2.0;
|
|
26
|
+
|
|
27
|
+
v0 = 1.0 - v0;
|
|
28
|
+
|
|
29
|
+
// We now have the coordinates for reading from the initial image
|
|
30
|
+
vec2 newCoords = vec2(coord.x, v0);
|
|
31
|
+
|
|
32
|
+
// Read for both horizontal and vertical direction and store them in separate channels
|
|
33
|
+
float horizontal = texture2D(in_Texture, newCoords).a;
|
|
34
|
+
float distanceH = (horizontal > MIN_ALPHA_TO_CAST_SHADOW ? length(newCoords - 0.5) : 1.0);
|
|
35
|
+
|
|
36
|
+
float vertical = texture2D(in_Texture, newCoords.yx).a;
|
|
37
|
+
float distanceV = (vertical > MIN_ALPHA_TO_CAST_SHADOW ? length(newCoords - 0.5) : 1.0);
|
|
38
|
+
|
|
39
|
+
return vec4(distanceH, distanceV, 0.0, 1.0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void main()
|
|
43
|
+
{
|
|
44
|
+
float pixel_width = 1.0 / float(in_TextureWidth);
|
|
45
|
+
int half_width = in_TextureWidth / 2;
|
|
46
|
+
|
|
47
|
+
// Get the left-most pixel.
|
|
48
|
+
gl_FragColor = distort(var_TexCoord);
|
|
49
|
+
|
|
50
|
+
// Grab each pixel to the right in turn and min it with the previous one.
|
|
51
|
+
for(int i = 1; i < half_width; i++)
|
|
52
|
+
{
|
|
53
|
+
vec2 color = distort(var_TexCoord + vec2(pixel_width * float(i), 0)).rg;
|
|
54
|
+
|
|
55
|
+
gl_FragColor.rg = min(gl_FragColor.rg, color.rg);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#version 110
|
|
2
|
+
|
|
3
|
+
// Based on Catalin Zima's shader based dynamic shadows system.
|
|
4
|
+
// http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/
|
|
5
|
+
|
|
6
|
+
uniform sampler2D in_Texture; // Shadow map texture.
|
|
7
|
+
|
|
8
|
+
uniform int in_TextureWidth;
|
|
9
|
+
|
|
10
|
+
varying vec2 var_TexCoord; // Pixel to process on this pass.
|
|
11
|
+
|
|
12
|
+
// coord x and y should be inverted when reading vertical distortion.
|
|
13
|
+
vec4 GetShadowDistances(in vec2 coord)
|
|
14
|
+
{
|
|
15
|
+
float u = coord.x;
|
|
16
|
+
float v = coord.y;
|
|
17
|
+
|
|
18
|
+
u = abs(u - 0.5) * 2.0;
|
|
19
|
+
v = v * 2.0 - 1.0;
|
|
20
|
+
float v0 = v / u;
|
|
21
|
+
v0 = (v0 + 1.0) / 2.0;
|
|
22
|
+
|
|
23
|
+
vec2 newCoords = vec2(coord.x, v0);
|
|
24
|
+
|
|
25
|
+
return texture2D(in_Texture, newCoords);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void main()
|
|
29
|
+
{
|
|
30
|
+
// Distance of this pixel from the center.
|
|
31
|
+
float distance = length(var_TexCoord - 0.5);
|
|
32
|
+
|
|
33
|
+
// Apply a 2-pixel bias, so we can see the edge of shadow-caster.
|
|
34
|
+
distance -= 2.0 / float(in_TextureWidth);
|
|
35
|
+
|
|
36
|
+
//distance stored in the shadow map
|
|
37
|
+
float shadowMapDistance;
|
|
38
|
+
|
|
39
|
+
// Coords in [-1,1]
|
|
40
|
+
float nY = 2.0 * (var_TexCoord.y - 0.5);
|
|
41
|
+
float nX = 2.0 * (var_TexCoord.x - 0.5);
|
|
42
|
+
|
|
43
|
+
// We use these to determine which quadrant we are in.
|
|
44
|
+
if(abs(nY) < abs(nX))
|
|
45
|
+
{
|
|
46
|
+
// Horizontal distance was stored in the Red component.
|
|
47
|
+
shadowMapDistance = GetShadowDistances(var_TexCoord).r;
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
{
|
|
51
|
+
// Vertical distance was stored in the Green component.
|
|
52
|
+
shadowMapDistance = GetShadowDistances(var_TexCoord.yx).g;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If distance to this pixel is lower than distance from shadowMap,
|
|
56
|
+
// then we are not in shadow.
|
|
57
|
+
float light = (distance < shadowMapDistance) ? 1.0 : 0.0;
|
|
58
|
+
|
|
59
|
+
gl_FragColor = vec4(vec2(light), length(var_TexCoord - 0.5), 1.0);
|
|
60
|
+
}
|