ashton 0.0.1alpha
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/CHANGELOG +0 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/Rakefile +24 -0
- data/examples/framebuffer_example.rb +50 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/examples/media/simple.png +0 -0
- data/examples/output/README.txt +1 -0
- data/examples/pixelate_example.rb +50 -0
- data/examples/radial_blur_example.rb +63 -0
- data/examples/shader_image_example.rb +42 -0
- data/examples/shockwave2_example.rb +76 -0
- data/examples/tv_screen_and_noise_example.rb +60 -0
- data/lib/ashton/base_shader.rb +172 -0
- data/lib/ashton/framebuffer.rb +183 -0
- data/lib/ashton/gosu_ext/color.rb +12 -0
- data/lib/ashton/gosu_ext/image.rb +32 -0
- data/lib/ashton/gosu_ext/window.rb +36 -0
- data/lib/ashton/image_stub.rb +37 -0
- data/lib/ashton/include/simplex.glsl +63 -0
- data/lib/ashton/post_process/contrast.frag +16 -0
- data/lib/ashton/post_process/default.vert +9 -0
- data/lib/ashton/post_process/fade.frag +11 -0
- data/lib/ashton/post_process/mezzotint.frag +24 -0
- data/lib/ashton/post_process/noise.frag +27 -0
- data/lib/ashton/post_process/pixelate.frag +48 -0
- data/lib/ashton/post_process/radial_blur.frag +31 -0
- data/lib/ashton/post_process/sepia.frag +19 -0
- data/lib/ashton/post_process/shockwave.frag +40 -0
- data/lib/ashton/post_process/shockwave2.frag +35 -0
- data/lib/ashton/post_process/tv_screen.frag +32 -0
- data/lib/ashton/post_process.rb +83 -0
- data/lib/ashton/shader/default.frag +19 -0
- data/lib/ashton/shader/default.vert +14 -0
- data/lib/ashton/shader.rb +62 -0
- data/lib/ashton/version.rb +3 -0
- data/lib/ashton.rb +26 -0
- metadata +201 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require "ashton/base_shader"
|
2
|
+
|
3
|
+
module Ashton
|
4
|
+
# Process the entire screen.
|
5
|
+
class PostProcess < BaseShader
|
6
|
+
DEFAULT_VERTEX_SOURCE = File.read File.expand_path("../post_process/default.vert", __FILE__)
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Canvas used to copy out the screen before post-processing it back onto the screen.
|
10
|
+
# We only need one of these, but only create it after a PostProcessor has
|
11
|
+
# actually been used.
|
12
|
+
def texture
|
13
|
+
@texture ||= begin
|
14
|
+
texture = glGenTextures(1).first
|
15
|
+
glBindTexture GL_TEXTURE_2D, texture
|
16
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
|
17
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
|
18
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
|
19
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
|
20
|
+
glTexImage2D GL_TEXTURE_2D, 0, GL_RGB8, $window.width, $window.height, 0,
|
21
|
+
GL_RGB, GL_UNSIGNED_BYTE, "\0" * ($window.width * $window.height * 3)
|
22
|
+
texture
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Todo: Pass in a filename (String) or name of built-in pp shader (Symbol)
|
28
|
+
def initialize(fragment)
|
29
|
+
super DEFAULT_VERTEX_SOURCE, fragment
|
30
|
+
|
31
|
+
# Set up defaults that we won't need to change at run-time.
|
32
|
+
use do
|
33
|
+
# Width/height are optional.
|
34
|
+
glUniform1i glGetUniformLocation(@program, "in_WindowWidth"), $window.width
|
35
|
+
glUniform1i glGetUniformLocation(@program, "in_WindowHeight"), $window.height
|
36
|
+
|
37
|
+
self["in_Texture"] = 0 # GL_TEXTURE0 will be activated.
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Full screen post-processing using a fragment shader.
|
42
|
+
#
|
43
|
+
# It will force all previous draw operations to be flushed to the
|
44
|
+
# screen, so that you can, or example, process the "game world" before you draw the GUI.
|
45
|
+
#
|
46
|
+
# Variables set for you in the fragment shader:
|
47
|
+
# uniform sampler2D in_Texture; // Texture containing the screen image.
|
48
|
+
# uniform int in_WindowWidth;
|
49
|
+
# uniform int in_WindowHeight;
|
50
|
+
def process
|
51
|
+
$window.gl do
|
52
|
+
width, height = $window.width, $window.height
|
53
|
+
texture = PostProcess.texture
|
54
|
+
|
55
|
+
# Copy window contents into a frame-buffer.
|
56
|
+
glBindTexture GL_TEXTURE_2D, texture
|
57
|
+
glCopyTexImage2D GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, width, height, 0
|
58
|
+
|
59
|
+
# clear screen and set "normal" openGL coordinates.
|
60
|
+
glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
|
61
|
+
glColor4f 1.0, 1.0, 1.0, 1.0
|
62
|
+
glMatrixMode GL_PROJECTION
|
63
|
+
glLoadIdentity
|
64
|
+
glViewport 0, 0, width, height
|
65
|
+
glOrtho 0, width, height, 0, -1, 1
|
66
|
+
|
67
|
+
# Assign the canvas, which was a copy of the screen.
|
68
|
+
glActiveTexture GL_TEXTURE0
|
69
|
+
glBindTexture GL_TEXTURE_2D, texture
|
70
|
+
raise unless glGetIntegerv(GL_ACTIVE_TEXTURE) == GL_TEXTURE0
|
71
|
+
|
72
|
+
use do
|
73
|
+
glBegin GL_QUADS do
|
74
|
+
glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0)
|
75
|
+
glTexCoord2f(1.0, 1.0); glVertex2f(width, 0.0)
|
76
|
+
glTexCoord2f(1.0, 0.0); glVertex2f(width, height)
|
77
|
+
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, height)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#version 110
|
2
|
+
|
3
|
+
uniform sampler2D in_Texture;
|
4
|
+
uniform bool in_TextureEnabled;
|
5
|
+
|
6
|
+
varying vec4 var_Color;
|
7
|
+
varying vec2 var_TexCoord;
|
8
|
+
|
9
|
+
void main()
|
10
|
+
{
|
11
|
+
if(in_TextureEnabled)
|
12
|
+
{
|
13
|
+
gl_FragColor = texture2D(in_Texture, var_TexCoord) * var_Color;
|
14
|
+
}
|
15
|
+
else
|
16
|
+
{
|
17
|
+
gl_FragColor = var_Color;
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "ashton/base_shader"
|
2
|
+
|
3
|
+
module Ashton
|
4
|
+
class Shader < BaseShader
|
5
|
+
attr_reader :image
|
6
|
+
|
7
|
+
shader_path = File.expand_path "../shader", __FILE__
|
8
|
+
DEFAULT_VERTEX_SOURCE = File.read File.join(shader_path, "default.vert")
|
9
|
+
DEFAULT_FRAGMENT_SOURCE = File.read File.join(shader_path, "default.frag")
|
10
|
+
|
11
|
+
# Todo: Pass in a filename (String) or name of built-in pp shader (Symbol)
|
12
|
+
#
|
13
|
+
# @option options [String] :vertex Source code for vertex shader.
|
14
|
+
# @option options [String] :vert equivalent to :vertex
|
15
|
+
# @option options [String] :fragment Source code for fragment shader.
|
16
|
+
# @option options [String] :frag equivalent to :fragment
|
17
|
+
def initialize(options = {})
|
18
|
+
@image = nil
|
19
|
+
|
20
|
+
vertex_source = options[:vertex] || options[:vert] || DEFAULT_VERTEX_SOURCE
|
21
|
+
fragment_source = options[:fragment] || options[:frag] || DEFAULT_FRAGMENT_SOURCE
|
22
|
+
|
23
|
+
super vertex_source, fragment_source
|
24
|
+
link
|
25
|
+
|
26
|
+
@color = [1, 1, 1, 1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def image=(image)
|
30
|
+
use do
|
31
|
+
if image
|
32
|
+
info = image.gl_tex_info
|
33
|
+
|
34
|
+
# Bind the single texture to 'in_Texture'
|
35
|
+
glActiveTexture GL_TEXTURE0
|
36
|
+
glBindTexture GL_TEXTURE_2D, info.tex_name
|
37
|
+
self["in_Texture"] = 0
|
38
|
+
raise unless glGetIntegerv(GL_ACTIVE_TEXTURE) == GL_TEXTURE0
|
39
|
+
|
40
|
+
# Ensure that the shader knows to use the texture.
|
41
|
+
self["in_TextureEnabled"] = true
|
42
|
+
else
|
43
|
+
begin
|
44
|
+
self["in_TextureEnabled"] = false
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
@image = image
|
51
|
+
end
|
52
|
+
|
53
|
+
def color=(color)
|
54
|
+
raise unless current?
|
55
|
+
|
56
|
+
opengl_color = color.is_a?(Gosu::Color) ? color.to_opengl : color
|
57
|
+
|
58
|
+
glVertexAttrib4f attribute("in_Color"), *opengl_color
|
59
|
+
@color = opengl_color
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/ashton.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'opengl'
|
2
|
+
require 'gosu'
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
module Ashton
|
7
|
+
class Error < RuntimeError; end
|
8
|
+
|
9
|
+
class NotSupportedError < Error; end
|
10
|
+
|
11
|
+
class ShaderError < Error; end
|
12
|
+
class ShaderCompileError < ShaderError; end
|
13
|
+
class ShaderLinkError < ShaderError; end
|
14
|
+
class ShaderUniformError < ShaderError; end
|
15
|
+
class ShaderAttributeError < ShaderError; end
|
16
|
+
end
|
17
|
+
|
18
|
+
require "ashton/gosu_ext/window"
|
19
|
+
require "ashton/gosu_ext/image"
|
20
|
+
require "ashton/gosu_ext/color"
|
21
|
+
|
22
|
+
require "ashton/version"
|
23
|
+
require "ashton/shader"
|
24
|
+
require "ashton/post_process"
|
25
|
+
require "ashton/framebuffer"
|
26
|
+
require "ashton/image_stub"
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ashton
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1alpha
|
5
|
+
prerelease: 5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bil Bas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: opengl
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.0.pre1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.0.pre1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.10.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.10.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: launchy
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: RedCloth
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.2.9
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 4.2.9
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: redcarpet
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.1.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.1.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.8.2.1
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.2.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: texplay
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.3'
|
126
|
+
description: ! 'Extra special effects, such as shader, for the Gosu game-development
|
127
|
+
library
|
128
|
+
|
129
|
+
'
|
130
|
+
email:
|
131
|
+
- bil.bagpuss@gmail.com
|
132
|
+
executables: []
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- CHANGELOG
|
137
|
+
- LICENSE
|
138
|
+
- Rakefile
|
139
|
+
- README.md
|
140
|
+
- lib/ashton/base_shader.rb
|
141
|
+
- lib/ashton/framebuffer.rb
|
142
|
+
- lib/ashton/gosu_ext/color.rb
|
143
|
+
- lib/ashton/gosu_ext/image.rb
|
144
|
+
- lib/ashton/gosu_ext/window.rb
|
145
|
+
- lib/ashton/image_stub.rb
|
146
|
+
- lib/ashton/include/simplex.glsl
|
147
|
+
- lib/ashton/post_process/contrast.frag
|
148
|
+
- lib/ashton/post_process/default.vert
|
149
|
+
- lib/ashton/post_process/fade.frag
|
150
|
+
- lib/ashton/post_process/mezzotint.frag
|
151
|
+
- lib/ashton/post_process/noise.frag
|
152
|
+
- lib/ashton/post_process/pixelate.frag
|
153
|
+
- lib/ashton/post_process/radial_blur.frag
|
154
|
+
- lib/ashton/post_process/sepia.frag
|
155
|
+
- lib/ashton/post_process/shockwave.frag
|
156
|
+
- lib/ashton/post_process/shockwave2.frag
|
157
|
+
- lib/ashton/post_process/tv_screen.frag
|
158
|
+
- lib/ashton/post_process.rb
|
159
|
+
- lib/ashton/shader/default.frag
|
160
|
+
- lib/ashton/shader/default.vert
|
161
|
+
- lib/ashton/shader.rb
|
162
|
+
- lib/ashton/version.rb
|
163
|
+
- lib/ashton.rb
|
164
|
+
- examples/framebuffer_example.rb
|
165
|
+
- examples/media/Earth.png
|
166
|
+
- examples/media/LargeStar.png
|
167
|
+
- examples/media/simple.png
|
168
|
+
- examples/media/Star.png
|
169
|
+
- examples/media/Starfighter.bmp
|
170
|
+
- examples/output/README.txt
|
171
|
+
- examples/pixelate_example.rb
|
172
|
+
- examples/radial_blur_example.rb
|
173
|
+
- examples/shader_image_example.rb
|
174
|
+
- examples/shockwave2_example.rb
|
175
|
+
- examples/tv_screen_and_noise_example.rb
|
176
|
+
homepage: https://github.com/spooner/ashton
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ! '>'
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.3.1
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project: ashton
|
197
|
+
rubygems_version: 1.8.24
|
198
|
+
signing_key:
|
199
|
+
specification_version: 3
|
200
|
+
summary: Extra special effects, such as shader, for the Gosu game-development library
|
201
|
+
test_files: []
|