ashton 0.0.1alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG +0 -0
  2. data/LICENSE +21 -0
  3. data/README.md +68 -0
  4. data/Rakefile +24 -0
  5. data/examples/framebuffer_example.rb +50 -0
  6. data/examples/media/Earth.png +0 -0
  7. data/examples/media/LargeStar.png +0 -0
  8. data/examples/media/Star.png +0 -0
  9. data/examples/media/Starfighter.bmp +0 -0
  10. data/examples/media/simple.png +0 -0
  11. data/examples/output/README.txt +1 -0
  12. data/examples/pixelate_example.rb +50 -0
  13. data/examples/radial_blur_example.rb +63 -0
  14. data/examples/shader_image_example.rb +42 -0
  15. data/examples/shockwave2_example.rb +76 -0
  16. data/examples/tv_screen_and_noise_example.rb +60 -0
  17. data/lib/ashton/base_shader.rb +172 -0
  18. data/lib/ashton/framebuffer.rb +183 -0
  19. data/lib/ashton/gosu_ext/color.rb +12 -0
  20. data/lib/ashton/gosu_ext/image.rb +32 -0
  21. data/lib/ashton/gosu_ext/window.rb +36 -0
  22. data/lib/ashton/image_stub.rb +37 -0
  23. data/lib/ashton/include/simplex.glsl +63 -0
  24. data/lib/ashton/post_process/contrast.frag +16 -0
  25. data/lib/ashton/post_process/default.vert +9 -0
  26. data/lib/ashton/post_process/fade.frag +11 -0
  27. data/lib/ashton/post_process/mezzotint.frag +24 -0
  28. data/lib/ashton/post_process/noise.frag +27 -0
  29. data/lib/ashton/post_process/pixelate.frag +48 -0
  30. data/lib/ashton/post_process/radial_blur.frag +31 -0
  31. data/lib/ashton/post_process/sepia.frag +19 -0
  32. data/lib/ashton/post_process/shockwave.frag +40 -0
  33. data/lib/ashton/post_process/shockwave2.frag +35 -0
  34. data/lib/ashton/post_process/tv_screen.frag +32 -0
  35. data/lib/ashton/post_process.rb +83 -0
  36. data/lib/ashton/shader/default.frag +19 -0
  37. data/lib/ashton/shader/default.vert +14 -0
  38. data/lib/ashton/shader.rb +62 -0
  39. data/lib/ashton/version.rb +3 -0
  40. data/lib/ashton.rb +26 -0
  41. metadata +201 -0
