mittsu 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/mittsu/cameras/orthographic_camera.rb +13 -0
- data/lib/mittsu/cameras/perspective_camera.rb +11 -0
- data/lib/mittsu/core/geometry.rb +12 -9
- data/lib/mittsu/core/object_3d.rb +33 -66
- data/lib/mittsu/lights/ambient_light.rb +8 -0
- data/lib/mittsu/lights/directional_light.rb +9 -0
- data/lib/mittsu/lights/hemisphere_light.rb +9 -0
- data/lib/mittsu/lights/point_light.rb +11 -0
- data/lib/mittsu/lights/spot_light.rb +13 -0
- data/lib/mittsu/loaders.rb +1 -0
- data/lib/mittsu/loaders/mtl_loader.rb +5 -12
- data/lib/mittsu/loaders/obj_loader.rb +212 -0
- data/lib/mittsu/loaders/obj_mtl_loader.rb +11 -207
- data/lib/mittsu/materials/material.rb +5 -2
- data/lib/mittsu/materials/mesh_basic_material.rb +0 -9
- data/lib/mittsu/math/color.rb +44 -104
- data/lib/mittsu/math/matrix3.rb +8 -1
- data/lib/mittsu/math/matrix4.rb +6 -0
- data/lib/mittsu/math/vector.rb +251 -0
- data/lib/mittsu/math/vector2.rb +14 -213
- data/lib/mittsu/math/vector3.rb +61 -351
- data/lib/mittsu/math/vector4.rb +45 -295
- data/lib/mittsu/objects/line.rb +12 -2
- data/lib/mittsu/objects/mesh.rb +18 -9
- data/lib/mittsu/renderers/glfw_window.rb +15 -13
- data/lib/mittsu/renderers/opengl/core/opengl_geometry.rb +253 -0
- data/lib/mittsu/renderers/opengl/core/opengl_object_3d.rb +131 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_ambient_light.rb +26 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_directional_light.rb +35 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_hemisphere_light.rb +42 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_light.rb +52 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_point_light.rb +36 -0
- data/lib/mittsu/renderers/opengl/lights/opengl_spot_light.rb +47 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_line_basic_material.rb +16 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_material.rb +275 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_basic_material.rb +69 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_lambert_material.rb +29 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_phong_material.rb +40 -0
- data/lib/mittsu/renderers/opengl/materials/opengl_shader_material.rb +11 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_group.rb +8 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_line.rb +54 -0
- data/lib/mittsu/renderers/opengl/objects/opengl_mesh.rb +77 -0
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +5 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +49 -7
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +54 -0
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +763 -0
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +130 -0
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +161 -0
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +61 -0
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +43 -0
- data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +53 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +147 -296
- data/lib/mittsu/renderers/opengl/opengl_state.rb +3 -5
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +12 -10
- data/lib/mittsu/renderers/opengl/scenes/opengl_scene.rb +8 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_compressed_texture.rb +21 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_cube_texture.rb +75 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_data_texture.rb +23 -0
- data/lib/mittsu/renderers/opengl/textures/opengl_texture.rb +111 -0
- data/lib/mittsu/renderers/opengl_render_target.rb +117 -2
- data/lib/mittsu/renderers/opengl_renderer.rb +653 -2978
- data/lib/mittsu/renderers/shaders/rbsl_loader.rb +166 -0
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +6 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +36 -37
- data/lib/mittsu/renderers/shaders/shader_lib.rb +26 -403
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +37 -0
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +3 -0
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +33 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +2 -0
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +26 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +56 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +7 -0
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +37 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +45 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +11 -0
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +43 -0
- data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +105 -0
- data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +143 -0
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +54 -55
- data/lib/mittsu/textures/texture.rb +5 -2
- data/lib/mittsu/version.rb +1 -1
- data/run_all_examples.sh +7 -0
- metadata +77 -28
- data/.ruby-version +0 -1
- data/lib/mittsu/core/hash_object.rb +0 -19
@@ -0,0 +1,130 @@
|
|
1
|
+
module Mittsu
|
2
|
+
module OpenGLGeometryLike
|
3
|
+
CONST_BUFFER_NAMES = [
|
4
|
+
:vertex,
|
5
|
+
:color,
|
6
|
+
:normal,
|
7
|
+
:tangent,
|
8
|
+
:uv,
|
9
|
+
:uv2,
|
10
|
+
:skin_indices,
|
11
|
+
:skin_weight,
|
12
|
+
:line_distance,
|
13
|
+
:face,
|
14
|
+
:line
|
15
|
+
]
|
16
|
+
attr_accessor(*CONST_BUFFER_NAMES.map(&:to_s).map { |name| "#{name}_buffer" }.map(&:to_sym))
|
17
|
+
attr_accessor(*CONST_BUFFER_NAMES.map(&:to_s).map { |name| "#{name}_array" }.map(&:to_sym))
|
18
|
+
|
19
|
+
attr_accessor :vertex_array_object,
|
20
|
+
:num_morph_targets,
|
21
|
+
:num_morph_normals,
|
22
|
+
:morph_targets_buffers,
|
23
|
+
:morph_normals_buffers,
|
24
|
+
:morph_targets_arrays,
|
25
|
+
:morph_normals_arrays,
|
26
|
+
:faces3,
|
27
|
+
:type_array,
|
28
|
+
:face_count,
|
29
|
+
:line_count,
|
30
|
+
:initted_arrays,
|
31
|
+
:custom_attributes_list,
|
32
|
+
:num_vertices
|
33
|
+
|
34
|
+
def bind_vertex_array_object
|
35
|
+
glBindVertexArray(@vertex_array_object) if @vertex_array_object
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_vertex_buffer(attribute)
|
39
|
+
glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
|
40
|
+
@renderer.state.enable_attribute(attribute)
|
41
|
+
glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, 0, 0)
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_other_buffers(object, material, attributes)
|
45
|
+
update_custom_attributes(attributes)
|
46
|
+
|
47
|
+
update_color_buffer(attributes['color'], object, material)
|
48
|
+
update_normal_buffer(attributes['normal'])
|
49
|
+
update_tangent_buffer(attributes['tangent'])
|
50
|
+
update_uv_buffers(attributes['uv'], attributes['uv2'], object, material)
|
51
|
+
|
52
|
+
if material.skinning
|
53
|
+
update_skin_buffers(attributes['skin_index'], attributes['skin_weight'])
|
54
|
+
end
|
55
|
+
|
56
|
+
update_line_distances_buffer(attributes['line_distances'])
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def attribute_exists?(attribute)
|
62
|
+
attribute && attribute >= 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_color_buffer(attribute, object, material)
|
66
|
+
return unless attribute_exists?(attribute)
|
67
|
+
if object.geometry.colors.length > 0 || object.geometry.faces.length > 0
|
68
|
+
update_attribute(attribute, @color_buffer, 3)
|
69
|
+
elsif material.default_attribute_values
|
70
|
+
glVertexAttrib3fv(attribute, material.default_attribute_values.color)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_normal_buffer(attribute)
|
75
|
+
return unless attribute_exists?(attribute)
|
76
|
+
update_attribute(attribute, @normal_buffer, 3)
|
77
|
+
end
|
78
|
+
|
79
|
+
def update_tangent_buffer(attribute)
|
80
|
+
return unless attribute_exists?(attribute)
|
81
|
+
update_attribute(attribute, @tangent_buffer, 4)
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_uv_buffers(uv_attribute, uv2_attribute, object, material)
|
85
|
+
update_uv_buffer(uv_attribute, @uv_buffer, object, 0)
|
86
|
+
update_uv_buffer(uv2_attribute, @uv2_buffer, object, 1)
|
87
|
+
end
|
88
|
+
|
89
|
+
def update_uv_buffer(attribute, buffer, object, index)
|
90
|
+
return unless attribute_exists?(attribute)
|
91
|
+
if object.geometry.face_vertex_uvs[index]
|
92
|
+
update_attribute(attribute, buffer, 2)
|
93
|
+
else
|
94
|
+
# TODO default_attribute_value ???
|
95
|
+
# glVertexAttrib2fv(attribute, default_attribute_value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def update_skin_buffers(index_attribute, weight_attribute)
|
100
|
+
return unless attribute_exists?(index_attribute) && attribute_exists?(weight_attribute)
|
101
|
+
update_attribute(attribute, @skin_indices_buffer, 4)
|
102
|
+
update_attribute(attribute, @skin_weight_buffer, 4)
|
103
|
+
end
|
104
|
+
|
105
|
+
def update_line_distances_buffer(attribute)
|
106
|
+
return unless attribute_exists?(attribute)
|
107
|
+
update_attribute(attribute, @line_distance_buffer, 1)
|
108
|
+
end
|
109
|
+
|
110
|
+
def update_custom_attributes(attributes)
|
111
|
+
if @custom_attributes_list
|
112
|
+
@custom_attributes_list.each do |custom_attribute|
|
113
|
+
belongs_to_attribute = attributes[custom_attribute.buffer.belongs_to_attribute]
|
114
|
+
update_custom_attribute(custom_attribute, belongs_to_attribute)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def update_custom_attribute(custom_attribute, belongs_to_attribute)
|
120
|
+
return unless attribute_exists?(belongs_to_attribute)
|
121
|
+
update_attribute(attribute, custom_attribute.buffer, custom_attribute.size)
|
122
|
+
end
|
123
|
+
|
124
|
+
def update_attribute(attribute, buffer, size)
|
125
|
+
glBindBuffer(GL_ARRAY_BUFFER, buffer)
|
126
|
+
@renderer.state.enable_attribute(attribute)
|
127
|
+
glVertexAttribPointer(attribute, size, GL_FLOAT, GL_FALSE, 0, 0)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module Mittsu
|
2
|
+
module OpenGLHelper
|
3
|
+
def glCreateBuffer
|
4
|
+
@_b ||= ' '*8
|
5
|
+
glGenBuffers(1, @_b)
|
6
|
+
@_b.unpack('L')[0]
|
7
|
+
end
|
8
|
+
|
9
|
+
def glCreateTexture
|
10
|
+
@_b ||= ' '*8
|
11
|
+
glGenTextures(1, @_b)
|
12
|
+
@_b.unpack('L')[0]
|
13
|
+
end
|
14
|
+
|
15
|
+
def glCreateVertexArray
|
16
|
+
@_b ||= ' '*8
|
17
|
+
glGenVertexArrays(1, @_b)
|
18
|
+
@_b.unpack('L')[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def glCreateFramebuffer
|
22
|
+
@_b ||= ' '*8
|
23
|
+
glGenFramebuffers(1, @_b)
|
24
|
+
@_b.unpack('L')[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
def glCreateRenderbuffer
|
28
|
+
@_b ||= ' '*8
|
29
|
+
glGenRenderbuffers(1, @_b)
|
30
|
+
@_b.unpack('L')[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def array_to_ptr_easy(data)
|
34
|
+
if data.first.is_a?(Float)
|
35
|
+
size_of_element = Fiddle::SIZEOF_FLOAT
|
36
|
+
format_of_element = 'F'
|
37
|
+
# data.map!{ |d| d.nil? ? 0.0 : d }
|
38
|
+
else
|
39
|
+
size_of_element = Fiddle::SIZEOF_INT
|
40
|
+
format_of_element = 'L'
|
41
|
+
# data.map!{ |d| d.nil? ? 0 : d }
|
42
|
+
end
|
43
|
+
size = data.length * size_of_element
|
44
|
+
array_to_ptr(data, size, format_of_element)
|
45
|
+
end
|
46
|
+
|
47
|
+
def array_to_ptr(data, size, format)
|
48
|
+
ptr = Fiddle::Pointer.malloc(size)
|
49
|
+
ptr[0,size] = data.pack(format * data.length)
|
50
|
+
ptr
|
51
|
+
end
|
52
|
+
|
53
|
+
def glBufferData_easy(target, data, usage)
|
54
|
+
ptr = array_to_ptr_easy(data)
|
55
|
+
glBufferData(target, ptr.size, ptr, usage)
|
56
|
+
end
|
57
|
+
|
58
|
+
def glGetParameter(pname)
|
59
|
+
@_b ||= ' '*8
|
60
|
+
glGetIntegerv(pname, @_b)
|
61
|
+
@_b.unpack('L')[0]
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
def mark_uniforms_lights_needs_update(uniforms, value)
|
66
|
+
uniforms['ambientLightColor'].needs_update = value
|
67
|
+
|
68
|
+
uniforms['directionalLightColor'].needs_update = value
|
69
|
+
uniforms['directionalLightDirection'].needs_update = value
|
70
|
+
|
71
|
+
uniforms['pointLightColor'].needs_update = value
|
72
|
+
uniforms['pointLightPosition'].needs_update = value
|
73
|
+
uniforms['pointLightDistance'].needs_update = value
|
74
|
+
uniforms['pointLightDecay'].needs_update = value
|
75
|
+
|
76
|
+
uniforms['spotLightColor'].needs_update = value
|
77
|
+
uniforms['spotLightPosition'].needs_update = value
|
78
|
+
uniforms['spotLightDistance'].needs_update = value
|
79
|
+
uniforms['spotLightDirection'].needs_update = value
|
80
|
+
uniforms['spotLightAngleCos'].needs_update = value
|
81
|
+
uniforms['spotLightExponent'].needs_update = value
|
82
|
+
uniforms['spotLightDecay'].needs_update = value
|
83
|
+
|
84
|
+
uniforms['hemisphereLightSkyColor'].needs_update = value
|
85
|
+
uniforms['hemisphereLightGroundColor'].needs_update = value
|
86
|
+
uniforms['hemisphereLightDirection'].needs_update = value
|
87
|
+
end
|
88
|
+
|
89
|
+
def refresh_uniforms_shadow(uniforms, lights)
|
90
|
+
if uniforms['shadowMatrix']
|
91
|
+
lights.select(&:cast_shadow).select { |light|
|
92
|
+
light.is_a?(SpotLight) || (light.is_a?(DirectionalLight) && !light.shadow_cascade)
|
93
|
+
}.each_with_index { |light, i|
|
94
|
+
uniforms['shadowMap'].value[i] = light.shadow_map
|
95
|
+
uniforms['shadowMapSize'].value[i] = light.shadow_map_size
|
96
|
+
|
97
|
+
uniforms['shadowMatrix'].value[i] = light.shadow_matrix
|
98
|
+
|
99
|
+
uniforms['shadowDarkness'].value[i] = light.shadow_darkness
|
100
|
+
uniforms['shadowBias'].value[i] = light.shadow_bias
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def refresh_uniforms_lights(uniforms, lights)
|
106
|
+
uniforms['ambientLightColor'].value = lights[:ambient].value
|
107
|
+
|
108
|
+
uniforms['directionalLightColor'].value = lights[:directional].colors
|
109
|
+
uniforms['directionalLightDirection'].value = lights[:directional].positions
|
110
|
+
|
111
|
+
uniforms['pointLightColor'].value = lights[:point].colors
|
112
|
+
uniforms['pointLightPosition'].value = lights[:point].positions
|
113
|
+
uniforms['pointLightDistance'].value = lights[:point].distances
|
114
|
+
uniforms['pointLightDecay'].value = lights[:point].decays
|
115
|
+
|
116
|
+
uniforms['spotLightColor'].value = lights[:spot].colors
|
117
|
+
uniforms['spotLightPosition'].value = lights[:spot].positions
|
118
|
+
uniforms['spotLightDistance'].value = lights[:spot].distances
|
119
|
+
uniforms['spotLightDirection'].value = lights[:spot].directions
|
120
|
+
uniforms['spotLightAngleCos'].value = lights[:spot].angles_cos
|
121
|
+
uniforms['spotLightExponent'].value = lights[:spot].exponents
|
122
|
+
uniforms['spotLightDecay'].value = lights[:spot].decays
|
123
|
+
|
124
|
+
uniforms['hemisphereLightSkyColor'].value = lights[:hemi].sky_colors
|
125
|
+
uniforms['hemisphereLightGroundColor'].value = lights[:hemi].ground_colors
|
126
|
+
uniforms['hemisphereLightDirection'].value = lights[:hemi].positions
|
127
|
+
end
|
128
|
+
|
129
|
+
def refresh_uniforms_lambert(uniforms, material)
|
130
|
+
end
|
131
|
+
|
132
|
+
def set_color_linear(array, offset, color, intensity)
|
133
|
+
array[offset] = color.r * intensity
|
134
|
+
array[offset + 1] = color.g * intensity
|
135
|
+
array[offset + 2] = color.b * intensity
|
136
|
+
end
|
137
|
+
|
138
|
+
def painter_sort_stable(a, b)
|
139
|
+
if a.object.render_order != b.object.render_order
|
140
|
+
a.object.render_order - b.object.render_order
|
141
|
+
elsif a.material.id != b.material.id
|
142
|
+
a.material.id - b.material.id
|
143
|
+
elsif a.z != b.z
|
144
|
+
a.z - b.z
|
145
|
+
else
|
146
|
+
a.object.id - b.object.id
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def reverse_painter_sort_stable(a, b)
|
151
|
+
if a.object.render_order != b.object.render_order
|
152
|
+
a.object.render_order - b.object.render_order
|
153
|
+
elsif a.z != b.z
|
154
|
+
b.z - a.z
|
155
|
+
else
|
156
|
+
a.id - b.id
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'mittsu/core/geometry'
|
2
|
+
require 'mittsu/core/object_3d'
|
3
|
+
require 'mittsu/objects'
|
4
|
+
require 'mittsu/materials'
|
5
|
+
require 'mittsu/textures'
|
6
|
+
require 'mittsu/scenes'
|
7
|
+
|
8
|
+
require 'mittsu/renderers/opengl/core/opengl_geometry'
|
9
|
+
require 'mittsu/renderers/opengl/core/opengl_object_3d'
|
10
|
+
require 'mittsu/renderers/opengl/objects/opengl_mesh'
|
11
|
+
require 'mittsu/renderers/opengl/objects/opengl_line'
|
12
|
+
require 'mittsu/renderers/opengl/objects/opengl_group'
|
13
|
+
require 'mittsu/renderers/opengl/scenes/opengl_scene'
|
14
|
+
require 'mittsu/renderers/opengl/materials/opengl_material'
|
15
|
+
require 'mittsu/renderers/opengl/materials/opengl_mesh_basic_material'
|
16
|
+
require 'mittsu/renderers/opengl/materials/opengl_mesh_lambert_material'
|
17
|
+
require 'mittsu/renderers/opengl/materials/opengl_mesh_phong_material'
|
18
|
+
require 'mittsu/renderers/opengl/materials/opengl_line_basic_material'
|
19
|
+
require 'mittsu/renderers/opengl/materials/opengl_shader_material'
|
20
|
+
require 'mittsu/renderers/opengl/textures/opengl_texture'
|
21
|
+
require 'mittsu/renderers/opengl/textures/opengl_cube_texture'
|
22
|
+
require 'mittsu/renderers/opengl/textures/opengl_data_texture'
|
23
|
+
require 'mittsu/renderers/opengl/textures/opengl_compressed_texture'
|
24
|
+
require 'mittsu/renderers/opengl/lights/opengl_light'
|
25
|
+
require 'mittsu/renderers/opengl/lights/opengl_light'
|
26
|
+
require 'mittsu/renderers/opengl/lights/opengl_spot_light'
|
27
|
+
require 'mittsu/renderers/opengl/lights/opengl_point_light'
|
28
|
+
require 'mittsu/renderers/opengl/lights/opengl_hemisphere_light'
|
29
|
+
require 'mittsu/renderers/opengl/lights/opengl_ambient_light'
|
30
|
+
require 'mittsu/renderers/opengl/lights/opengl_directional_light'
|
31
|
+
|
32
|
+
module Mittsu
|
33
|
+
OPENGL_IMPLEMENTATIONS = {
|
34
|
+
Object3D => OpenGLObject3D,
|
35
|
+
Geometry => OpenGLGeometry,
|
36
|
+
Material => OpenGLMaterial,
|
37
|
+
Texture => OpenGLTexture,
|
38
|
+
Light => OpenGLLight,
|
39
|
+
CubeTexture => OpenGLCubeTexture,
|
40
|
+
Mesh => OpenGLMesh,
|
41
|
+
Line => OpenGLLine,
|
42
|
+
SpotLight => OpenGLSpotLight,
|
43
|
+
PointLight => OpenGLPointLight,
|
44
|
+
HemisphereLight => OpenGLHemisphereLight,
|
45
|
+
AmbientLight => OpenGLAmbientLight,
|
46
|
+
DirectionalLight => OpenGLDirectionalLight,
|
47
|
+
DataTexture => OpenGLDataTexture,
|
48
|
+
CompressedTexture => OpenGLCompressedTexture,
|
49
|
+
Scene => OpenGLScene,
|
50
|
+
Group => OpenGLGroup,
|
51
|
+
MeshBasicMaterial => OpenGLMeshBasicMaterial,
|
52
|
+
MeshLambertMaterial => OpenGLMeshLambertMaterial,
|
53
|
+
MeshPhongMaterial => OpenGLMeshPhongMaterial,
|
54
|
+
LineBasicMaterial => OpenGLLineBasicMaterial,
|
55
|
+
ShaderMaterial => OpenGLShaderMaterial
|
56
|
+
}
|
57
|
+
OPENGL_IMPLEMENTATIONS.default_proc = -> (hash, key) {
|
58
|
+
super_klass = key.ancestors.find { |a| hash.has_key?(a) }
|
59
|
+
super_klass ? (hash[key] = hash[super_klass]) : nil
|
60
|
+
}
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class OpenGLLightRenderer
|
3
|
+
attr_accessor :lights_need_update, :cache
|
4
|
+
|
5
|
+
LIGHT_CLASSES = [
|
6
|
+
OpenGLAmbientLight,
|
7
|
+
OpenGLDirectionalLight,
|
8
|
+
OpenGLPointLight,
|
9
|
+
OpenGLSpotLight,
|
10
|
+
OpenGLHemisphereLight
|
11
|
+
]
|
12
|
+
LIGHT_TYPES = LIGHT_CLASSES.map { |klass| klass::TYPE }
|
13
|
+
|
14
|
+
def initialize(renderer)
|
15
|
+
@renderer = renderer
|
16
|
+
@lights_need_update = true
|
17
|
+
@cache = {}
|
18
|
+
LIGHT_CLASSES.each { |klass|
|
19
|
+
@cache[klass::TYPE] = klass::Cache.new
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup(lights)
|
24
|
+
@cache.values.each(&:reset)
|
25
|
+
|
26
|
+
lights.each do |light|
|
27
|
+
next if light.only_shadow
|
28
|
+
light.implementation(self).setup
|
29
|
+
end
|
30
|
+
|
31
|
+
LIGHT_CLASSES.each do |klass|
|
32
|
+
cache = @cache[klass::TYPE]
|
33
|
+
klass.null_remaining_lights(cache)
|
34
|
+
end
|
35
|
+
|
36
|
+
@lights_need_update = false
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset
|
40
|
+
@lights_need_update = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Mittsu
|
2
|
+
GL_MITTSU_PARAMS = {
|
3
|
+
RepeatWrapping => GL_REPEAT,
|
4
|
+
ClampToEdgeWrapping => GL_CLAMP_TO_EDGE,
|
5
|
+
MirroredRepeatWrapping => GL_MIRRORED_REPEAT,
|
6
|
+
|
7
|
+
NearestFilter => GL_NEAREST,
|
8
|
+
NearestMipMapNearestFilter => GL_NEAREST_MIPMAP_NEAREST,
|
9
|
+
NearestMipMapLinearFilter => GL_NEAREST_MIPMAP_LINEAR,
|
10
|
+
|
11
|
+
LinearFilter => GL_LINEAR,
|
12
|
+
LinearMipMapNearestFilter => GL_LINEAR_MIPMAP_NEAREST,
|
13
|
+
LinearMipMapLinearFilter => GL_LINEAR_MIPMAP_LINEAR,
|
14
|
+
|
15
|
+
UnsignedByteType => GL_UNSIGNED_BYTE,
|
16
|
+
UnsignedShort4444Type => GL_UNSIGNED_SHORT_4_4_4_4,
|
17
|
+
UnsignedShort5551Type => GL_UNSIGNED_SHORT_5_5_5_1,
|
18
|
+
UnsignedShort565Type => GL_UNSIGNED_SHORT_5_6_5,
|
19
|
+
|
20
|
+
ByteType => GL_BYTE,
|
21
|
+
ShortType => GL_SHORT,
|
22
|
+
UnsignedShortType => GL_UNSIGNED_SHORT,
|
23
|
+
IntType => GL_INT,
|
24
|
+
UnsignedIntType => GL_UNSIGNED_INT,
|
25
|
+
FloatType => GL_FLOAT,
|
26
|
+
|
27
|
+
AlphaFormat => GL_ALPHA,
|
28
|
+
RGBFormat => GL_RGB,
|
29
|
+
RGBAFormat => GL_RGBA,
|
30
|
+
LuminanceFormat => GL_LUMINANCE,
|
31
|
+
LuminanceAlphaFormat => GL_LUMINANCE_ALPHA,
|
32
|
+
|
33
|
+
AddEquation => GL_FUNC_ADD,
|
34
|
+
SubtractEquation => GL_FUNC_SUBTRACT,
|
35
|
+
ReverseSubtractEquation => GL_FUNC_REVERSE_SUBTRACT,
|
36
|
+
|
37
|
+
ZeroFactor => GL_ZERO,
|
38
|
+
OneFactor => GL_ONE,
|
39
|
+
SrcColorFactor => GL_SRC_COLOR,
|
40
|
+
OneMinusSrcColorFactor => GL_ONE_MINUS_SRC_COLOR,
|
41
|
+
SrcAlphaFactor => GL_SRC_ALPHA,
|
42
|
+
OneMinusSrcAlphaFactor => GL_ONE_MINUS_SRC_ALPHA,
|
43
|
+
DstAlphaFactor => GL_DST_ALPHA,
|
44
|
+
OneMinusDstAlphaFactor => GL_ONE_MINUS_DST_ALPHA,
|
45
|
+
|
46
|
+
DstColorFactor => GL_DST_COLOR,
|
47
|
+
OneMinusDstColorFactor => GL_ONE_MINUS_DST_COLOR,
|
48
|
+
SrcAlphaSaturateFactor => GL_SRC_ALPHA_SATURATE
|
49
|
+
|
50
|
+
# TODO: populate with extension parameters?
|
51
|
+
}
|
52
|
+
GL_MITTSU_PARAMS.default = 0
|
53
|
+
end
|