danabr75-ashton 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +0 -0
  3. data/LICENSE +21 -0
  4. data/README.md +95 -0
  5. data/Rakefile +42 -0
  6. data/examples/bloom_example.rb +59 -0
  7. data/examples/lighting_example.rb +127 -0
  8. data/examples/media/Earth.png +0 -0
  9. data/examples/media/LargeStar.png +0 -0
  10. data/examples/media/SmallStar.png +0 -0
  11. data/examples/media/Star.png +0 -0
  12. data/examples/media/Starfighter.bmp +0 -0
  13. data/examples/media/Starfighter.png +0 -0
  14. data/examples/media/simple.png +0 -0
  15. data/examples/noise_example.rb +94 -0
  16. data/examples/outline_example.rb +86 -0
  17. data/examples/particle_emitter_example.rb +114 -0
  18. data/examples/pixelate_example.rb +52 -0
  19. data/examples/pixelated_texture_example.rb +69 -0
  20. data/examples/radial_blur_example.rb +61 -0
  21. data/examples/shader_image_example.rb +75 -0
  22. data/examples/shockwave_example.rb +75 -0
  23. data/examples/stencil_shader_example.rb +104 -0
  24. data/examples/texture_render_example.rb +54 -0
  25. data/examples/tv_screen_and_static_example.rb +60 -0
  26. data/ext/ashton/GLee.c +18170 -0
  27. data/ext/ashton/GLee.h +17648 -0
  28. data/ext/ashton/ashton.c +42 -0
  29. data/ext/ashton/ashton.h +31 -0
  30. data/ext/ashton/color.c +45 -0
  31. data/ext/ashton/color.h +25 -0
  32. data/ext/ashton/common.h +41 -0
  33. data/ext/ashton/extconf.rb +45 -0
  34. data/ext/ashton/fast_math.c +30 -0
  35. data/ext/ashton/fast_math.h +30 -0
  36. data/ext/ashton/font.c +8 -0
  37. data/ext/ashton/font.h +16 -0
  38. data/ext/ashton/gosu.c +18 -0
  39. data/ext/ashton/gosu.h +19 -0
  40. data/ext/ashton/image.c +8 -0
  41. data/ext/ashton/image.h +16 -0
  42. data/ext/ashton/particle_emitter.c +788 -0
  43. data/ext/ashton/particle_emitter.h +171 -0
  44. data/ext/ashton/pixel_cache.c +237 -0
  45. data/ext/ashton/pixel_cache.h +58 -0
  46. data/ext/ashton/shader.c +9 -0
  47. data/ext/ashton/shader.h +16 -0
  48. data/ext/ashton/texture.c +442 -0
  49. data/ext/ashton/texture.h +63 -0
  50. data/ext/ashton/vendor/gl/include/GL/GL.H +1526 -0
  51. data/ext/ashton/window.c +8 -0
  52. data/ext/ashton/window.h +16 -0
  53. data/lib/ashton.rb +38 -0
  54. data/lib/ashton/gosu_ext/color.rb +25 -0
  55. data/lib/ashton/gosu_ext/font.rb +58 -0
  56. data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
  57. data/lib/ashton/gosu_ext/image.rb +96 -0
  58. data/lib/ashton/gosu_ext/window.rb +79 -0
  59. data/lib/ashton/image_stub.rb +33 -0
  60. data/lib/ashton/lighting/light_source.rb +146 -0
  61. data/lib/ashton/lighting/manager.rb +98 -0
  62. data/lib/ashton/mixins/version_checking.rb +23 -0
  63. data/lib/ashton/particle_emitter.rb +87 -0
  64. data/lib/ashton/pixel_cache.rb +24 -0
  65. data/lib/ashton/shader.rb +386 -0
  66. data/lib/ashton/shaders/bloom.frag +41 -0
  67. data/lib/ashton/shaders/color_inversion.frag +11 -0
  68. data/lib/ashton/shaders/contrast.frag +16 -0
  69. data/lib/ashton/shaders/default.frag +22 -0
  70. data/lib/ashton/shaders/default.vert +14 -0
  71. data/lib/ashton/shaders/fade.frag +14 -0
  72. data/lib/ashton/shaders/grayscale.frag +15 -0
  73. data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
  74. data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
  75. data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
  76. data/lib/ashton/shaders/include/noise2d.glsl +70 -0
  77. data/lib/ashton/shaders/include/noise3d.glsl +102 -0
  78. data/lib/ashton/shaders/include/noise4d.glsl +128 -0
  79. data/lib/ashton/shaders/include/rand.glsl +5 -0
  80. data/lib/ashton/shaders/lighting/distort.frag +57 -0
  81. data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
  82. data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
  83. data/lib/ashton/shaders/mezzotint.frag +22 -0
  84. data/lib/ashton/shaders/multitexture2.vert +19 -0
  85. data/lib/ashton/shaders/outline.frag +45 -0
  86. data/lib/ashton/shaders/pixelate.frag +48 -0
  87. data/lib/ashton/shaders/radial_blur.frag +63 -0
  88. data/lib/ashton/shaders/sepia.frag +26 -0
  89. data/lib/ashton/shaders/shockwave.frag +38 -0
  90. data/lib/ashton/shaders/signed_distance_field.frag +80 -0
  91. data/lib/ashton/shaders/static.frag +25 -0
  92. data/lib/ashton/shaders/stencil.frag +27 -0
  93. data/lib/ashton/shaders/tv_screen.frag +23 -0
  94. data/lib/ashton/signed_distance_field.rb +151 -0
  95. data/lib/ashton/texture.rb +186 -0
  96. data/lib/ashton/version.rb +3 -0
  97. data/lib/ashton/window_buffer.rb +16 -0
  98. data/spec/ashton/ashton_spec.rb +22 -0
  99. data/spec/ashton/gosu_ext/color_spec.rb +34 -0
  100. data/spec/ashton/gosu_ext/font_spec.rb +57 -0
  101. data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
  102. data/spec/ashton/gosu_ext/image_spec.rb +66 -0
  103. data/spec/ashton/gosu_ext/window_spec.rb +71 -0
  104. data/spec/ashton/image_stub_spec.rb +46 -0
  105. data/spec/ashton/particle_emitter_spec.rb +123 -0
  106. data/spec/ashton/pixel_cache_spec.rb +153 -0
  107. data/spec/ashton/shader_spec.rb +152 -0
  108. data/spec/ashton/signed_distance_field_spec.rb +163 -0
  109. data/spec/ashton/texture_spec.rb +347 -0
  110. data/spec/helper.rb +12 -0
  111. metadata +309 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0c5002bfe7b7d7243704995bdafc10b318acf0f