@@ -0,0 +1,183 @@
1
+ module Ashton
2
+ class Framebuffer
3
+ TEXTURE_COORDINATES = [
4
+ [0, 1], # TL
5
+ [0, 0], # BL
6
+ [1, 0], # TR
7
+ [1, 1], # BR
8
+ ]
9
+
10
+ TEXTURE_COORDINATES_FLIPPED = [
11
+ [0, 0], # BL
12
+ [0, 1], # TL
13
+ [1, 1], # BR
14
+ [1, 0], # TR
15
+ ]
16
+
17
+ attr_reader :width, :height, :texture
18
+
19
+ def initialize(width, height)
20
+ @width, @height = width.to_i, height.to_i
21
+ @fbo, @texture = init_framebuffer
22
+
23
+ status = glCheckFramebufferStatusEXT GL_FRAMEBUFFER_EXT
24
+ raise unless status == GL_FRAMEBUFFER_COMPLETE_EXT
25
+
26
+ clear
27
+
28
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
29
+ glBindRenderbufferEXT GL_RENDERBUFFER_EXT, 0
30
+ end
31
+
32
+ # Clears the buffer to transparent.
33
+ def clear(options = {})
34
+ options = {
35
+ color: [0.0, 0.0, 0.0, 0.0],
36
+ }.merge! options
37
+
38
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, @fbo
39
+
40
+ glClearColor *options[:color]
41
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
42
+
43
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
44
+ end
45
+
46
+ # Enable the framebuffer to use (e.g. to draw or convert it).
47
+ # BUG: This will force all draws performed in, AND BEFORE, the block!
48
+ def use
49
+ raise ArgumentError, "block required" unless block_given?
50
+
51
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, @fbo
52
+ result = yield self
53
+
54
+ $window.flush
55
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
56
+
57
+ result
58
+ end
59
+
60
+ # Draw the image, _immediately_ (no z-ordering by Gosu).
61
+ #
62
+ # This is not as versatile as converting the Framebuffer into a Gosu::Image and then
63
+ # drawing it, but it is many times faster, so use it when you are updating the buffer
64
+ # every frame, rather than just composing an image.
65
+ #
66
+ # Drawing in Gosu orientation will be flipped in standard OpenGL and visa versa.
67
+ #
68
+ # @param x [Number]
69
+ # @param y [Number]
70
+ # @option options :orientation [:gosu, :opengl] (:gosu)
71
+ def draw x, y, options = {}
72
+ options = {
73
+ :orientation => :gosu,
74
+ }.merge! options
75
+
76
+ glEnable GL_TEXTURE_2D
77
+ glBindTexture GL_TEXTURE_2D, @texture
78
+
79
+ coords = case options[:orientation]
80
+ when :gosu then TEXTURE_COORDINATES_FLIPPED
81
+ when :opengl then TEXTURE_COORDINATES
82
+ else raise ArgumentError, ":orientation option expected to be either :opengl or :gosu"
83
+ end
84
+
85
+ glBegin GL_QUADS do
86
+ glTexCoord2d *coords[0]
87
+ glVertex2d x, y + @height # BL
88
+
89
+ glTexCoord2d *coords[1]
90
+ glVertex2d x, y # TL
91
+
92
+ glTexCoord2d *coords[2]
93
+ glVertex2d x + @width, y # TR
94
+
95
+ glTexCoord2d *coords[3]
96
+ glVertex2d x + @width, y + @height # BR
97
+ end
98
+
99
+ glBindTexture GL_TEXTURE_2D, 0
100
+ end
101
+
102
+ # Convert the current contents of the buffer into a Gosu::Image
103
+ #
104
+ # @option options [Boolean] :caching (true) TexPlay behaviour.
105
+ # @option options [Boolean] :tileable (false) Standard Gosu behaviour.
106
+ # @option options [Array<Integer>] :rect ([0, 0, width, height]) Rectangular area of buffer to use to create the image [x, y, w, h]
107
+ def to_image(options = {})
108
+ options = {
109
+ rect: [0, 0, @width, @height],
110
+ tileable: false,
111
+ }.merge! options
112
+
113
+ rect = options[:rect]
114
+
115
+ # Draw onto the clean flip buffer, in order to flip before saving.
116
+ @fbo_flip, @fbo_flip_texture = init_framebuffer unless defined? @fbo_flip
117
+
118
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, @fbo_flip
119
+ glClearColor 0, 0, 0, 0
120
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
121
+ draw 0, 0
122
+
123
+ # Read the data in the flip-buffer.
124
+ glBindTexture GL_TEXTURE_2D, @fbo_flip_texture
125
+ blob = glReadPixels *rect, GL_RGBA, GL_UNSIGNED_BYTE
126
+
127
+ # Clean up.
128
+ glBindTexture GL_TEXTURE_2D, 0
129
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
130
+
131
+ # Create a new Image from the flipped pixel data.
132
+ stub = ImageStub.new blob, rect[2], rect[3]
133
+ if defined? TexPlay
134
+ Gosu::Image.new $window, stub, options[:tileable], options
135
+ else
136
+ Gosu::Image.new $window, stub, options[:tileable]
137
+ end
138
+
139
+ end
140
+
141
+ # Create an fbo and its texture
142
+ def init_framebuffer
143
+ fbo = glGenFramebuffersEXT(1)[0]
144
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, fbo
145
+
146
+ texture = init_framebuffer_texture
147
+
148
+ glFramebufferTexture2DEXT GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0
149
+
150
+ [fbo, texture]
151
+ end
152
+
153
+ protected
154
+ # Called by init_framebuffer.
155
+ def init_framebuffer_texture
156
+ texture = glGenTextures(1)[0]
157
+ glBindTexture GL_TEXTURE_2D, texture
158
+
159
+ glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
160
+ glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
161
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST
162
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST
163
+
164
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA8, @width, @height,
165
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, nil
166
+
167
+ glBindTexture GL_TEXTURE_2D, 0 # Unbind the texture
168
+
169
+ texture
170
+ end
171
+
172
+ protected
173
+ def delete
174
+ glDeleteFramebuffersEXT @fbo
175
+ glDeleteTextures @texture
176
+
177
+ glDeleteFramebuffersEXT @fbo_flip if defined? @fbo_flip
178
+ glDeleteTextures @fbo_flip_texture if defined? @fbo_flip_texture
179
+
180
+ glBindFramebufferEXT GL_FRAMEBUFFER_EXT, 0
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,12 @@
1
+ module Gosu
2
+ class Color
3
+ def self.from_opengl(array)
4
+ rgba *array.map {|c| (c * 255).to_i }
5
+ end
6
+
7
+ # Convert to length 4 array of floats in range 0.0 to 1.0
8
+ def to_opengl
9
+ [red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ module Gosu
2
+ class Image
3
+ alias_method :draw_without_hash, :draw
4
+
5
+ def draw(*args)
6
+ if args.last.is_a? Hash
7
+ shader = args.last[:shader]
8
+ shader.use do
9
+ shader.image = self
10
+ shader.color = args[5].is_a?(Color) ? args[5] : [1, 1, 1, 1]
11
+ draw_without_hash *args[0...-1]
12
+ end
13
+ else
14
+ draw_without_hash *args
15
+ end
16
+ end
17
+
18
+ alias_method :draw_rot_without_hash, :draw_rot
19
+ def draw_rot(*args)
20
+ if args.last.is_a? Hash
21
+ shader = args.last[:shader]
22
+ shader.use do
23
+ shader.image = self
24
+ shader.color = args[8].is_a?(Color) ? args[8] : [1, 1, 1, 1]
25
+ draw_rot_without_hash *args[0...-1]
26
+ end
27
+ else
28
+ draw_rot_without_hash *args
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # Set the window global, in case it hasn't been set (e.g. by Chingu)
2
+ module Gosu
3
+ class Window
4
+ class << self
5
+ # Used for post-processing effects.
6
+ attr_accessor :back_buffer
7
+ end
8
+
9
+ alias_method :ashton_initialize, :initialize
10
+ def initialize(*args, &block)
11
+ $window = self
12
+ ashton_initialize *args, &block
13
+ end
14
+
15
+ # TODO: accept multiple shaders.
16
+ def post_process(shader)
17
+ raise ArgumentError, "Block required" unless block_given?
18
+
19
+ Window.back_buffer ||= Ashton::Framebuffer.new width, height
20
+
21
+ buffer = Window.back_buffer
22
+ buffer.clear
23
+
24
+ # allow drawing into the back-buffer.
25
+ buffer.use do
26
+ yield
27
+ end
28
+
29
+ # Draw the back-buffer onto the window, utilising the shader.
30
+ shader.use do
31
+ shader["in_Texture"] = 0
32
+ buffer.draw 0, 0
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ module Ashton
2
+ # Used internally to create images from raw binary (blob) data.
3
+ #
4
+ # This object duck-types an RMagick image (#rows, #columns, #to_blob), so that Gosu will import it.
5
+ class ImageStub
6
+
7
+ # @return [Integer]
8
+ attr_reader :rows, :columns
9
+
10
+ # The first pixel in the blob will be at the top left hand corner of the created image, since that is the orientation
11
+ # of Gosu images.
12
+ #
13
+ # @param [String] blob_data Raw data string to import. Must be RGBA ordered, (4 * width * height) bytes in length.
14
+ # @param [Integer] width Number of pixels wide.
15
+ # @param [Integer] height Number of pixels high.
16
+ def initialize(blob_data, width, height)
17
+ @data, @columns, @rows = blob_data, width, height
18
+ end
19
+
20
+ # @return [String]
21
+ def to_blob
22
+ @data
23
+ end
24
+ end
25
+
26
+ # Used internally to create blank images (red/blue/green/alpha all 0).
27
+ #
28
+ # Credit to philomory for this class.
29
+ class EmptyImageStub < ImageStub
30
+ # @param width (see ImageStub#initialize)
31
+ # @param height (see ImageStub#initialize)
32
+ def initialize(width, height)
33
+ #raise ArgumentError if (width > TexPlay::TP_MAX_QUAD_SIZE || height > TexPlay::TP_MAX_QUAD_SIZE)
34
+ super('\0' * (width * height * 4), width, height)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ // -----------------------------------
2
+ //
3
+ // Description : Array and textureless GLSL 2D simplex noise function.
4
+ // Author : Ian McEwan, Ashima Arts.
5
+ // Maintainer : ijm
6
+ // Lastmod : 20110410 (stegu)
7
+ // License : Copyright (C) 2011 Ashima Arts. All rights reserved.
8
+ // Distributed under the MIT License. See LICENSE file.
9
+ //
10
+
11
+ vec3 permute(vec3 x)
12
+ {
13
+ return mod(((x*34.0)+1.0)*x, 289.0);
14
+ }
15
+
16
+ float snoise(vec2 v)
17
+ {
18
+ const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
19
+ 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
20
+ -0.577350269189626, // -1.0 + 2.0 * C.x
21
+ 0.024390243902439); // 1.0 / 41.0
22
+ // First corner
23
+ vec2 i = floor(v + dot(v, C.yy) );
24
+ vec2 x0 = v - i + dot(i, C.xx);
25
+
26
+ // Other corners
27
+ vec2 i1;
28
+ //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
29
+ //i1.y = 1.0 - i1.x;
30
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
31
+ // x0 = x0 - 0.0 + 0.0 * C.xx ;
32
+ // x1 = x0 - i1 + 1.0 * C.xx ;
33
+ // x2 = x0 - 1.0 + 2.0 * C.xx ;
34
+ vec4 x12 = x0.xyxy + C.xxzz;
35
+ x12.xy -= i1;
36
+
37
+ // Permutations
38
+ i = mod(i, 289.0); // Avoid truncation effects in permutation
39
+ vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
40
+ + i.x + vec3(0.0, i1.x, 1.0 ));
41
+
42
+ vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
43
+ m = m*m ;
44
+ m = m*m ;
45
+
46
+ // Gradients: 41 points uniformly over a line, mapped onto a diamond.
47
+ // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
48
+
49
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
50
+ vec3 h = abs(x) - 0.5;
51
+ vec3 ox = floor(x + 0.5);
52
+ vec3 a0 = x - ox;
53
+
54
+ // Normalise gradients implicitly by scaling m
55
+ // Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
56
+ m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
57
+
58
+ // Compute final noise value at P
59
+ vec3 g;
60
+ g.x = a0.x * x0.x + h.x * x0.y;
61
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
62
+ return 130.0 * dot(m, g);
63
+ }
@@ -0,0 +1,16 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture;
4
+ uniform float in_contrast;
5
+
6
+ varying vec2 var_TexCoord;
7
+
8
+ void main()
9
+ {
10
+ vec4 color = texture2D(in_Texture, var_TexCoord);
11
+
12
+ color = (color - 0.5) * contrast + 0.5;
13
+
14
+ gl_FragColor.rgb = color.rgb;
15
+ gl_FragColor.a = 1.0;
16
+ }
@@ -0,0 +1,9 @@
1
+ #version 110
2
+
3
+ varying vec2 var_TexCoord;
4
+
5
+ void main()
6
+ {
7
+ gl_Position = ftransform();
8
+ var_TexCoord = gl_MultiTexCoord0.xy;
9
+ }
@@ -0,0 +1,11 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture;
4
+
5
+ uniform float fade; # 1.0 => normal 0.0 => invisible.
6
+
7
+ varying vec2 var_TexCoord;
8
+
9
+ void main() {
10
+ gl_FragColor = texture2D(in_Texture, var_TexCoord) * fade;
11
+ }
@@ -0,0 +1,24 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture;
4
+
5
+ uniform int t;
6
+
7
+ varying vec2 var_TexCoord;
8
+
9
+ float rand(vec2 co) {
10
+ return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
11
+ }
12
+
13
+ void main() {
14
+ vec4 color;
15
+
16
+ color = texture2D(in_Texture, var_TexCoord);
17
+
18
+ vec3 mezzo = vec3(0.0);
19
+ if(rand(var_TexCoord + float(t)/640.0) <= color.r) { mezzo.r = 1.0; }
20
+ if(rand(var_TexCoord + float(t)/640.0) <= color.g) { mezzo.g = 1.0; }
21
+ if(rand(var_TexCoord + float(t)/640.0) <= color.b) { mezzo.b = 1.0; }
22
+
23
+ gl_FragColor.rgb = mezzo;
24
+ }
@@ -0,0 +1,27 @@
1
+ #version 110
2
+
3
+ // Rather poor quality noise generation, but better than nothing and sort of looks like TV static a bit.
4
+
5
+ uniform sampler2D in_Texture;
6
+
7
+ uniform int in_WindowWidth; // Not used.
8
+ uniform int in_WindowHeight; // Not used.
9
+
10
+ uniform float in_Intensity;
11
+ uniform float in_T;
12
+
13
+ varying vec2 var_TexCoord;
14
+
15
+ float rand(vec2 co) {
16
+ return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
17
+ }
18
+
19
+ void main() {
20
+ vec4 color = texture2D(in_Texture, var_TexCoord);
21
+
22
+ vec4 influence = min(color, 1.0 - color);
23
+
24
+ float noise = 1.0 - 2.0 * rand(var_TexCoord + float(in_T));
25
+
26
+ gl_FragColor = color + in_Intensity * influence * noise;
27
+ }
@@ -0,0 +1,48 @@
1
+ #version 110
2
+
3
+ #define KERNEL_SIZE 9
4
+
5
+ uniform int in_WindowWidth;
6
+ uniform int in_WindowHeight;
7
+
8
+ uniform sampler2D in_Texture;
9
+ uniform int in_PixelSize;
10
+
11
+ varying vec2 var_TexCoord;
12
+
13
+ vec2 texCoords[KERNEL_SIZE];
14
+
15
+ void main(void)
16
+ {
17
+ vec4 avgColor;
18
+ vec2 texCoordsStep = 1.0 /
19
+ (vec2(float(in_WindowWidth), float(in_WindowHeight))/float(in_PixelSize));
20
+ vec2 pixelBin = floor(var_TexCoord / texCoordsStep);
21
+ vec2 inPixelStep = texCoordsStep / 3.0;
22
+ vec2 inPixelHalfStep = inPixelStep / 2.0;
23
+
24
+
25
+ texCoords[0] = vec2(inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
26
+ texCoords[1] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
27
+ texCoords[2] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
28
+ texCoords[3] = vec2(inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
29
+ texCoords[4] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
30
+ texCoords[5] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
31
+ texCoords[6] = vec2(inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
32
+ texCoords[7] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
33
+ texCoords[8] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
34
+
35
+ avgColor = texture2D(in_Texture, texCoords[0]) +
36
+ texture2D(in_Texture, texCoords[1]) +
37
+ texture2D(in_Texture, texCoords[2]) +
38
+ texture2D(in_Texture, texCoords[3]) +
39
+ texture2D(in_Texture, texCoords[4]) +
40
+ texture2D(in_Texture, texCoords[5]) +
41
+ texture2D(in_Texture, texCoords[6]) +
42
+ texture2D(in_Texture, texCoords[7]) +
43
+ texture2D(in_Texture, texCoords[8]);
44
+
45
+ avgColor /= float(KERNEL_SIZE);
46
+
47
+ gl_FragColor = avgColor;
48
+ }
@@ -0,0 +1,31 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture; // Texture to manipulate.
4
+ uniform int in_WindowWidth;
5
+ uniform int in_WindowHeight;
6
+
7
+ uniform float in_BlurFactor;
8
+ uniform float in_BrightFactor;
9
+ uniform float in_OriginX;
10
+ uniform float in_OriginY;
11
+ uniform int in_Passes; // Number of passes to make (more is slower)
12
+
13
+ varying vec2 var_TexCoord; // Coordinate coming from the default vertex shader.
14
+
15
+ void main()
16
+ {
17
+ vec2 Origin = vec2(in_OriginX, 1.0 - in_OriginY);
18
+
19
+ vec2 TexCoord = vec2(var_TexCoord);
20
+
21
+ vec4 SumColor = vec4(0.0, 0.0, 0.0, 0.0);
22
+ TexCoord += vec2(1.0 / float(in_WindowWidth), 1.0 / float(in_WindowHeight)) * 0.5 - Origin;
23
+
24
+ for (int i = 0; i < in_Passes; i++)
25
+ {
26
+ float Scale = 1.0 - in_BlurFactor * (float(i) / float(in_Passes - 1));
27
+ SumColor += texture2D(in_Texture, TexCoord * Scale + Origin);
28
+ }
29
+
30
+ gl_FragColor = SumColor / float(in_Passes) * in_BrightFactor;
31
+ }
@@ -0,0 +1,19 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture;
4
+
5
+ varying vec2 var_TexCoord;
6
+
7
+ void main()
8
+ {
9
+ vec4 Sepia1 = vec4( 0.2, 0.05, 0.0, 1.0 );
10
+ vec4 Sepia2 = vec4( 1.0, 0.9, 0.5, 1.0 );
11
+
12
+ vec4 Color = texture2D(in_Texture, vec2(var_TexCoord));
13
+
14
+ float SepiaMix = dot(vec3(0.3, 0.59, 0.11), vec3(Color));
15
+ Color = mix(Color, vec4(SepiaMix), vec4(0.5));
16
+ vec4 Sepia = mix(Sepia1, Sepia2, SepiaMix);
17
+
18
+ gl_FragColor = mix(Color, Sepia, 1.0);
19
+ }
@@ -0,0 +1,40 @@
1
+ #version 110
2
+
3
+ uniform sampler2D in_Texture;
4
+
5
+ varying vec2 var_TexCoord;
6
+
7
+ uniform float in_Center;
8
+ uniform float in_WaveWidth;
9
+ uniform float in_Time;
10
+ uniform float in_Ratio;
11
+ uniform float in_Refraction;
12
+
13
+ uniform int in_WindowWidth;
14
+ uniform int in_WindowHeight;
15
+
16
+ const float PI = 3.14159;
17
+
18
+ void main()
19
+ {
20
+ vec2 source_coords = var_TexCoord;
21
+ vec3 color = texture2D(in_Texture, source_coords).rgb;
22
+
23
+ float x = in_X / float(in_WindowHeight);
24
+ float y = 1.0 - in_Y / float(in_WindowHeight);
25
+ vec2 rel = source_coords - vec2(x, y);
26
+ rel.x *= in_Ratio;
27
+
28
+ float dist = sqrt(rel.x * rel.x + rel.y * rel.y);
29
+
30
+ if(dist >= in_Min && dist <= in_Max)
31
+ {
32
+ float inner = (dist - in_Min) / (in_Max - in_Min);
33
+ float depth = 0.5 + 0.5 * cos((inner + 0.5) * 2.0 * PI);
34
+
35
+ source_coords -= depth * rel / dist * in_Refraction;
36
+ color = texture2D(in_Texture, source_coords).rgb;
37
+ }
38
+
39
+ gl_FragColor.rgb = color;
40
+ }
@@ -0,0 +1,35 @@
1
+ #version 110
2
+
3
+ // http://www.geeks3d.com/20091116/shader-library-2d-shockwave-post-processing-filter-glsl/
4
+
5
+ uniform sampler2D in_Texture; // 0
6
+ uniform vec2 in_Center; // Mouse position
7
+ uniform float in_Time; // effect elapsed time. Multiply this to affect speed.
8
+
9
+ // Amplitude?, Refraction?, Width? e.g. 10.0, 0.8, 0.1
10
+ uniform vec3 in_ShockParams;
11
+
12
+ uniform int in_WindowWidth;
13
+ uniform int in_WindowHeight;
14
+
15
+ varying vec2 var_TexCoord;
16
+
17
+ void main()
18
+ {
19
+ vec2 uv = var_TexCoord;
20
+ vec2 texCoord = uv;
21
+ float distance = distance(uv, in_Center / vec2(float(in_WindowWidth), float(in_WindowHeight)));
22
+
23
+ if ( (distance <= (in_Time + in_ShockParams.z)) &&
24
+ (distance >= (in_Time - in_ShockParams.z)) )
25
+ {
26
+ float diff = (distance - in_Time);
27
+ float powDiff = 1.0 - pow(abs(diff * in_ShockParams.x),
28
+ in_ShockParams.y);
29
+ float diffTime = diff * powDiff;
30
+ vec2 diffUV = normalize(uv - in_Center);
31
+ texCoord = uv + (diffUV * diffTime);
32
+ }
33
+
34
+ gl_FragColor = texture2D(in_Texture, texCoord);
35
+ }
@@ -0,0 +1,32 @@
1
+ #version 110
2
+ #extension GL_EXT_gpu_shader4 : enable
3
+
4
+ uniform sampler2D in_Texture;
5
+
6
+ uniform float in_ColumnWidth; // In pixels.
7
+ uniform int in_WindowWidth;
8
+ uniform int in_WindowHeight; // Not used in this shader.
9
+
10
+ varying vec2 var_TexCoord;
11
+
12
+ void main()
13
+ {
14
+ vec3 color = texture2D(in_Texture, var_TexCoord).rgb;
15
+
16
+ gl_FragColor = vec4(color * 0.25, 1.0);
17
+
18
+ float column_index = var_TexCoord.x * float(in_WindowWidth) / in_ColumnWidth;
19
+
20
+ switch(int(column_index) % 3)
21
+ {
22
+ case 0:
23
+ gl_FragColor.r = color.r;
24
+ break;
25
+ case 1:
26
+ gl_FragColor.g = color.g;
27
+ break;
28
+ case 2:
29
+ gl_FragColor.b = color.b;
30
+ break;
31
+ }
32
+ }