rbgl 0.1.0 → 1.0.1
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/.rubocop.yml +3 -0
- data/CHANGELOG.md +20 -2
- data/README.md +130 -74
- data/Rakefile +7 -0
- data/bench/renderer_bench.rb +283 -0
- data/docs/.nojekyll +1 -0
- data/docs/index.html +38 -0
- data/examples/array_test.rb +1 -1
- data/examples/color_test.rb +1 -1
- data/examples/cube_spinning.rb +1 -1
- data/examples/gradient.rb +1 -1
- data/examples/multi_return_test.rb +1 -1
- data/examples/plasma.rb +1 -1
- data/examples/sphere_raymarch.rb +1 -1
- data/examples/triangle_window.rb +1 -1
- data/exe/rbgl +42 -0
- data/lib/rbgl/cli/doctor.rb +155 -0
- data/lib/rbgl/engine/buffer.rb +150 -40
- data/lib/rbgl/engine/clip_space_clipper.rb +163 -0
- data/lib/rbgl/engine/context.rb +133 -63
- data/lib/rbgl/engine/framebuffer.rb +153 -48
- data/lib/rbgl/engine/immutable_color.rb +32 -0
- data/lib/rbgl/engine/pipeline.rb +38 -7
- data/lib/rbgl/engine/rasterizer/attribute_interpolator.rb +195 -0
- data/lib/rbgl/engine/rasterizer/line_renderer.rb +88 -0
- data/lib/rbgl/engine/rasterizer/point_renderer.rb +35 -0
- data/lib/rbgl/engine/rasterizer/triangle_renderer.rb +136 -0
- data/lib/rbgl/engine/rasterizer.rb +65 -171
- data/lib/rbgl/engine/shader/base_shader.rb +51 -0
- data/lib/rbgl/engine/shader/builtins.rb +257 -0
- data/lib/rbgl/engine/shader/dynamic_data.rb +73 -0
- data/lib/rbgl/engine/shader.rb +5 -318
- data/lib/rbgl/engine/texture.rb +264 -51
- data/lib/rbgl/engine.rb +4 -1
- data/lib/rbgl/gui/backend.rb +21 -34
- data/lib/rbgl/gui/backend_factory.rb +89 -0
- data/lib/rbgl/gui/cocoa/backend.rb +59 -46
- data/lib/rbgl/gui/cocoa/key_mapper.rb +48 -0
- data/lib/rbgl/gui/event.rb +4 -2
- data/lib/rbgl/gui/file_backend/bmp_writer.rb +63 -0
- data/lib/rbgl/gui/file_backend/frame_writer.rb +35 -0
- data/lib/rbgl/gui/file_backend/png_writer.rb +18 -0
- data/lib/rbgl/gui/file_backend/ppm_writer.rb +26 -0
- data/lib/rbgl/gui/file_backend.rb +50 -55
- data/lib/rbgl/gui/wayland/backend.rb +214 -60
- data/lib/rbgl/gui/wayland/codec.rb +50 -0
- data/lib/rbgl/gui/wayland/connection.rb +188 -231
- data/lib/rbgl/gui/wayland/event_dispatcher.rb +165 -0
- data/lib/rbgl/gui/wayland/global_binder.rb +46 -0
- data/lib/rbgl/gui/wayland/input_mapper.rb +61 -0
- data/lib/rbgl/gui/wayland/protocol_objects/arguments.rb +63 -0
- data/lib/rbgl/gui/wayland/protocol_objects/display.rb +54 -0
- data/lib/rbgl/gui/wayland/protocol_objects/seat.rb +115 -0
- data/lib/rbgl/gui/wayland/protocol_objects/shm.rb +157 -0
- data/lib/rbgl/gui/wayland/protocol_objects/surface.rb +33 -0
- data/lib/rbgl/gui/wayland/protocol_objects/xdg_shell.rb +60 -0
- data/lib/rbgl/gui/wayland/protocol_objects.rb +8 -0
- data/lib/rbgl/gui/window/event_dispatcher.rb +30 -0
- data/lib/rbgl/gui/window/render_loop.rb +111 -0
- data/lib/rbgl/gui/window.rb +74 -84
- data/lib/rbgl/gui/x11/atom_cache.rb +29 -0
- data/lib/rbgl/gui/x11/backend.rb +73 -49
- data/lib/rbgl/gui/x11/connection.rb +284 -219
- data/lib/rbgl/gui/x11/event_parser.rb +71 -0
- data/lib/rbgl/gui/x11/key_mapper.rb +48 -0
- data/lib/rbgl/gui/x11/pixel_encoder.rb +164 -0
- data/lib/rbgl/gui/x11/request_encoder.rb +155 -0
- data/lib/rbgl/gui/x11/setup_parser.rb +138 -0
- data/lib/rbgl/gui/x11/transport.rb +81 -0
- data/lib/rbgl/gui/x11/x_authority.rb +107 -0
- data/lib/rbgl/gui.rb +3 -5
- data/lib/rbgl/version.rb +1 -1
- metadata +63 -24
- data/examples/chemical_heartbeat.rb +0 -166
- data/examples/dark_transit.rb +0 -166
- data/examples/fractured_orb.rb +0 -428
- data/examples/fractured_orb_rb.rb +0 -598
- data/examples/hexagonal_flow.rb +0 -333
- data/examples/teapot.rb +0 -362
- data/examples/teapot_mcu.rb +0 -344
data/lib/rbgl/gui.rb
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "version"
|
|
3
4
|
require_relative "gui/event"
|
|
4
5
|
require_relative "gui/backend"
|
|
6
|
+
require_relative "gui/backend_factory"
|
|
5
7
|
require_relative "gui/file_backend"
|
|
6
8
|
require_relative "gui/window"
|
|
7
9
|
|
|
8
10
|
module RBGL
|
|
9
11
|
module GUI
|
|
10
|
-
VERSION =
|
|
11
|
-
|
|
12
|
-
def self.load_tk_backend
|
|
13
|
-
require_relative "gui/tk_backend"
|
|
14
|
-
end
|
|
12
|
+
VERSION = RBGL::VERSION
|
|
15
13
|
end
|
|
16
14
|
end
|
data/lib/rbgl/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,98 +1,136 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbgl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yudai Takada
|
|
8
|
-
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-09-25 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: larb
|
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
|
15
16
|
requirements:
|
|
16
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
17
18
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0'
|
|
19
|
+
version: '1.0'
|
|
19
20
|
type: :runtime
|
|
20
21
|
prerelease: false
|
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
23
|
requirements:
|
|
23
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '0'
|
|
26
|
+
version: '1.0'
|
|
26
27
|
- !ruby/object:Gem::Dependency
|
|
27
28
|
name: rlsl
|
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
|
29
30
|
requirements:
|
|
30
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
31
32
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
+
version: '1.0'
|
|
33
34
|
type: :runtime
|
|
34
35
|
prerelease: false
|
|
35
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
37
|
requirements:
|
|
37
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
38
39
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
|
+
version: '1.0'
|
|
40
41
|
description: A pure Ruby graphics library with software rendering engine and cross-platform
|
|
41
42
|
GUI support (X11, Wayland, Cocoa).
|
|
42
43
|
email:
|
|
43
44
|
- t.yudai92@gmail.com
|
|
44
|
-
executables:
|
|
45
|
+
executables:
|
|
46
|
+
- rbgl
|
|
45
47
|
extensions: []
|
|
46
48
|
extra_rdoc_files: []
|
|
47
49
|
files:
|
|
50
|
+
- ".rubocop.yml"
|
|
48
51
|
- CHANGELOG.md
|
|
49
52
|
- LICENSE
|
|
50
53
|
- README.md
|
|
51
54
|
- Rakefile
|
|
55
|
+
- bench/renderer_bench.rb
|
|
56
|
+
- docs/.nojekyll
|
|
57
|
+
- docs/index.html
|
|
52
58
|
- examples/array_test.rb
|
|
53
|
-
- examples/chemical_heartbeat.rb
|
|
54
59
|
- examples/color_test.rb
|
|
55
60
|
- examples/cube_spinning.rb
|
|
56
|
-
- examples/dark_transit.rb
|
|
57
|
-
- examples/fractured_orb.rb
|
|
58
|
-
- examples/fractured_orb_rb.rb
|
|
59
61
|
- examples/gradient.rb
|
|
60
|
-
- examples/hexagonal_flow.rb
|
|
61
62
|
- examples/multi_return_test.rb
|
|
62
63
|
- examples/plasma.rb
|
|
63
64
|
- examples/sphere_raymarch.rb
|
|
64
|
-
- examples/teapot.rb
|
|
65
|
-
- examples/teapot_mcu.rb
|
|
66
65
|
- examples/triangle_basic.rb
|
|
67
66
|
- examples/triangle_window.rb
|
|
68
67
|
- examples/window_test.rb
|
|
68
|
+
- exe/rbgl
|
|
69
69
|
- lib/rbgl.rb
|
|
70
|
+
- lib/rbgl/cli/doctor.rb
|
|
70
71
|
- lib/rbgl/engine.rb
|
|
71
72
|
- lib/rbgl/engine/buffer.rb
|
|
73
|
+
- lib/rbgl/engine/clip_space_clipper.rb
|
|
72
74
|
- lib/rbgl/engine/context.rb
|
|
73
75
|
- lib/rbgl/engine/framebuffer.rb
|
|
76
|
+
- lib/rbgl/engine/immutable_color.rb
|
|
74
77
|
- lib/rbgl/engine/pipeline.rb
|
|
75
78
|
- lib/rbgl/engine/rasterizer.rb
|
|
79
|
+
- lib/rbgl/engine/rasterizer/attribute_interpolator.rb
|
|
80
|
+
- lib/rbgl/engine/rasterizer/line_renderer.rb
|
|
81
|
+
- lib/rbgl/engine/rasterizer/point_renderer.rb
|
|
82
|
+
- lib/rbgl/engine/rasterizer/triangle_renderer.rb
|
|
76
83
|
- lib/rbgl/engine/shader.rb
|
|
84
|
+
- lib/rbgl/engine/shader/base_shader.rb
|
|
85
|
+
- lib/rbgl/engine/shader/builtins.rb
|
|
86
|
+
- lib/rbgl/engine/shader/dynamic_data.rb
|
|
77
87
|
- lib/rbgl/engine/texture.rb
|
|
78
88
|
- lib/rbgl/gui.rb
|
|
79
89
|
- lib/rbgl/gui/backend.rb
|
|
90
|
+
- lib/rbgl/gui/backend_factory.rb
|
|
80
91
|
- lib/rbgl/gui/cocoa/backend.rb
|
|
92
|
+
- lib/rbgl/gui/cocoa/key_mapper.rb
|
|
81
93
|
- lib/rbgl/gui/event.rb
|
|
82
94
|
- lib/rbgl/gui/file_backend.rb
|
|
95
|
+
- lib/rbgl/gui/file_backend/bmp_writer.rb
|
|
96
|
+
- lib/rbgl/gui/file_backend/frame_writer.rb
|
|
97
|
+
- lib/rbgl/gui/file_backend/png_writer.rb
|
|
98
|
+
- lib/rbgl/gui/file_backend/ppm_writer.rb
|
|
83
99
|
- lib/rbgl/gui/wayland/backend.rb
|
|
100
|
+
- lib/rbgl/gui/wayland/codec.rb
|
|
84
101
|
- lib/rbgl/gui/wayland/connection.rb
|
|
102
|
+
- lib/rbgl/gui/wayland/event_dispatcher.rb
|
|
103
|
+
- lib/rbgl/gui/wayland/global_binder.rb
|
|
104
|
+
- lib/rbgl/gui/wayland/input_mapper.rb
|
|
105
|
+
- lib/rbgl/gui/wayland/protocol_objects.rb
|
|
106
|
+
- lib/rbgl/gui/wayland/protocol_objects/arguments.rb
|
|
107
|
+
- lib/rbgl/gui/wayland/protocol_objects/display.rb
|
|
108
|
+
- lib/rbgl/gui/wayland/protocol_objects/seat.rb
|
|
109
|
+
- lib/rbgl/gui/wayland/protocol_objects/shm.rb
|
|
110
|
+
- lib/rbgl/gui/wayland/protocol_objects/surface.rb
|
|
111
|
+
- lib/rbgl/gui/wayland/protocol_objects/xdg_shell.rb
|
|
85
112
|
- lib/rbgl/gui/window.rb
|
|
113
|
+
- lib/rbgl/gui/window/event_dispatcher.rb
|
|
114
|
+
- lib/rbgl/gui/window/render_loop.rb
|
|
115
|
+
- lib/rbgl/gui/x11/atom_cache.rb
|
|
86
116
|
- lib/rbgl/gui/x11/backend.rb
|
|
87
117
|
- lib/rbgl/gui/x11/connection.rb
|
|
118
|
+
- lib/rbgl/gui/x11/event_parser.rb
|
|
119
|
+
- lib/rbgl/gui/x11/key_mapper.rb
|
|
120
|
+
- lib/rbgl/gui/x11/pixel_encoder.rb
|
|
121
|
+
- lib/rbgl/gui/x11/request_encoder.rb
|
|
122
|
+
- lib/rbgl/gui/x11/setup_parser.rb
|
|
123
|
+
- lib/rbgl/gui/x11/transport.rb
|
|
124
|
+
- lib/rbgl/gui/x11/x_authority.rb
|
|
88
125
|
- lib/rbgl/version.rb
|
|
89
|
-
homepage: https://github.
|
|
126
|
+
homepage: https://rbgfx.github.io/rbgl/
|
|
90
127
|
licenses:
|
|
91
128
|
- MIT
|
|
92
129
|
metadata:
|
|
93
|
-
homepage_uri: https://github.
|
|
94
|
-
source_code_uri: https://github.com/
|
|
95
|
-
changelog_uri: https://github.com/
|
|
130
|
+
homepage_uri: https://rbgfx.github.io/rbgl/
|
|
131
|
+
source_code_uri: https://github.com/rbgfx/rbgl/tree/main
|
|
132
|
+
changelog_uri: https://github.com/rbgfx/rbgl/blob/main/CHANGELOG.md
|
|
133
|
+
post_install_message:
|
|
96
134
|
rdoc_options: []
|
|
97
135
|
require_paths:
|
|
98
136
|
- lib
|
|
@@ -107,7 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
145
|
- !ruby/object:Gem::Version
|
|
108
146
|
version: '0'
|
|
109
147
|
requirements: []
|
|
110
|
-
rubygems_version: 4.
|
|
148
|
+
rubygems_version: 3.4.19
|
|
149
|
+
signing_key:
|
|
111
150
|
specification_version: 4
|
|
112
151
|
summary: RuBy Graphics Library - Pure Ruby software rendering with cross-platform
|
|
113
152
|
GUI
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# chemical heartbeat
|
|
4
|
-
# Original: https://www.shadertoy.com/view/lXtXD4
|
|
5
|
-
# License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
|
6
|
-
# https://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
|
|
7
|
-
|
|
8
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
|
9
|
-
|
|
10
|
-
require "rbgl"
|
|
11
|
-
require "rlsl"
|
|
12
|
-
|
|
13
|
-
WIDTH = 640
|
|
14
|
-
HEIGHT = 480
|
|
15
|
-
|
|
16
|
-
# Define shader using pure Ruby DSL
|
|
17
|
-
shader = RLSL.define(:chemical_heartbeat) do
|
|
18
|
-
uniforms do
|
|
19
|
-
float :time
|
|
20
|
-
float :camera_x
|
|
21
|
-
float :camera_y
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
fragment do |frag_coord, resolution, u|
|
|
25
|
-
uv = frag_coord / resolution.y
|
|
26
|
-
|
|
27
|
-
# Constants
|
|
28
|
-
inv_hex_size = 50.0
|
|
29
|
-
sqrt3_div3 = 0.5773502691896257
|
|
30
|
-
one_div3 = 0.3333333333333333
|
|
31
|
-
two_div3 = 0.6666666666666666
|
|
32
|
-
inv_warp_grid = 5.0
|
|
33
|
-
warp_clamp = 1.7
|
|
34
|
-
warp_scale = 4.4
|
|
35
|
-
warp_amplitude = 0.015
|
|
36
|
-
warp_speed = 1.5
|
|
37
|
-
time_dilation = 0.2
|
|
38
|
-
|
|
39
|
-
# Colors
|
|
40
|
-
color_a = vec3(58.0 / 255.0, 1.0 / 255.0, 92.0 / 255.0)
|
|
41
|
-
color_b = vec3(201.0 / 255.0, 100.0 / 255.0, 128.0 / 255.0)
|
|
42
|
-
color_c = vec3(59.0 / 255.0, 206.0 / 255.0, 172.0 / 255.0)
|
|
43
|
-
color_d = vec3(17.0 / 255.0, 0.0 / 255.0, 28.0 / 255.0)
|
|
44
|
-
|
|
45
|
-
# Apply camera offset
|
|
46
|
-
base_ux = uv.x - 0.5 + u.camera_x
|
|
47
|
-
base_uy = uv.y - 0.5 + u.camera_y
|
|
48
|
-
|
|
49
|
-
# Zoomy warp
|
|
50
|
-
pos_x = base_ux * inv_warp_grid
|
|
51
|
-
pos_y = base_uy * inv_warp_grid
|
|
52
|
-
ax = floor(pos_x)
|
|
53
|
-
ay = floor(pos_y)
|
|
54
|
-
|
|
55
|
-
hash_a = hash21(vec2(ax, ay))
|
|
56
|
-
hash_b = hash21(vec2(ax + 1.0, ay))
|
|
57
|
-
hash_c = hash21(vec2(ax, ay + 1.0))
|
|
58
|
-
hash_d = hash21(vec2(ax + 1.0, ay + 1.0))
|
|
59
|
-
|
|
60
|
-
diff_x = pos_x - ax
|
|
61
|
-
diff_y = pos_y - ay
|
|
62
|
-
|
|
63
|
-
warp = hash_a + (hash_b - hash_a) * diff_x
|
|
64
|
-
warp = warp + ((hash_c + (hash_d - hash_c) * diff_x) - warp) * diff_y
|
|
65
|
-
warp = warp + u.time * warp_speed
|
|
66
|
-
|
|
67
|
-
smoothed = (1.0 + cos(warp * TAU)) * 0.5
|
|
68
|
-
clamped = smoothed * warp_scale - warp_clamp
|
|
69
|
-
clamped = clamp(clamped, 0.0, 1.0)
|
|
70
|
-
|
|
71
|
-
ux = base_ux + cos(clamped) * warp_amplitude
|
|
72
|
-
uy = base_uy + sin(clamped) * warp_amplitude
|
|
73
|
-
|
|
74
|
-
# Axial from pixel
|
|
75
|
-
axial_q = (sqrt3_div3 * ux - one_div3 * uy) * inv_hex_size
|
|
76
|
-
axial_r = two_div3 * uy * inv_hex_size
|
|
77
|
-
axial_s = 0.0 - axial_q - axial_r
|
|
78
|
-
|
|
79
|
-
# Axial round
|
|
80
|
-
q = floor(axial_q)
|
|
81
|
-
r = floor(axial_r)
|
|
82
|
-
s = floor(axial_s)
|
|
83
|
-
|
|
84
|
-
q_diff = abs(q - axial_q)
|
|
85
|
-
r_diff = abs(r - axial_r)
|
|
86
|
-
s_diff = abs(s - axial_s)
|
|
87
|
-
|
|
88
|
-
if q_diff > r_diff && q_diff > s_diff
|
|
89
|
-
q = 0.0 - r - s
|
|
90
|
-
elsif r_diff > s_diff
|
|
91
|
-
r = 0.0 - q - s
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Hash for hex cell
|
|
95
|
-
hash_val = hash21(vec2(q, r))
|
|
96
|
-
|
|
97
|
-
# Animated color value
|
|
98
|
-
value = fract(hash_val + u.time * time_dilation)
|
|
99
|
-
value = smoothstep(0.0, 1.0, value)
|
|
100
|
-
value = (1.0 + cos(value * TAU)) * 0.5
|
|
101
|
-
|
|
102
|
-
# Color mixing
|
|
103
|
-
ab = mix(color_a, color_b, value)
|
|
104
|
-
bc = mix(color_b, color_c, value)
|
|
105
|
-
cd = mix(color_c, color_d, value)
|
|
106
|
-
|
|
107
|
-
left = mix(ab, bc, value)
|
|
108
|
-
right = mix(bc, cd, value)
|
|
109
|
-
|
|
110
|
-
mix(left, right, value)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# Initialize display
|
|
115
|
-
window = RBGL::GUI::Window.new(width: WIDTH, height: HEIGHT, title: "Chemical Heartbeat")
|
|
116
|
-
|
|
117
|
-
puts "Chemical Heartbeat"
|
|
118
|
-
puts "Original: https://www.shadertoy.com/view/lXtXD4"
|
|
119
|
-
puts "License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0"
|
|
120
|
-
puts "https://creativecommons.org/licenses/by-nc-sa/3.0/deed.en"
|
|
121
|
-
puts "Press 'q' or Escape to quit"
|
|
122
|
-
|
|
123
|
-
start_time = Time.now
|
|
124
|
-
frame_count = 0
|
|
125
|
-
last_fps_time = start_time
|
|
126
|
-
running = true
|
|
127
|
-
|
|
128
|
-
buffer = "\x00" * (WIDTH * HEIGHT * 4)
|
|
129
|
-
|
|
130
|
-
while running && !window.should_close?
|
|
131
|
-
time = Time.now - start_time
|
|
132
|
-
|
|
133
|
-
# Camera movement
|
|
134
|
-
circle_value = time * 0.1
|
|
135
|
-
wave_value = time * 0.33
|
|
136
|
-
radius = 1.0 + Math.cos(wave_value) * 0.25
|
|
137
|
-
camera_x = Math.cos(circle_value) * radius
|
|
138
|
-
camera_y = Math.sin(circle_value) * radius
|
|
139
|
-
|
|
140
|
-
# Render using compiled shader
|
|
141
|
-
shader.render(buffer, WIDTH, HEIGHT, {
|
|
142
|
-
time: time,
|
|
143
|
-
camera_x: camera_x,
|
|
144
|
-
camera_y: camera_y
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
window.set_pixels(buffer)
|
|
148
|
-
|
|
149
|
-
events = window.poll_events_raw
|
|
150
|
-
events.each do |e|
|
|
151
|
-
if e[:type] == :key_press && (e[:key] == 12 || e[:key] == "q")
|
|
152
|
-
running = false
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
frame_count += 1
|
|
157
|
-
now = Time.now
|
|
158
|
-
if now - last_fps_time >= 1.0
|
|
159
|
-
fps = frame_count / (now - last_fps_time)
|
|
160
|
-
puts "FPS: #{fps.round(1)}"
|
|
161
|
-
frame_count = 0
|
|
162
|
-
last_fps_time = now
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
window.close
|
data/examples/dark_transit.rb
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Dark Transit
|
|
4
|
-
# Original: https://www.shadertoy.com/view/WcdczB
|
|
5
|
-
# 28 steps raymarching tunnel
|
|
6
|
-
# License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
|
7
|
-
# https://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
|
|
8
|
-
|
|
9
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
|
10
|
-
|
|
11
|
-
require "rbgl"
|
|
12
|
-
require "rlsl"
|
|
13
|
-
|
|
14
|
-
WIDTH = 640
|
|
15
|
-
HEIGHT = 480
|
|
16
|
-
|
|
17
|
-
shader = RLSL.define(:dark_transit) do
|
|
18
|
-
uniforms do
|
|
19
|
-
float :time
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Register helper function signatures for Ruby mode
|
|
23
|
-
functions do
|
|
24
|
-
define :get_t, returns: :float, params: { time: :float }
|
|
25
|
-
define :path_point, returns: :vec3, params: { z: :float }
|
|
26
|
-
define :noise_a, returns: :float, params: { f: :float, h: :float, k: :float, p: :vec3 }
|
|
27
|
-
define :cross_prod, returns: :vec3, params: { a: :vec3, b: :vec3 }
|
|
28
|
-
define :mat3_mul, returns: :vec3, params: { c0: :vec3, c1: :vec3, c2: :vec3, v: :vec3 }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
helpers do
|
|
32
|
-
def get_t(time)
|
|
33
|
-
time * 4.0 + 5.0 + 5.0 * sin(time * 0.3)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def path_point(z)
|
|
37
|
-
vec3(12.0 * cos(z * 0.1), 12.0 * cos(z * 0.12), z)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def noise_a(f, h, k, p)
|
|
41
|
-
abs(h * (sin(f * p.x * k) + sin(f * p.y * k) + sin(f * p.z * k))) / k
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def cross_prod(a, b)
|
|
45
|
-
vec3(
|
|
46
|
-
a.y * b.z - a.z * b.y,
|
|
47
|
-
a.z * b.x - a.x * b.z,
|
|
48
|
-
a.x * b.y - a.y * b.x
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def mat3_mul(c0, c1, c2, v)
|
|
53
|
-
vec3(
|
|
54
|
-
c0.x * v.x + c1.x * v.y + c2.x * v.z,
|
|
55
|
-
c0.y * v.x + c1.y * v.y + c2.y * v.z,
|
|
56
|
-
c0.z * v.x + c1.z * v.y + c2.z * v.z
|
|
57
|
-
)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
fragment do |frag_coord, resolution, u|
|
|
62
|
-
i_time = u.time
|
|
63
|
-
t_val = get_t(i_time)
|
|
64
|
-
|
|
65
|
-
# Scaled coords
|
|
66
|
-
screen_uv = vec2(
|
|
67
|
-
(frag_coord.x - resolution.x * 0.5) / resolution.y,
|
|
68
|
-
(frag_coord.y - resolution.y * 0.5) / resolution.y
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
# Cinema bars
|
|
72
|
-
if abs(screen_uv.y) > 0.375
|
|
73
|
-
vec3(0.0, 0.0, 0.0)
|
|
74
|
-
else
|
|
75
|
-
# Setup variables
|
|
76
|
-
t = 0.0
|
|
77
|
-
s = 0.0
|
|
78
|
-
i = 0.0
|
|
79
|
-
d = 0.0
|
|
80
|
-
e = 0.0
|
|
81
|
-
c = vec3(0.0, 0.0, 0.0)
|
|
82
|
-
|
|
83
|
-
# Camera path
|
|
84
|
-
p = path_point(t_val)
|
|
85
|
-
z_dir = normalize(path_point(t_val + 4.0) - p)
|
|
86
|
-
x_dir = normalize(vec3(z_dir.z, 0.0, 0.0 - z_dir.x))
|
|
87
|
-
|
|
88
|
-
# View matrix
|
|
89
|
-
neg_x = vec3(0.0 - x_dir.x, 0.0 - x_dir.y, 0.0 - x_dir.z)
|
|
90
|
-
cross_xz = cross_prod(x_dir, z_dir)
|
|
91
|
-
ray_d = mat3_mul(neg_x, cross_xz, z_dir, vec3(screen_uv.x, screen_uv.y, 1.0))
|
|
92
|
-
|
|
93
|
-
# Raymarching loop
|
|
94
|
-
while i < 28.0 && d < 30.0
|
|
95
|
-
i = i + 1.0
|
|
96
|
-
p = p + ray_d * s
|
|
97
|
-
x_dir = path_point(p.z)
|
|
98
|
-
t = sin(i_time)
|
|
99
|
-
|
|
100
|
-
# Orb position
|
|
101
|
-
orb = vec3(x_dir.x + t, x_dir.y + t * 2.0, 6.0 + t_val + t * 2.0)
|
|
102
|
-
e = length(p - orb) - 0.01
|
|
103
|
-
|
|
104
|
-
# Tunnel distance
|
|
105
|
-
px_offset = x_dir.x + 6.0
|
|
106
|
-
d1 = length(vec2(p.x - px_offset, p.y - px_offset))
|
|
107
|
-
d2 = length(vec2(p.x - x_dir.x, p.y - x_dir.y))
|
|
108
|
-
|
|
109
|
-
s = cos(p.z * 0.6) * 2.0 + 4.0 - min(d1, d2) + noise_a(4.0, 0.25, 0.1, p) + noise_a(8.0, 0.22, 2.0, p)
|
|
110
|
-
s = min(e, 0.01 + 0.25 * abs(s))
|
|
111
|
-
d = d + s
|
|
112
|
-
|
|
113
|
-
# Accumulate color
|
|
114
|
-
inv_s = 1.0 / s
|
|
115
|
-
inv_e = 10.0 / max(e, 0.6)
|
|
116
|
-
c = vec3(c.x + inv_s + inv_e, c.y + inv_s + inv_e * 2.0, c.z + inv_s + inv_e * 5.0)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# Output color
|
|
120
|
-
vec3(c.x * c.x / 1000000.0, c.y * c.y / 1000000.0, c.z * c.z / 1000000.0)
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# Initialize display
|
|
126
|
-
window = RBGL::GUI::Window.new(width: WIDTH, height: HEIGHT, title: "Dark Transit")
|
|
127
|
-
|
|
128
|
-
puts "Dark Transit"
|
|
129
|
-
puts "Original: https://www.shadertoy.com/view/WcdczB"
|
|
130
|
-
puts "License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0"
|
|
131
|
-
puts "https://creativecommons.org/licenses/by-nc-sa/3.0/deed.en"
|
|
132
|
-
puts "Press 'q' or Escape to quit"
|
|
133
|
-
|
|
134
|
-
start_time = Time.now
|
|
135
|
-
frame_count = 0
|
|
136
|
-
last_fps_time = start_time
|
|
137
|
-
running = true
|
|
138
|
-
|
|
139
|
-
buffer = "\x00" * (WIDTH * HEIGHT * 4)
|
|
140
|
-
|
|
141
|
-
while running && !window.should_close?
|
|
142
|
-
time = Time.now - start_time
|
|
143
|
-
|
|
144
|
-
shader.render(buffer, WIDTH, HEIGHT, { time: time })
|
|
145
|
-
|
|
146
|
-
window.set_pixels(buffer)
|
|
147
|
-
|
|
148
|
-
events = window.poll_events_raw
|
|
149
|
-
events.each do |e|
|
|
150
|
-
case e[:type]
|
|
151
|
-
when :key_press
|
|
152
|
-
running = false if e[:key] == 12 || e[:key] == "q"
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
frame_count += 1
|
|
157
|
-
now = Time.now
|
|
158
|
-
if now - last_fps_time >= 1.0
|
|
159
|
-
fps = frame_count / (now - last_fps_time)
|
|
160
|
-
puts "FPS: #{fps.round(1)}"
|
|
161
|
-
frame_count = 0
|
|
162
|
-
last_fps_time = now
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
window.close
|