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
data/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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.
|
data/README.md
CHANGED
|
@@ -1,68 +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)
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- Gosu::
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- Gosu::Window
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- {Ashton::
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- {Ashton::
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
|
data/Rakefile
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
require '
|
|
4
|
-
require '
|
|
5
|
-
require '
|
|
6
|
-
require '
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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"
|
|
24
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
|