4
+ data.tar.gz: 89895d937cbfeda0fd26a713df6309100d6053a2
5
+ SHA512:
6
+ metadata.gz: 7187d0bf0462d5d2b3d3d9630fd56e9fa212f0f73a786367e5dd5f06990e00639b424b9892af814fd81ec82a9df13806c000ebc9e3eecc200cf9c0a383d8e914
7
+ data.tar.gz: 31ff1d30925ff37e35b88e0fc4303f13bf0353b5224f58b53f3b44709f6c0841d3ffee9a66bdd63d4ee34168ba8375cc444e47d12ff8e634f950986b7b679383
File without changes
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Bil Bas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ Ashton
2
+ ======
3
+
4
+ Description
5
+ -----------
6
+
7
+ Add extra visual effects to the Gosu game-development library, utilising OpenGL shaders (using shader model 1.0, for maximum compatibility) and frame-buffers.
8
+
9
+ "Ashton" is named after [Clark Ashton Smith](http://en.wikipedia.org/wiki/Clark_Ashton_Smith), an fantasy/horror author
10
+ with a particularly colourful imagination.
11
+
12
+ - Author: [Bil Bas (Spooner)](http://spooner.github.com/)
13
+ - [Wiki](https://github.com/Spooner/ashton/wiki)
14
+ - License: MIT
15
+
16
+ Usage
17
+ -----
18
+
19
+ gem install ashton --pre
20
+
21
+ Features
22
+ --------
23
+
24
+ * Gosu extensions
25
+ - {Gosu::Color} - Converting to and from opengl values.
26
+
27
+ - {Gosu::Font} - Apply shader to draw operations.
28
+
29
+ - {Gosu::Image} - Apply shader to each draw operation or group of draws. Manipulation, such as flipping and scaling.
30
+
31
+ - {Gosu::Window} - Post-processing with shaders. Converting to image.
32
+
33
+ * Ashton
34
+ - {Ashton::Texture} - Single texture (compared to Gosu::Image which uses a spritesheet) which can be drawn directly onto and drawn to the Window.
35
+
36
+ - {Ashton::Lighting::Manager} - Manages and combines the lighting from {Ashton::Lighting::LightSource} objects.
37
+
38
+ - {Ashton::Lighting::LightSource} - A single light-source that illuminates and whose can be blocked by shadow-casting objects.
39
+
40
+ - {Ashton::ParticleEmitter} - Generates, manages and displays particles.
41
+
42
+ - {Ashton::PixelCache} - Cached image data attached to an {Ashton::Texture} or {Gosu::Image}.
43
+
44
+ - {Ashton::SignedDistanceField} - A signed distance field based on a an image mask.
45
+
46
+ - {Ashton::Shader} - Wrapper around a GLSL shaders, Supports vertex and fragment shaders. Small shader/function library.
47
+
48
+ - {Ashton::WindowBuffer} - Texture that is the same size as the Gosu Window that can capture the contents of the screen.
49
+
50
+ Requirements
51
+ ------------
52
+
53
+ * OSX/Linux: Requires OpenGL library be installed.
54
+
55
+ * {Ashton::Shader} and {Ashton::Lighting} or anything else using shaders, require OpenGL 2.0.
56
+
57
+ Similar Libraries
58
+ -----------------
59
+
60
+ - [TexPlay](https://github.com/banister/texplay) - Deals with Gosu::Image manipulation, such as per-pixel editing and drawing. It is compatible with, and complementary to, this gem.
61
+
62
+ Third party
63
+ -----------
64
+
65
+ - OpenGL static library (in Windows binary gem) and headers.
66
+ - [GLee](http://elf-stone.com/glee.php) source.
67
+
68
+ - Various trivial shaders - "randomly found on the Internet" :$
69
+
70
+ - [Classic and Simplex noise functions](https://github.com/ashima/webgl-noise/) - Copyright (C) 2011 Ashima Arts - MIT license.
71
+ * classicnoise2d.glsl - 2D Classic Perlin noise implementation - `cnoise(vec2)`
72
+ * classicnoise3d.glsl - 3D Classic Perlin noise implementation - `cnoise(vec3)`
73
+ * classicnoise4d.glsl - 4D Classic Perlin noise implementation - `cnoise(vec4)`
74
+ * noise2d.glsl - 2D Simplex noise implementation - `snoise(vec2)`
75
+ * noise3d.glsl - 3D Simplex noise implementation - `snoise(vec3)`
76
+ * noise4d.glsl - 4D Simplex noise implementation - `snoise(vec4)`
77
+
78
+ - [Bloom filter by myheroics](http://myheroics.wordpress.com/2008/09/04/glsl-bloom-shader/)
79
+ * bloom.frag
80
+
81
+ - [Shockwave by Crystalin](http://empire-defense.crystalin.fr/blog/2d_shock_wave_texture_with_shader)
82
+ * shockwave.frag
83
+
84
+ - [Radial Blur by gamerendering.com](http://www.gamerendering.com/2008/12/20/radial-blur-filter/)
85
+ * radial_blur.frag
86
+
87
+ - Lighting based on, but much optimised from, Catalin Zima's shader based dynamic shadows system.
88
+ * http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/
89
+ * {Ashton::Lighting::LightSource} and {Ashton::Lighting::Manager} classes.
90
+ * shadow_blur.frag
91
+ * shadow_distory.frag
92
+ * shadow_draw_shadows.frag
93
+
94
+
95
+
@@ -0,0 +1,42 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'rake/clean'
4
+ require 'rspec/core/rake_task'
5
+ require 'rake/extensiontask'
6
+ require 'yard'
7
+ require 'redcloth'
8
+ require 'launchy'
9
+
10
+ begin
11
+ require 'devkit' # only used on windows
12
+ rescue LoadError
13
+ end
14
+
15
+
16
+ spec = Gem::Specification.load Dir['*.gemspec'].first
17
+
18
+ Gem::PackageTask.new spec do
19
+ end
20
+
21
+ Rake::ExtensionTask.new 'ashton', spec do |ext|
22
+ RUBY_VERSION =~ /(\d+.\d+)/
23
+ ext.lib_dir = "lib/ashton/#{$1}"
24
+ end
25
+
26
+ YARD::Rake::YardocTask.new
27
+
28
+ task :default => :spec
29
+ task :spec => :compile
30
+
31
+ RSpec::Core::RakeTask.new do |t|
32
+ end
33
+
34
+ desc "Open yard docs in browser"
35
+ task :browse_yard => :yard do
36
+ Launchy.open "doc/index.html" rescue nil
37
+ end
38
+
39
+ desc "Create platform-specific compiled gem"
40
+ task :native_gem do
41
+ Rake::Task["native"].invoke "gem"
42
+ end
@@ -0,0 +1,59 @@
1
+ # Use of GLSL shader in Gosu to post-process the entire screen.
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ end
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
9
+ require "ashton"
10
+
11
+ def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
12
+
13
+ class TestWindow < Gosu::Window
14
+ def initialize
15
+ super 640, 480, false
16
+ self.caption = "Post-processing with 'bloom' - mouse pos alters glare and power - hold <Space> to disable"
17
+
18
+ @bloom = Ashton::Shader.new fragment: :bloom
19
+
20
+
21
+ @font = Gosu::Font.new self, Gosu::default_font_name, 40
22
+ @star = Gosu::Image.new(self, media_path("LargeStar.png"), true)
23
+ @background = Gosu::Image.new(self, media_path("Earth.png"), true)
24
+
25
+ update # Ensure the values are initially set.
26
+ end
27
+
28
+ def update
29
+ $gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
30
+ @bloom.glare_size = [0.008 * mouse_x / width, 0.0].max
31
+ @bloom.power = [0.5 * mouse_y / height, 0.0].max
32
+ end
33
+
34
+ def needs_cursor?; true end
35
+
36
+ def button_down(id)
37
+ if id == Gosu::KbEscape
38
+ close
39
+ end
40
+ end
41
+
42
+ def draw
43
+ shaders = button_down?(Gosu::KbSpace) ? [] : [@bloom]
44
+ post_process(*shaders) do
45
+ @background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
46
+ @star.draw 0, 0, 0
47
+ @star.draw 200, 100, 0, 1, 1, Gosu::Color.rgb(100, 100, 100)
48
+ end
49
+
50
+ # Drawing after the effect isn't processed, which is useful for GUI elements.
51
+ @font.draw_rel "Less glare", 0, height / 2, 0, 0, 0.5
52
+ @font.draw_rel "More glare", width, height / 2, 0, 1, 0.5
53
+
54
+ @font.draw_rel "Less power", width / 2, 0, 0, 0.5, 0
55
+ @font.draw_rel "More power", width / 2, height, 0, 0.5, 1
56
+ end
57
+ end
58
+
59
+ TestWindow.new.show
@@ -0,0 +1,127 @@
1
+ # Use of GLSL shader in Gosu to post-process the entire screen.
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ end
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
9
+ require "ashton"
10
+
11
+ def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
12
+
13
+ class TestWindow < Gosu::Window
14
+ def initialize
15
+ super 640, 480, false
16
+ self.caption = "Shadow-casting - <space> new layout; <LMB> place light; <Arrows> to scroll"
17
+
18
+ @font = Gosu::Font.new self, Gosu::default_font_name, 32
19
+ @background = Gosu::Image.new(self, media_path("Earth.png"), true)
20
+
21
+ @star = Gosu::Image.new(self, media_path("LargeStar.png"), true)
22
+
23
+ # Input: Shadow casters are any object that casts a shadow.
24
+ place_shadow_casters
25
+
26
+ setup_lighting
27
+
28
+ # Perform the initial rendering into the light manager.
29
+ @lighting.update_shadow_casters do
30
+ draw_shadow_casters
31
+ end
32
+
33
+ @debug = false
34
+ @camera_x, @camera_y = 0, 0
35
+ end
36
+
37
+ def setup_lighting
38
+ @lighting = Ashton::Lighting::Manager.new
39
+
40
+ # Add some lights (various methods)
41
+ @lighting.create_light 240, 240, 0, height / 3, color: Gosu::Color::RED
42
+
43
+ light = Ashton::Lighting::LightSource.new 400, 150, 0, height / 5, color: Gosu::Color::GREEN
44
+ @lighting << light
45
+
46
+ @light_mouse = @lighting.create_light mouse_x, mouse_y, 0, height / 2, color: Gosu::Color::GRAY
47
+ end
48
+
49
+ # Creates a new set of objects that cast shadows.
50
+ def place_shadow_casters
51
+ @shadow_casters = Array.new 12 do
52
+ { x: rand() * width, y: rand() * height, angle: rand() * 360 }
53
+ end
54
+ end
55
+
56
+ def update
57
+ $gosu_blocks.clear if defined? $gosu_blocks # workaround for Gosu 0.7.45 bug.
58
+
59
+ @camera_x -= 2 if button_down? Gosu::KbLeft
60
+ @camera_x += 2 if button_down? Gosu::KbRight
61
+ @camera_y -= 2 if button_down? Gosu::KbUp
62
+ @camera_y += 2 if button_down? Gosu::KbDown
63
+
64
+ @lighting.camera_x = @camera_x
65
+ @lighting.camera_y = @camera_y
66
+
67
+ @light_mouse.x, @light_mouse.y = mouse_x + @camera_x, mouse_y + @camera_y
68
+
69
+ @lighting.update_shadow_casters do
70
+ draw_shadow_casters
71
+ end
72
+ end
73
+
74
+ def draw_shadow_casters
75
+ @font.draw "Hello world! Time to get a grip, eh?", 0, 150, 0, 1, 1, Gosu::Color::RED
76
+ @shadow_casters.each do |star|
77
+ @star.draw_rot star[:x], star[:y], 0, star[:angle], 0.5, 0.5, 0.125, 0.125
78
+ end
79
+ end
80
+
81
+ def needs_cursor?
82
+ true
83
+ end
84
+
85
+ def button_down(id)
86
+ case id
87
+ when Gosu::KbEscape
88
+ close
89
+
90
+ when Gosu::KbSpace
91
+ place_shadow_casters
92
+
93
+ when Gosu::MsLeft
94
+ color = Gosu::Color.rgba rand(255), rand(255), rand(255), 127 + rand(128)
95
+ @lighting.create_light mouse_x + @camera_x, mouse_y + @camera_y, 0, height / 16 + rand(height / 2), color: color
96
+
97
+ when Gosu::KbD
98
+ @debug = !@debug
99
+
100
+ when Gosu::KbS
101
+ @lighting.each {|light| light.send :save_buffers }
102
+ end
103
+ end
104
+
105
+ def draw
106
+ translate -@camera_x, -@camera_y do
107
+ @background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
108
+
109
+ # ... would draw player and other objects here ...
110
+
111
+ @lighting.draw
112
+
113
+ draw_shadow_casters # These should be drawn above or below the lighting, depending on preference.
114
+
115
+ # Draw the light itself - this isn't managed by the manager.
116
+ @lighting.each do |light|
117
+ pixel.draw_rot light.x, light.y, 0, 0, 0.5, 0.5, 15, 15, light.color, :add
118
+ light.draw_debug if @debug
119
+ end
120
+ end
121
+
122
+ # Drawing after the effect isn't processed, which is useful for GUI elements.
123
+ @font.draw "FPS: #{Gosu::fps} (for #{@lighting.size} lights)", 0, 0, 0
124
+ end
125
+ end
126
+
127
+ TestWindow.new.show
Binary file
Binary file
Binary file
@@ -0,0 +1,94 @@
1
+ # Use of GLSL shader in Gosu to post-process the entire screen.
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ end
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
9
+ require "ashton"
10
+
11
+ def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
12
+
13
+ class TestWindow < Gosu::Window
14
+ NOISE_FRAGMENT =<<-END
15
+ #version 110
16
+
17
+ // Use 3D Simplex noise, even though the shader operates on a 2D
18
+ // texture, since then we can make the Z-coordinate act as time.
19
+ #include <noise3d>
20
+
21
+ uniform sampler2D in_Texture;
22
+
23
+ uniform float in_T;
24
+ uniform vec4 in_BlobColor;
25
+
26
+ varying vec2 var_TexCoord;
27
+
28
+ void main()
29
+ {
30
+ gl_FragColor = texture2D(in_Texture, var_TexCoord);
31
+
32
+ // First layer. faster, low intensity, small scale blobbing.
33
+ // Use [x, y, t] to create a 2D noise that varies over time.
34
+ vec3 position1 = vec3(var_TexCoord * 25.0, in_T * 1.6);
35
+
36
+ // Gives range 0.75..1.25
37
+ float brightness1 = snoise(position1) / 4.0 + 1.0;
38
+
39
+ // Second layer - slow, high intensity, large-scale blobbing
40
+ // This decides where the first layer will be "seen"
41
+ // Use [x, y, t] to create a 2D noise that varies over time.
42
+ vec3 position2 = vec3(var_TexCoord * 3.0, in_T * 0.16);
43
+
44
+ // Gives range 0.3..1.3
45
+ float brightness2 = snoise(position2) / 2.0 + 0.8;
46
+
47
+ if(brightness2 > 0.8)
48
+ {
49
+ gl_FragColor.rgb += in_BlobColor.rgb;
50
+ gl_FragColor.rgb *= brightness1 * brightness2;
51
+ }
52
+ }
53
+ END
54
+
55
+ def initialize
56
+ super 640, 480, false
57
+ self.caption = "Post-processing with the simplex noise function - intelligent blob?"
58
+
59
+ @noise = Ashton::Shader.new fragment: NOISE_FRAGMENT, uniforms: {
60
+ blob_color: Gosu::Color.rgb(0, 40, 0),
61
+ }
62
+
63
+ @font = Gosu::Font.new self, Gosu::default_font_name, 40
64
+ @background = Gosu::Image.new(self, media_path("Earth.png"), true)
65
+ @start_time = Time.now
66
+
67
+ update # Ensure the values are initially set.
68
+ end
69
+
70
+ def update
71
+ $gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
72
+ @noise.t = Time.now - @start_time
73
+ end
74
+
75
+ def draw
76
+ post_process @noise do
77
+ @background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
78
+
79
+ @font.draw_rel "Hello world!", 350, 50, 0, 0.5, 0.5, 1, 1, Gosu::Color::GREEN
80
+ @font.draw_rel "Goodbye world!", 400, 350, 0, 0.5, 0.5, 2, 2, Gosu::Color::BLUE
81
+ end
82
+
83
+ # Drawing after the effect isn't processed, which is useful for GUI elements.
84
+ @font.draw "FPS: #{Gosu::fps}", 0, 0, 0
85
+ end
86
+
87
+ def button_down(id)
88
+ if id == Gosu::KbEscape
89
+ close
90
+ end
91
+ end
92
+ end
93
+
94
+ TestWindow.new.show