processing 0.5.14 → 0.5.16
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.
- checksums.yaml +4 -4
- data/ChangeLog.md +14 -0
- data/VERSION +1 -1
- data/lib/processing/graphics.rb +7 -4
- data/lib/processing/graphics_context.rb +5 -4
- data/lib/processing/shader.rb +104 -61
- data/lib/processing/window.rb +3 -3
- data/lib/processing.rb +3 -1
- data/processing.gemspec +1 -1
- data/test/test_shader.rb +14 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6025b178164394ad3493995863e8077280dbf2745abd4c2a84223fcbfb6aa65
|
4
|
+
data.tar.gz: 41a9a7b7410d0a6aa5bc34e611e17432722a85a15179eb746511aa75f46eaa97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbdf458466e765affb174fce19573fab4d4cfe76e106aaef421fc4e66f95e7b02a6c2d5bc11662756a313f0cabbadfb705f75306b0f7627c32386a17da365030
|
7
|
+
data.tar.gz: 11a736963e87ab5b91c087dce0fcd863c29f5912a6bbfd20d643345f0ead8f268e7a0784f3ceeb7bf903a0d06d500c350e82f9fc34c25d61f23d0cdf2b828554
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# processing ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [v0.5.16] - 2023-06-02
|
5
|
+
|
6
|
+
- Fix failed tests and add tests
|
7
|
+
|
8
|
+
|
9
|
+
## [v0.5.15] - 2023-06-02
|
10
|
+
|
11
|
+
- Set initial canvas size to same as the window size
|
12
|
+
- Use WIDTH and HEIGHT env vars for initial canvas size
|
13
|
+
- Shader class can take shadertoy frament shader source
|
14
|
+
- createGraphics() can take pixelDensity parameter
|
15
|
+
- Pass self to the block call of beginDraw(), and ensure endDraw
|
16
|
+
|
17
|
+
|
4
18
|
## [v0.5.14] - 2023-05-29
|
5
19
|
|
6
20
|
- Add windowMove() and windowResize()
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.16
|
data/lib/processing/graphics.rb
CHANGED
@@ -10,8 +10,8 @@ module Processing
|
|
10
10
|
|
11
11
|
# Initialize graphics object.
|
12
12
|
#
|
13
|
-
def initialize(width, height)
|
14
|
-
image = Rays::Image.new width, height
|
13
|
+
def initialize(width, height, pixelDensity = 1)
|
14
|
+
image = Rays::Image.new width, height, Rays::RGBA, pixelDensity
|
15
15
|
init__ image, image.painter
|
16
16
|
end
|
17
17
|
|
@@ -22,8 +22,11 @@ module Processing
|
|
22
22
|
@painter__.__send__ :begin_paint
|
23
23
|
push
|
24
24
|
if block
|
25
|
-
|
26
|
-
|
25
|
+
begin
|
26
|
+
block.call self
|
27
|
+
ensure
|
28
|
+
endDraw
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -1648,13 +1648,14 @@ module Processing
|
|
1648
1648
|
|
1649
1649
|
# Creates a new off-screen graphics context object.
|
1650
1650
|
#
|
1651
|
-
# @param width
|
1652
|
-
# @param height
|
1651
|
+
# @param width [Numeric] width of graphics image
|
1652
|
+
# @param height [Numeric] height of graphics image
|
1653
|
+
# @param pixelDensity [Numeric] pixel density of graphics image
|
1653
1654
|
#
|
1654
1655
|
# @return [Graphics] graphics object
|
1655
1656
|
#
|
1656
|
-
def createGraphics(width, height)
|
1657
|
-
Graphics.new width, height
|
1657
|
+
def createGraphics(width, height, pixelDensity = 1)
|
1658
|
+
Graphics.new width, height, pixelDensity
|
1658
1659
|
end
|
1659
1660
|
|
1660
1661
|
# Creates a shader object.
|
data/lib/processing/shader.rb
CHANGED
@@ -13,7 +13,7 @@ module Processing
|
|
13
13
|
# @param fragSrc [String] fragment shader source
|
14
14
|
#
|
15
15
|
def initialize(vertSrc, fragSrc)
|
16
|
-
@shader = Rays::Shader.new fragSrc, vertSrc, ENV__
|
16
|
+
@shader = Rays::Shader.new modifyFragSource(fragSrc), vertSrc, ENV__
|
17
17
|
end
|
18
18
|
|
19
19
|
# Sets uniform variables.
|
@@ -83,74 +83,117 @@ module Processing
|
|
83
83
|
when Shader
|
84
84
|
arg
|
85
85
|
when :threshold
|
86
|
-
self.new(nil,
|
87
|
-
uniform float threshold;
|
88
|
-
uniform sampler2D texMap;
|
89
|
-
varying vec4 vertTexCoord;
|
90
|
-
varying vec4 vertColor;
|
91
|
-
void main() {
|
92
|
-
vec4 col = texture2D(texMap, vertTexCoord.xy) * vertColor;
|
93
|
-
float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
|
94
|
-
gl_FragColor = vec4(vec3(gray > threshold ? 1.0 : 0.0), 1.0);
|
95
|
-
}
|
96
|
-
END
|
86
|
+
self.new(nil, THRESHOLD_SOURCE).tap {|sh| sh.set :threshold, (args.shift || 0.5)}
|
97
87
|
when :gray
|
98
|
-
self.new nil,
|
99
|
-
uniform sampler2D texMap;
|
100
|
-
varying vec4 vertTexCoord;
|
101
|
-
varying vec4 vertColor;
|
102
|
-
void main() {
|
103
|
-
vec4 col = texture2D(texMap, vertTexCoord.xy);
|
104
|
-
float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
|
105
|
-
gl_FragColor = vec4(vec3(gray), 1.0) * vertColor;
|
106
|
-
}
|
107
|
-
END
|
88
|
+
self.new nil, GRAY_SOURCE
|
108
89
|
when :invert
|
109
|
-
self.new nil,
|
110
|
-
uniform sampler2D texMap;
|
111
|
-
varying vec4 vertTexCoord;
|
112
|
-
varying vec4 vertColor;
|
113
|
-
void main() {
|
114
|
-
vec4 col = texture2D(texMap, vertTexCoord.xy);
|
115
|
-
gl_FragColor = vec4(vec3(1.0 - col.rgb), 1.0) * vertColor;
|
116
|
-
}
|
117
|
-
END
|
90
|
+
self.new nil, INVERT_SOURCE
|
118
91
|
when :blur
|
119
|
-
self.new(nil,
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
92
|
+
self.new(nil, BLUR_SOURCE).tap {|sh| sh.set :radius, (args.shift || 1).to_f}
|
93
|
+
else
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
THRESHOLD_SOURCE = <<~END
|
101
|
+
uniform float threshold;
|
102
|
+
uniform sampler2D texMap;
|
103
|
+
varying vec4 vertTexCoord;
|
104
|
+
varying vec4 vertColor;
|
105
|
+
void main() {
|
106
|
+
vec4 col = texture2D(texMap, vertTexCoord.xy) * vertColor;
|
107
|
+
float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
|
108
|
+
gl_FragColor = vec4(vec3(gray > threshold ? 1.0 : 0.0), 1.0);
|
109
|
+
}
|
110
|
+
END
|
111
|
+
|
112
|
+
GRAY_SOURCE = <<~END
|
113
|
+
uniform sampler2D texMap;
|
114
|
+
varying vec4 vertTexCoord;
|
115
|
+
varying vec4 vertColor;
|
116
|
+
void main() {
|
117
|
+
vec4 col = texture2D(texMap, vertTexCoord.xy);
|
118
|
+
float gray = col.r * 0.3 + col.g * 0.59 + col.b * 0.11;
|
119
|
+
gl_FragColor = vec4(vec3(gray), 1.0) * vertColor;
|
120
|
+
}
|
121
|
+
END
|
122
|
+
|
123
|
+
INVERT_SOURCE = <<~END
|
124
|
+
uniform sampler2D texMap;
|
125
|
+
varying vec4 vertTexCoord;
|
126
|
+
varying vec4 vertColor;
|
127
|
+
void main() {
|
128
|
+
vec4 col = texture2D(texMap, vertTexCoord.xy);
|
129
|
+
gl_FragColor = vec4(vec3(1.0 - col.rgb), 1.0) * vertColor;
|
130
|
+
}
|
131
|
+
END
|
132
|
+
|
133
|
+
BLUR_SOURCE = <<~END
|
134
|
+
#define PI 3.1415926538
|
135
|
+
uniform float radius;
|
136
|
+
uniform sampler2D texMap;
|
137
|
+
uniform vec3 texMin;
|
138
|
+
uniform vec3 texMax;
|
139
|
+
uniform vec3 texOffset;
|
140
|
+
varying vec4 vertTexCoord;
|
141
|
+
varying vec4 vertColor;
|
142
|
+
float gaussian(vec2 pos, float sigma) {
|
143
|
+
float s2 = sigma * sigma;
|
144
|
+
return 1.0 / (2.0 * PI * s2) * exp(-(dot(pos, pos) / (2.0 * s2)));
|
145
|
+
}
|
146
|
+
void main() {
|
147
|
+
float sigma = radius * 0.5;
|
148
|
+
vec3 color = vec3(0.0);
|
149
|
+
float total_weight = 0.0;
|
150
|
+
for (float y = -radius; y < radius; y += 1.0)
|
151
|
+
for (float x = -radius; x < radius; x += 1.0) {
|
152
|
+
vec2 offset = vec2(x, y);
|
153
|
+
float weight = gaussian(offset, sigma);
|
154
|
+
vec2 texcoord = vertTexCoord.xy + offset * texOffset.xy;
|
155
|
+
if (
|
156
|
+
texcoord.x < texMin.x || texMax.x < texcoord.x ||
|
157
|
+
texcoord.y < texMin.y || texMax.y < texcoord.y
|
158
|
+
) continue;
|
159
|
+
color += texture2D(texMap, texcoord).rgb * weight;
|
160
|
+
total_weight += weight;
|
161
|
+
}
|
162
|
+
gl_FragColor = vec4(color / total_weight, 1.0) * vertColor;
|
163
|
+
}
|
164
|
+
END
|
165
|
+
|
166
|
+
def modifyFragSource(source)
|
167
|
+
return nil unless source
|
168
|
+
if hasShadertoyMainImage?(source) && source !~ /void\s+main\s*\(/
|
169
|
+
source += <<~END
|
126
170
|
varying vec4 vertTexCoord;
|
127
|
-
varying vec4 vertColor;
|
128
|
-
float gaussian(vec2 pos, float sigma) {
|
129
|
-
float s2 = sigma * sigma;
|
130
|
-
return 1.0 / (2.0 * PI * s2) * exp(-(dot(pos, pos) / (2.0 * s2)));
|
131
|
-
}
|
132
171
|
void main() {
|
133
|
-
|
134
|
-
vec3 color = vec3(0.0);
|
135
|
-
float total_weight = 0.0;
|
136
|
-
for (float y = -radius; y < radius; y += 1.0)
|
137
|
-
for (float x = -radius; x < radius; x += 1.0) {
|
138
|
-
vec2 offset = vec2(x, y);
|
139
|
-
float weight = gaussian(offset, sigma);
|
140
|
-
vec2 texcoord = vertTexCoord.xy + offset * texOffset.xy;
|
141
|
-
if (
|
142
|
-
texcoord.x < texMin.x || texMax.x < texcoord.x ||
|
143
|
-
texcoord.y < texMin.y || texMax.y < texcoord.y
|
144
|
-
) continue;
|
145
|
-
color += texture2D(texMap, texcoord).rgb * weight;
|
146
|
-
total_weight += weight;
|
147
|
-
}
|
148
|
-
gl_FragColor = vec4(color / total_weight, 1.0) * vertColor;
|
172
|
+
mainImage(gl_FragColor, vertTexCoord.xy);
|
149
173
|
}
|
150
174
|
END
|
151
|
-
else
|
152
|
-
nil
|
153
175
|
end
|
176
|
+
{
|
177
|
+
iTime: :float,
|
178
|
+
iResolution: :vec2,
|
179
|
+
iMouse: :vec2
|
180
|
+
}.each do |uniformName, type|
|
181
|
+
if needsUniformDeclaration type, uniformName, source
|
182
|
+
source = <<~END + source
|
183
|
+
uniform #{type} #{uniformName};
|
184
|
+
END
|
185
|
+
end
|
186
|
+
end
|
187
|
+
source
|
188
|
+
end
|
189
|
+
|
190
|
+
def hasShadertoyMainImage?(source)
|
191
|
+
source =~ /void\s+mainImage\s*\(\s*out\s+vec4\s+\w+\s*,\s*in\s+vec2\s+\w+\s*\)/
|
192
|
+
end
|
193
|
+
|
194
|
+
def needsUniformDeclaration(type, uniformName, source)
|
195
|
+
source.include?(uniformName.to_s) &&
|
196
|
+
source !~ /uniform\s+#{type}\s+#{uniformName}/
|
154
197
|
end
|
155
198
|
|
156
199
|
end# Shader
|
data/lib/processing/window.rb
CHANGED
@@ -20,7 +20,7 @@ module Processing
|
|
20
20
|
@events = []
|
21
21
|
@error = nil
|
22
22
|
@auto_resize = true
|
23
|
-
@canvas = Canvas.new self
|
23
|
+
@canvas = Canvas.new self, width, height
|
24
24
|
@canvas_view = add CanvasView.new name: :canvas
|
25
25
|
@overlay_view = @canvas_view.add Reflex::View.new name: :overlay
|
26
26
|
|
@@ -204,11 +204,11 @@ module Processing
|
|
204
204
|
|
205
205
|
attr_reader :image, :painter
|
206
206
|
|
207
|
-
def initialize(window)
|
207
|
+
def initialize(window, width, height)
|
208
208
|
@image = nil
|
209
209
|
@painter = window.painter
|
210
210
|
|
211
|
-
resize
|
211
|
+
resize width, height
|
212
212
|
painter.miter_limit = 10
|
213
213
|
end
|
214
214
|
|
data/lib/processing.rb
CHANGED
@@ -2,7 +2,9 @@ require 'processing/all'
|
|
2
2
|
|
3
3
|
|
4
4
|
module Processing
|
5
|
-
|
5
|
+
w = (ENV['WIDTH'] || 500).to_i
|
6
|
+
h = (ENV['HEIGHT'] || 500).to_i
|
7
|
+
WINDOW = Processing::Window.new(w, h) {start}
|
6
8
|
CONTEXT = Processing::Context.new WINDOW
|
7
9
|
|
8
10
|
refine Object do
|
data/processing.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_runtime_dependency 'xot', '~> 0.1.38'
|
29
29
|
s.add_runtime_dependency 'rucy', '~> 0.1.38'
|
30
30
|
s.add_runtime_dependency 'rays', '~> 0.1.39'
|
31
|
-
s.add_runtime_dependency 'reflexion', '~> 0.1.
|
31
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1.42'
|
32
32
|
|
33
33
|
s.add_development_dependency 'rake'
|
34
34
|
s.add_development_dependency 'test-unit'
|
data/test/test_shader.rb
CHANGED
@@ -41,6 +41,20 @@ class TestShader < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_shadertoy_shader()
|
45
|
+
assert_equal <<~EXPECTED, shader(nil, <<~ACTUAL).instance_variable_get(:@shader).fragment_shader_source
|
46
|
+
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
|
47
|
+
}
|
48
|
+
varying vec4 vertTexCoord;
|
49
|
+
void main() {
|
50
|
+
mainImage(gl_FragColor, vertTexCoord.xy);
|
51
|
+
}
|
52
|
+
EXPECTED
|
53
|
+
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
|
54
|
+
}
|
55
|
+
ACTUAL
|
56
|
+
end
|
57
|
+
|
44
58
|
def test_inspect()
|
45
59
|
assert_match %r|#<Processing::Shader:0x\w{16}>|, shader.inspect
|
46
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.42
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.42
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|