3rb 0.1.0
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 +7 -0
- data/.rspec +2 -0
- data/3rb.gemspec +29 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE +21 -0
- data/README.md +321 -0
- data/Rakefile +13 -0
- data/examples/01_hello_cube.rb +29 -0
- data/examples/02_basic_geometries.rb +56 -0
- data/examples/03_materials.rb +61 -0
- data/examples/04_lighting.rb +63 -0
- data/examples/05_animation.rb +79 -0
- data/examples/06_custom_shader.rb +92 -0
- data/examples/07_scene_graph.rb +74 -0
- data/examples/08_orbit_controls.rb +50 -0
- data/examples/09_3d_chart.rb +71 -0
- data/examples/10_procedural_terrain.rb +140 -0
- data/examples/11_particle_system.rb +68 -0
- data/examples/12_model_loader.rb +73 -0
- data/examples/13_game_prototype.rb +145 -0
- data/examples/14_utah_teapot.rb +291 -0
- data/examples/15_stanford_bunny.rb +200 -0
- data/examples/16_cornell_box.rb +373 -0
- data/examples/17_weird_fractal4.rb +130 -0
- data/examples/18_platonic_solids.rb +268 -0
- data/lib/3rb/animation/animation_clip.rb +287 -0
- data/lib/3rb/animation/animation_mixer.rb +366 -0
- data/lib/3rb/cameras/camera.rb +50 -0
- data/lib/3rb/cameras/orthographic_camera.rb +92 -0
- data/lib/3rb/cameras/perspective_camera.rb +103 -0
- data/lib/3rb/controls/orbit_controls.rb +341 -0
- data/lib/3rb/core/buffer_attribute.rb +172 -0
- data/lib/3rb/core/group.rb +9 -0
- data/lib/3rb/core/object3d.rb +298 -0
- data/lib/3rb/core/scene.rb +78 -0
- data/lib/3rb/dsl/helpers.rb +57 -0
- data/lib/3rb/dsl/scene_builder.rb +288 -0
- data/lib/3rb/ffi/glfw.rb +61 -0
- data/lib/3rb/ffi/opengl.rb +137 -0
- data/lib/3rb/ffi/platform.rb +65 -0
- data/lib/3rb/geometries/box_geometry.rb +101 -0
- data/lib/3rb/geometries/buffer_geometry.rb +345 -0
- data/lib/3rb/geometries/cone_geometry.rb +29 -0
- data/lib/3rb/geometries/cylinder_geometry.rb +149 -0
- data/lib/3rb/geometries/plane_geometry.rb +75 -0
- data/lib/3rb/geometries/sphere_geometry.rb +93 -0
- data/lib/3rb/geometries/torus_geometry.rb +77 -0
- data/lib/3rb/lights/ambient_light.rb +9 -0
- data/lib/3rb/lights/directional_light.rb +57 -0
- data/lib/3rb/lights/hemisphere_light.rb +26 -0
- data/lib/3rb/lights/light.rb +27 -0
- data/lib/3rb/lights/point_light.rb +68 -0
- data/lib/3rb/lights/rect_area_light.rb +35 -0
- data/lib/3rb/lights/spot_light.rb +88 -0
- data/lib/3rb/loaders/gltf_loader.rb +304 -0
- data/lib/3rb/loaders/loader.rb +94 -0
- data/lib/3rb/loaders/obj_loader.rb +186 -0
- data/lib/3rb/loaders/texture_loader.rb +55 -0
- data/lib/3rb/materials/basic_material.rb +70 -0
- data/lib/3rb/materials/lambert_material.rb +102 -0
- data/lib/3rb/materials/material.rb +114 -0
- data/lib/3rb/materials/phong_material.rb +106 -0
- data/lib/3rb/materials/shader_material.rb +104 -0
- data/lib/3rb/materials/standard_material.rb +106 -0
- data/lib/3rb/math/color.rb +246 -0
- data/lib/3rb/math/euler.rb +156 -0
- data/lib/3rb/math/math_utils.rb +132 -0
- data/lib/3rb/math/matrix3.rb +269 -0
- data/lib/3rb/math/matrix4.rb +501 -0
- data/lib/3rb/math/quaternion.rb +337 -0
- data/lib/3rb/math/vector2.rb +216 -0
- data/lib/3rb/math/vector3.rb +366 -0
- data/lib/3rb/math/vector4.rb +233 -0
- data/lib/3rb/native/gl.rb +382 -0
- data/lib/3rb/native/native.rb +55 -0
- data/lib/3rb/native/window.rb +111 -0
- data/lib/3rb/native.rb +9 -0
- data/lib/3rb/objects/line.rb +116 -0
- data/lib/3rb/objects/mesh.rb +40 -0
- data/lib/3rb/objects/points.rb +71 -0
- data/lib/3rb/renderers/opengl_renderer.rb +567 -0
- data/lib/3rb/renderers/renderer.rb +60 -0
- data/lib/3rb/renderers/shader_lib.rb +100 -0
- data/lib/3rb/textures/cube_texture.rb +26 -0
- data/lib/3rb/textures/data_texture.rb +35 -0
- data/lib/3rb/textures/render_target.rb +125 -0
- data/lib/3rb/textures/texture.rb +190 -0
- data/lib/3rb/version.rb +5 -0
- data/lib/3rb.rb +86 -0
- data/shaders/basic.frag +19 -0
- data/shaders/basic.vert +15 -0
- data/shaders/common/lights.glsl +53 -0
- data/shaders/common/uniforms.glsl +9 -0
- data/shaders/lambert.frag +37 -0
- data/shaders/lambert.vert +22 -0
- data/shaders/phong.frag +51 -0
- data/shaders/phong.vert +28 -0
- data/shaders/standard.frag +92 -0
- data/shaders/standard.vert +28 -0
- metadata +155 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class MeshBasicMaterial < Material
|
|
5
|
+
attr_accessor :color, :map
|
|
6
|
+
attr_accessor :light_map, :light_map_intensity
|
|
7
|
+
attr_accessor :ao_map, :ao_map_intensity
|
|
8
|
+
attr_accessor :specular_map, :alpha_map
|
|
9
|
+
attr_accessor :env_map, :combine, :reflectivity, :refraction_ratio
|
|
10
|
+
attr_accessor :wireframe, :wireframe_linewidth
|
|
11
|
+
|
|
12
|
+
MULTIPLY_OPERATION = 0
|
|
13
|
+
MIX_OPERATION = 1
|
|
14
|
+
ADD_OPERATION = 2
|
|
15
|
+
|
|
16
|
+
def initialize(color: 0xffffff, map: nil, wireframe: false)
|
|
17
|
+
super()
|
|
18
|
+
|
|
19
|
+
@color = color.is_a?(Color) ? color : Color.new(color)
|
|
20
|
+
@map = map
|
|
21
|
+
|
|
22
|
+
@light_map = nil
|
|
23
|
+
@light_map_intensity = 1.0
|
|
24
|
+
|
|
25
|
+
@ao_map = nil
|
|
26
|
+
@ao_map_intensity = 1.0
|
|
27
|
+
|
|
28
|
+
@specular_map = nil
|
|
29
|
+
@alpha_map = nil
|
|
30
|
+
|
|
31
|
+
@env_map = nil
|
|
32
|
+
@combine = MULTIPLY_OPERATION
|
|
33
|
+
@reflectivity = 1.0
|
|
34
|
+
@refraction_ratio = 0.98
|
|
35
|
+
|
|
36
|
+
@wireframe = wireframe
|
|
37
|
+
@wireframe_linewidth = 1
|
|
38
|
+
|
|
39
|
+
@lights = false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def copy(source)
|
|
43
|
+
super
|
|
44
|
+
@color = source.color.clone
|
|
45
|
+
@map = source.map
|
|
46
|
+
@light_map = source.light_map
|
|
47
|
+
@light_map_intensity = source.light_map_intensity
|
|
48
|
+
@ao_map = source.ao_map
|
|
49
|
+
@ao_map_intensity = source.ao_map_intensity
|
|
50
|
+
@specular_map = source.specular_map
|
|
51
|
+
@alpha_map = source.alpha_map
|
|
52
|
+
@env_map = source.env_map
|
|
53
|
+
@combine = source.combine
|
|
54
|
+
@reflectivity = source.reflectivity
|
|
55
|
+
@refraction_ratio = source.refraction_ratio
|
|
56
|
+
@wireframe = source.wireframe
|
|
57
|
+
@wireframe_linewidth = source.wireframe_linewidth
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_h
|
|
62
|
+
super.merge(
|
|
63
|
+
color: @color.get_hex,
|
|
64
|
+
wireframe: @wireframe
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
BasicMaterial = MeshBasicMaterial
|
|
70
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class MeshLambertMaterial < Material
|
|
5
|
+
attr_accessor :color, :map
|
|
6
|
+
attr_accessor :light_map, :light_map_intensity
|
|
7
|
+
attr_accessor :ao_map, :ao_map_intensity
|
|
8
|
+
attr_accessor :emissive, :emissive_intensity, :emissive_map
|
|
9
|
+
attr_accessor :bump_map, :bump_scale
|
|
10
|
+
attr_accessor :normal_map, :normal_map_type, :normal_scale
|
|
11
|
+
attr_accessor :displacement_map, :displacement_scale, :displacement_bias
|
|
12
|
+
attr_accessor :specular_map, :alpha_map
|
|
13
|
+
attr_accessor :env_map, :combine, :reflectivity, :refraction_ratio
|
|
14
|
+
attr_accessor :wireframe, :wireframe_linewidth
|
|
15
|
+
attr_accessor :flat_shading
|
|
16
|
+
|
|
17
|
+
TANGENT_SPACE_NORMAL_MAP = 0
|
|
18
|
+
OBJECT_SPACE_NORMAL_MAP = 1
|
|
19
|
+
|
|
20
|
+
def initialize(color: 0xffffff, emissive: 0x000000, map: nil, wireframe: false)
|
|
21
|
+
super()
|
|
22
|
+
|
|
23
|
+
@color = color.is_a?(Color) ? color : Color.new(color)
|
|
24
|
+
@map = map
|
|
25
|
+
|
|
26
|
+
@light_map = nil
|
|
27
|
+
@light_map_intensity = 1.0
|
|
28
|
+
|
|
29
|
+
@ao_map = nil
|
|
30
|
+
@ao_map_intensity = 1.0
|
|
31
|
+
|
|
32
|
+
@emissive = emissive.is_a?(Color) ? emissive : Color.new(emissive)
|
|
33
|
+
@emissive_intensity = 1.0
|
|
34
|
+
@emissive_map = nil
|
|
35
|
+
|
|
36
|
+
@bump_map = nil
|
|
37
|
+
@bump_scale = 1
|
|
38
|
+
|
|
39
|
+
@normal_map = nil
|
|
40
|
+
@normal_map_type = TANGENT_SPACE_NORMAL_MAP
|
|
41
|
+
@normal_scale = Vector2.new(1, 1)
|
|
42
|
+
|
|
43
|
+
@displacement_map = nil
|
|
44
|
+
@displacement_scale = 1
|
|
45
|
+
@displacement_bias = 0
|
|
46
|
+
|
|
47
|
+
@specular_map = nil
|
|
48
|
+
@alpha_map = nil
|
|
49
|
+
|
|
50
|
+
@env_map = nil
|
|
51
|
+
@combine = MeshBasicMaterial::MULTIPLY_OPERATION
|
|
52
|
+
@reflectivity = 1.0
|
|
53
|
+
@refraction_ratio = 0.98
|
|
54
|
+
|
|
55
|
+
@wireframe = wireframe
|
|
56
|
+
@wireframe_linewidth = 1
|
|
57
|
+
|
|
58
|
+
@flat_shading = false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def copy(source)
|
|
62
|
+
super
|
|
63
|
+
@color = source.color.clone
|
|
64
|
+
@map = source.map
|
|
65
|
+
@light_map = source.light_map
|
|
66
|
+
@light_map_intensity = source.light_map_intensity
|
|
67
|
+
@ao_map = source.ao_map
|
|
68
|
+
@ao_map_intensity = source.ao_map_intensity
|
|
69
|
+
@emissive = source.emissive.clone
|
|
70
|
+
@emissive_intensity = source.emissive_intensity
|
|
71
|
+
@emissive_map = source.emissive_map
|
|
72
|
+
@bump_map = source.bump_map
|
|
73
|
+
@bump_scale = source.bump_scale
|
|
74
|
+
@normal_map = source.normal_map
|
|
75
|
+
@normal_map_type = source.normal_map_type
|
|
76
|
+
@normal_scale = source.normal_scale.clone
|
|
77
|
+
@displacement_map = source.displacement_map
|
|
78
|
+
@displacement_scale = source.displacement_scale
|
|
79
|
+
@displacement_bias = source.displacement_bias
|
|
80
|
+
@specular_map = source.specular_map
|
|
81
|
+
@alpha_map = source.alpha_map
|
|
82
|
+
@env_map = source.env_map
|
|
83
|
+
@combine = source.combine
|
|
84
|
+
@reflectivity = source.reflectivity
|
|
85
|
+
@refraction_ratio = source.refraction_ratio
|
|
86
|
+
@wireframe = source.wireframe
|
|
87
|
+
@wireframe_linewidth = source.wireframe_linewidth
|
|
88
|
+
@flat_shading = source.flat_shading
|
|
89
|
+
self
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def to_h
|
|
93
|
+
super.merge(
|
|
94
|
+
color: @color.get_hex,
|
|
95
|
+
emissive: @emissive.get_hex,
|
|
96
|
+
wireframe: @wireframe
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
LambertMaterial = MeshLambertMaterial
|
|
102
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class Material
|
|
5
|
+
FRONT_SIDE = 0
|
|
6
|
+
BACK_SIDE = 1
|
|
7
|
+
DOUBLE_SIDE = 2
|
|
8
|
+
|
|
9
|
+
NO_BLENDING = 0
|
|
10
|
+
NORMAL_BLENDING = 1
|
|
11
|
+
ADDITIVE_BLENDING = 2
|
|
12
|
+
SUBTRACTIVE_BLENDING = 3
|
|
13
|
+
MULTIPLY_BLENDING = 4
|
|
14
|
+
CUSTOM_BLENDING = 5
|
|
15
|
+
|
|
16
|
+
attr_reader :uuid, :version
|
|
17
|
+
attr_accessor :name, :fog, :lights
|
|
18
|
+
attr_accessor :blending, :side, :vertex_colors
|
|
19
|
+
attr_accessor :opacity, :transparent
|
|
20
|
+
attr_accessor :alpha_test, :alpha_to_coverage
|
|
21
|
+
attr_accessor :depth_test, :depth_write
|
|
22
|
+
attr_accessor :color_write, :stencil_write
|
|
23
|
+
attr_accessor :polygon_offset, :polygon_offset_factor, :polygon_offset_units
|
|
24
|
+
attr_accessor :clipping_planes, :clip_intersection, :clip_shadows
|
|
25
|
+
attr_accessor :shadow_side
|
|
26
|
+
attr_accessor :visible
|
|
27
|
+
|
|
28
|
+
def initialize
|
|
29
|
+
@uuid = MathUtils.generate_uuid
|
|
30
|
+
@name = ""
|
|
31
|
+
@version = 0
|
|
32
|
+
|
|
33
|
+
@fog = true
|
|
34
|
+
@lights = true
|
|
35
|
+
|
|
36
|
+
@blending = NORMAL_BLENDING
|
|
37
|
+
@side = FRONT_SIDE
|
|
38
|
+
@vertex_colors = false
|
|
39
|
+
|
|
40
|
+
@opacity = 1.0
|
|
41
|
+
@transparent = false
|
|
42
|
+
|
|
43
|
+
@alpha_test = 0
|
|
44
|
+
@alpha_to_coverage = false
|
|
45
|
+
|
|
46
|
+
@depth_test = true
|
|
47
|
+
@depth_write = true
|
|
48
|
+
|
|
49
|
+
@color_write = true
|
|
50
|
+
@stencil_write = false
|
|
51
|
+
|
|
52
|
+
@polygon_offset = false
|
|
53
|
+
@polygon_offset_factor = 0
|
|
54
|
+
@polygon_offset_units = 0
|
|
55
|
+
|
|
56
|
+
@clipping_planes = nil
|
|
57
|
+
@clip_intersection = false
|
|
58
|
+
@clip_shadows = false
|
|
59
|
+
|
|
60
|
+
@shadow_side = nil
|
|
61
|
+
@visible = true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def needs_update=(value)
|
|
65
|
+
@version += 1 if value
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def copy(source)
|
|
69
|
+
@name = source.name
|
|
70
|
+
@fog = source.fog
|
|
71
|
+
@lights = source.lights
|
|
72
|
+
@blending = source.blending
|
|
73
|
+
@side = source.side
|
|
74
|
+
@vertex_colors = source.vertex_colors
|
|
75
|
+
@opacity = source.opacity
|
|
76
|
+
@transparent = source.transparent
|
|
77
|
+
@alpha_test = source.alpha_test
|
|
78
|
+
@alpha_to_coverage = source.alpha_to_coverage
|
|
79
|
+
@depth_test = source.depth_test
|
|
80
|
+
@depth_write = source.depth_write
|
|
81
|
+
@color_write = source.color_write
|
|
82
|
+
@stencil_write = source.stencil_write
|
|
83
|
+
@polygon_offset = source.polygon_offset
|
|
84
|
+
@polygon_offset_factor = source.polygon_offset_factor
|
|
85
|
+
@polygon_offset_units = source.polygon_offset_units
|
|
86
|
+
@clipping_planes = source.clipping_planes&.dup
|
|
87
|
+
@clip_intersection = source.clip_intersection
|
|
88
|
+
@clip_shadows = source.clip_shadows
|
|
89
|
+
@shadow_side = source.shadow_side
|
|
90
|
+
@visible = source.visible
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def clone
|
|
95
|
+
self.class.new.copy(self)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def dispose
|
|
99
|
+
@version = 0
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def to_h
|
|
103
|
+
{
|
|
104
|
+
uuid: @uuid,
|
|
105
|
+
type: self.class.name,
|
|
106
|
+
name: @name,
|
|
107
|
+
opacity: @opacity,
|
|
108
|
+
transparent: @transparent,
|
|
109
|
+
side: @side,
|
|
110
|
+
visible: @visible
|
|
111
|
+
}
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class MeshPhongMaterial < Material
|
|
5
|
+
attr_accessor :color, :specular, :shininess, :map
|
|
6
|
+
attr_accessor :light_map, :light_map_intensity
|
|
7
|
+
attr_accessor :ao_map, :ao_map_intensity
|
|
8
|
+
attr_accessor :emissive, :emissive_intensity, :emissive_map
|
|
9
|
+
attr_accessor :bump_map, :bump_scale
|
|
10
|
+
attr_accessor :normal_map, :normal_map_type, :normal_scale
|
|
11
|
+
attr_accessor :displacement_map, :displacement_scale, :displacement_bias
|
|
12
|
+
attr_accessor :specular_map, :alpha_map
|
|
13
|
+
attr_accessor :env_map, :combine, :reflectivity, :refraction_ratio
|
|
14
|
+
attr_accessor :wireframe, :wireframe_linewidth
|
|
15
|
+
attr_accessor :flat_shading
|
|
16
|
+
|
|
17
|
+
def initialize(color: 0xffffff, specular: 0x111111, shininess: 30,
|
|
18
|
+
emissive: 0x000000, map: nil, wireframe: false)
|
|
19
|
+
super()
|
|
20
|
+
|
|
21
|
+
@color = color.is_a?(Color) ? color : Color.new(color)
|
|
22
|
+
@specular = specular.is_a?(Color) ? specular : Color.new(specular)
|
|
23
|
+
@shininess = shininess.to_f
|
|
24
|
+
@map = map
|
|
25
|
+
|
|
26
|
+
@light_map = nil
|
|
27
|
+
@light_map_intensity = 1.0
|
|
28
|
+
|
|
29
|
+
@ao_map = nil
|
|
30
|
+
@ao_map_intensity = 1.0
|
|
31
|
+
|
|
32
|
+
@emissive = emissive.is_a?(Color) ? emissive : Color.new(emissive)
|
|
33
|
+
@emissive_intensity = 1.0
|
|
34
|
+
@emissive_map = nil
|
|
35
|
+
|
|
36
|
+
@bump_map = nil
|
|
37
|
+
@bump_scale = 1
|
|
38
|
+
|
|
39
|
+
@normal_map = nil
|
|
40
|
+
@normal_map_type = MeshLambertMaterial::TANGENT_SPACE_NORMAL_MAP
|
|
41
|
+
@normal_scale = Vector2.new(1, 1)
|
|
42
|
+
|
|
43
|
+
@displacement_map = nil
|
|
44
|
+
@displacement_scale = 1
|
|
45
|
+
@displacement_bias = 0
|
|
46
|
+
|
|
47
|
+
@specular_map = nil
|
|
48
|
+
@alpha_map = nil
|
|
49
|
+
|
|
50
|
+
@env_map = nil
|
|
51
|
+
@combine = MeshBasicMaterial::MULTIPLY_OPERATION
|
|
52
|
+
@reflectivity = 1.0
|
|
53
|
+
@refraction_ratio = 0.98
|
|
54
|
+
|
|
55
|
+
@wireframe = wireframe
|
|
56
|
+
@wireframe_linewidth = 1
|
|
57
|
+
|
|
58
|
+
@flat_shading = false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def copy(source)
|
|
62
|
+
super
|
|
63
|
+
@color = source.color.clone
|
|
64
|
+
@specular = source.specular.clone
|
|
65
|
+
@shininess = source.shininess
|
|
66
|
+
@map = source.map
|
|
67
|
+
@light_map = source.light_map
|
|
68
|
+
@light_map_intensity = source.light_map_intensity
|
|
69
|
+
@ao_map = source.ao_map
|
|
70
|
+
@ao_map_intensity = source.ao_map_intensity
|
|
71
|
+
@emissive = source.emissive.clone
|
|
72
|
+
@emissive_intensity = source.emissive_intensity
|
|
73
|
+
@emissive_map = source.emissive_map
|
|
74
|
+
@bump_map = source.bump_map
|
|
75
|
+
@bump_scale = source.bump_scale
|
|
76
|
+
@normal_map = source.normal_map
|
|
77
|
+
@normal_map_type = source.normal_map_type
|
|
78
|
+
@normal_scale = source.normal_scale.clone
|
|
79
|
+
@displacement_map = source.displacement_map
|
|
80
|
+
@displacement_scale = source.displacement_scale
|
|
81
|
+
@displacement_bias = source.displacement_bias
|
|
82
|
+
@specular_map = source.specular_map
|
|
83
|
+
@alpha_map = source.alpha_map
|
|
84
|
+
@env_map = source.env_map
|
|
85
|
+
@combine = source.combine
|
|
86
|
+
@reflectivity = source.reflectivity
|
|
87
|
+
@refraction_ratio = source.refraction_ratio
|
|
88
|
+
@wireframe = source.wireframe
|
|
89
|
+
@wireframe_linewidth = source.wireframe_linewidth
|
|
90
|
+
@flat_shading = source.flat_shading
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def to_h
|
|
95
|
+
super.merge(
|
|
96
|
+
color: @color.get_hex,
|
|
97
|
+
specular: @specular.get_hex,
|
|
98
|
+
shininess: @shininess,
|
|
99
|
+
emissive: @emissive.get_hex,
|
|
100
|
+
wireframe: @wireframe
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
PhongMaterial = MeshPhongMaterial
|
|
106
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class ShaderMaterial < Material
|
|
5
|
+
attr_accessor :vertex_shader, :fragment_shader
|
|
6
|
+
attr_accessor :uniforms, :defines
|
|
7
|
+
attr_accessor :extensions
|
|
8
|
+
attr_accessor :wireframe, :wireframe_linewidth
|
|
9
|
+
attr_accessor :line_width
|
|
10
|
+
attr_accessor :flat_shading
|
|
11
|
+
attr_accessor :uniform_needs_update
|
|
12
|
+
|
|
13
|
+
def initialize(vertex_shader: nil, fragment_shader: nil, uniforms: {})
|
|
14
|
+
super()
|
|
15
|
+
|
|
16
|
+
@vertex_shader = vertex_shader || default_vertex_shader
|
|
17
|
+
@fragment_shader = fragment_shader || default_fragment_shader
|
|
18
|
+
@uniforms = uniforms
|
|
19
|
+
@defines = {}
|
|
20
|
+
|
|
21
|
+
@extensions = {
|
|
22
|
+
derivatives: false,
|
|
23
|
+
frag_depth: false,
|
|
24
|
+
draw_buffers: false,
|
|
25
|
+
shader_texture_lod: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@wireframe = false
|
|
29
|
+
@wireframe_linewidth = 1
|
|
30
|
+
@line_width = 1
|
|
31
|
+
|
|
32
|
+
@flat_shading = false
|
|
33
|
+
@uniform_needs_update = false
|
|
34
|
+
|
|
35
|
+
@fog = false
|
|
36
|
+
@lights = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def copy(source)
|
|
40
|
+
super
|
|
41
|
+
@vertex_shader = source.vertex_shader
|
|
42
|
+
@fragment_shader = source.fragment_shader
|
|
43
|
+
@uniforms = deep_copy_uniforms(source.uniforms)
|
|
44
|
+
@defines = source.defines.dup
|
|
45
|
+
@extensions = source.extensions.dup
|
|
46
|
+
@wireframe = source.wireframe
|
|
47
|
+
@wireframe_linewidth = source.wireframe_linewidth
|
|
48
|
+
@line_width = source.line_width
|
|
49
|
+
@flat_shading = source.flat_shading
|
|
50
|
+
self
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clone
|
|
54
|
+
self.class.new.copy(self)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def to_h
|
|
58
|
+
super.merge(
|
|
59
|
+
uniforms: @uniforms.keys,
|
|
60
|
+
defines: @defines
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def default_vertex_shader
|
|
67
|
+
<<~GLSL
|
|
68
|
+
#version 330 core
|
|
69
|
+
layout (location = 0) in vec3 position;
|
|
70
|
+
uniform mat4 modelViewMatrix;
|
|
71
|
+
uniform mat4 projectionMatrix;
|
|
72
|
+
void main() {
|
|
73
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
74
|
+
}
|
|
75
|
+
GLSL
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def default_fragment_shader
|
|
79
|
+
<<~GLSL
|
|
80
|
+
#version 330 core
|
|
81
|
+
out vec4 FragColor;
|
|
82
|
+
void main() {
|
|
83
|
+
FragColor = vec4(1.0, 0.0, 1.0, 1.0);
|
|
84
|
+
}
|
|
85
|
+
GLSL
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def deep_copy_uniforms(uniforms)
|
|
89
|
+
uniforms.transform_values do |value|
|
|
90
|
+
case value
|
|
91
|
+
when Hash
|
|
92
|
+
deep_copy_uniforms(value)
|
|
93
|
+
when Array
|
|
94
|
+
value.map { |v| v.respond_to?(:clone) ? v.clone : v }
|
|
95
|
+
else
|
|
96
|
+
value.respond_to?(:clone) ? value.clone : value
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
class RawShaderMaterial < ShaderMaterial
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sunrb
|
|
4
|
+
class MeshStandardMaterial < Material
|
|
5
|
+
attr_accessor :color, :roughness, :metalness, :map
|
|
6
|
+
attr_accessor :light_map, :light_map_intensity
|
|
7
|
+
attr_accessor :ao_map, :ao_map_intensity
|
|
8
|
+
attr_accessor :emissive, :emissive_intensity, :emissive_map
|
|
9
|
+
attr_accessor :bump_map, :bump_scale
|
|
10
|
+
attr_accessor :normal_map, :normal_map_type, :normal_scale
|
|
11
|
+
attr_accessor :displacement_map, :displacement_scale, :displacement_bias
|
|
12
|
+
attr_accessor :roughness_map, :metalness_map
|
|
13
|
+
attr_accessor :alpha_map
|
|
14
|
+
attr_accessor :env_map, :env_map_intensity
|
|
15
|
+
attr_accessor :wireframe, :wireframe_linewidth
|
|
16
|
+
attr_accessor :flat_shading
|
|
17
|
+
|
|
18
|
+
def initialize(color: 0xffffff, roughness: 1.0, metalness: 0.0,
|
|
19
|
+
emissive: 0x000000, map: nil, wireframe: false)
|
|
20
|
+
super()
|
|
21
|
+
|
|
22
|
+
@color = color.is_a?(Color) ? color : Color.new(color)
|
|
23
|
+
@roughness = roughness.to_f
|
|
24
|
+
@metalness = metalness.to_f
|
|
25
|
+
@map = map
|
|
26
|
+
|
|
27
|
+
@light_map = nil
|
|
28
|
+
@light_map_intensity = 1.0
|
|
29
|
+
|
|
30
|
+
@ao_map = nil
|
|
31
|
+
@ao_map_intensity = 1.0
|
|
32
|
+
|
|
33
|
+
@emissive = emissive.is_a?(Color) ? emissive : Color.new(emissive)
|
|
34
|
+
@emissive_intensity = 1.0
|
|
35
|
+
@emissive_map = nil
|
|
36
|
+
|
|
37
|
+
@bump_map = nil
|
|
38
|
+
@bump_scale = 1
|
|
39
|
+
|
|
40
|
+
@normal_map = nil
|
|
41
|
+
@normal_map_type = MeshLambertMaterial::TANGENT_SPACE_NORMAL_MAP
|
|
42
|
+
@normal_scale = Vector2.new(1, 1)
|
|
43
|
+
|
|
44
|
+
@displacement_map = nil
|
|
45
|
+
@displacement_scale = 1
|
|
46
|
+
@displacement_bias = 0
|
|
47
|
+
|
|
48
|
+
@roughness_map = nil
|
|
49
|
+
@metalness_map = nil
|
|
50
|
+
|
|
51
|
+
@alpha_map = nil
|
|
52
|
+
|
|
53
|
+
@env_map = nil
|
|
54
|
+
@env_map_intensity = 1.0
|
|
55
|
+
|
|
56
|
+
@wireframe = wireframe
|
|
57
|
+
@wireframe_linewidth = 1
|
|
58
|
+
|
|
59
|
+
@flat_shading = false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def copy(source)
|
|
63
|
+
super
|
|
64
|
+
@color = source.color.clone
|
|
65
|
+
@roughness = source.roughness
|
|
66
|
+
@metalness = source.metalness
|
|
67
|
+
@map = source.map
|
|
68
|
+
@light_map = source.light_map
|
|
69
|
+
@light_map_intensity = source.light_map_intensity
|
|
70
|
+
@ao_map = source.ao_map
|
|
71
|
+
@ao_map_intensity = source.ao_map_intensity
|
|
72
|
+
@emissive = source.emissive.clone
|
|
73
|
+
@emissive_intensity = source.emissive_intensity
|
|
74
|
+
@emissive_map = source.emissive_map
|
|
75
|
+
@bump_map = source.bump_map
|
|
76
|
+
@bump_scale = source.bump_scale
|
|
77
|
+
@normal_map = source.normal_map
|
|
78
|
+
@normal_map_type = source.normal_map_type
|
|
79
|
+
@normal_scale = source.normal_scale.clone
|
|
80
|
+
@displacement_map = source.displacement_map
|
|
81
|
+
@displacement_scale = source.displacement_scale
|
|
82
|
+
@displacement_bias = source.displacement_bias
|
|
83
|
+
@roughness_map = source.roughness_map
|
|
84
|
+
@metalness_map = source.metalness_map
|
|
85
|
+
@alpha_map = source.alpha_map
|
|
86
|
+
@env_map = source.env_map
|
|
87
|
+
@env_map_intensity = source.env_map_intensity
|
|
88
|
+
@wireframe = source.wireframe
|
|
89
|
+
@wireframe_linewidth = source.wireframe_linewidth
|
|
90
|
+
@flat_shading = source.flat_shading
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def to_h
|
|
95
|
+
super.merge(
|
|
96
|
+
color: @color.get_hex,
|
|
97
|
+
roughness: @roughness,
|
|
98
|
+
metalness: @metalness,
|
|
99
|
+
emissive: @emissive.get_hex,
|
|
100
|
+
wireframe: @wireframe
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
StandardMaterial = MeshStandardMaterial
|
|
106
|
+
end
|