mittsu 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-workflow.yml +3 -38
  3. data/Gemfile +0 -4
  4. data/README.md +16 -130
  5. data/bin/console +0 -4
  6. data/lib/mittsu/cameras/cube_camera.rb +1 -1
  7. data/lib/mittsu/core/uniform.rb +23 -0
  8. data/lib/mittsu/core.rb +1 -0
  9. data/lib/mittsu/loaders/stl_loader.rb +186 -0
  10. data/lib/mittsu/loaders.rb +1 -0
  11. data/lib/mittsu/textures/render_target.rb +93 -0
  12. data/lib/mittsu/textures/render_target_cube.rb +8 -0
  13. data/lib/mittsu/textures/texture.rb +1 -1
  14. data/lib/mittsu/textures.rb +2 -0
  15. data/lib/mittsu/version.rb +1 -1
  16. data/lib/mittsu.rb +0 -1
  17. data/mittsu.gemspec +8 -12
  18. metadata +28 -199
  19. data/install-glfw.ps1 +0 -13
  20. data/lib/mittsu/renderers/generic_lib.rb +0 -125
  21. data/lib/mittsu/renderers/glfw_lib.rb +0 -64
  22. data/lib/mittsu/renderers/glfw_window.rb +0 -233
  23. data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
  24. data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
  25. data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
  26. data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
  27. data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
  28. data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
  29. data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
  30. data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
  31. data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
  32. data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
  33. data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
  34. data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
  35. data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
  36. data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
  37. data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
  38. data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
  39. data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
  40. data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
  41. data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
  42. data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
  43. data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
  44. data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
  45. data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
  46. data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
  47. data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
  48. data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
  49. data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
  50. data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
  51. data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
  52. data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
  53. data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
  54. data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
  55. data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
  56. data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
  57. data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
  58. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
  59. data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
  60. data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
  61. data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
  62. data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
  63. data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
  64. data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
  65. data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
  66. data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
  67. data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
  68. data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
  69. data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
  70. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
  71. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
  72. data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
  73. data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
  74. data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
  75. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
  76. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
  77. data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
  78. data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
  79. data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
  80. data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
  81. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
  82. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
  83. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
  84. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
  85. data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
  86. data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
  87. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
  88. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
  89. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
  90. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
  91. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
  92. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
  93. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
  94. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
  95. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
  96. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
  97. data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
  98. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
  99. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
  100. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
  101. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
  102. data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
  103. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
  104. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
  105. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
  106. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
  107. data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
  108. data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
  109. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
  110. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
  111. data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
  112. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
  113. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
  114. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
  115. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
  116. data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
  117. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
  118. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
  119. data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
  120. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
  121. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
  122. data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
  123. data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
  124. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
  125. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
  126. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
  127. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
  128. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
  129. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
  130. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
  131. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
  132. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +0 -12
  133. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
  134. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
  135. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
  136. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
  137. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
  138. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
  139. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
  140. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
  141. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
  142. data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
  143. data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
  144. data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
  145. data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
  146. data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
  147. data/lib/mittsu/renderers.rb +0 -1
@@ -1,132 +0,0 @@
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
- :particle_count,
31
- :initted_arrays,
32
- :custom_attributes_list,
33
- :num_vertices,
34
- :renderer
35
-
36
- def bind_vertex_array_object
37
- glBindVertexArray(@vertex_array_object) if @vertex_array_object
38
- end
39
-
40
- def update_vertex_buffer(attribute)
41
- glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
42
- @renderer.state.enable_attribute(attribute)
43
- glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, 0, 0)
44
- end
45
-
46
- def update_other_buffers(object, material, attributes)
47
- update_custom_attributes(attributes)
48
-
49
- update_color_buffer(attributes['color'], object, material)
50
- update_normal_buffer(attributes['normal'])
51
- update_tangent_buffer(attributes['tangent'])
52
- update_uv_buffers(attributes['uv'], attributes['uv2'], object, material)
53
-
54
- if material.skinning
55
- update_skin_buffers(attributes['skin_index'], attributes['skin_weight'])
56
- end
57
-
58
- update_line_distances_buffer(attributes['line_distances'])
59
- end
60
-
61
- private
62
-
63
- def attribute_exists?(attribute)
64
- attribute && attribute >= 0
65
- end
66
-
67
- def update_color_buffer(attribute, object, material)
68
- return unless attribute_exists?(attribute)
69
- if object.geometry.colors.length > 0 || object.geometry.faces.length > 0
70
- update_attribute(attribute, @color_buffer, 3)
71
- elsif material.default_attribute_values
72
- glVertexAttrib3fv(attribute, material.default_attribute_values.color)
73
- end
74
- end
75
-
76
- def update_normal_buffer(attribute)
77
- return unless attribute_exists?(attribute)
78
- update_attribute(attribute, @normal_buffer, 3)
79
- end
80
-
81
- def update_tangent_buffer(attribute)
82
- return unless attribute_exists?(attribute)
83
- update_attribute(attribute, @tangent_buffer, 4)
84
- end
85
-
86
- def update_uv_buffers(uv_attribute, uv2_attribute, object, material)
87
- update_uv_buffer(uv_attribute, @uv_buffer, object, 0)
88
- update_uv_buffer(uv2_attribute, @uv2_buffer, object, 1)
89
- end
90
-
91
- def update_uv_buffer(attribute, buffer, object, index)
92
- return unless attribute_exists?(attribute)
93
- if object.geometry.face_vertex_uvs[index]
94
- update_attribute(attribute, buffer, 2)
95
- else
96
- # TODO default_attribute_value ???
97
- # glVertexAttrib2fv(attribute, default_attribute_value)
98
- end
99
- end
100
-
101
- def update_skin_buffers(index_attribute, weight_attribute)
102
- return unless attribute_exists?(index_attribute) && attribute_exists?(weight_attribute)
103
- update_attribute(attribute, @skin_indices_buffer, 4)
104
- update_attribute(attribute, @skin_weight_buffer, 4)
105
- end
106
-
107
- def update_line_distances_buffer(attribute)
108
- return unless attribute_exists?(attribute)
109
- update_attribute(attribute, @line_distance_buffer, 1)
110
- end
111
-
112
- def update_custom_attributes(attributes)
113
- if @custom_attributes_list
114
- @custom_attributes_list.each do |custom_attribute|
115
- belongs_to_attribute = attributes[custom_attribute.buffer.belongs_to_attribute]
116
- update_custom_attribute(custom_attribute, belongs_to_attribute)
117
- end
118
- end
119
- end
120
-
121
- def update_custom_attribute(custom_attribute, belongs_to_attribute)
122
- return unless attribute_exists?(belongs_to_attribute)
123
- update_attribute(attribute, custom_attribute.buffer, custom_attribute.size)
124
- end
125
-
126
- def update_attribute(attribute, buffer, size)
127
- glBindBuffer(GL_ARRAY_BUFFER, buffer)
128
- @renderer.state.enable_attribute(attribute)
129
- glVertexAttribPointer(attribute, size, GL_FLOAT, GL_FALSE, 0, 0)
130
- end
131
- end
132
- end
@@ -1,161 +0,0 @@
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
- b.id <=> a.id
157
- end
158
- end
159
- end
160
- end
161
- end
@@ -1,37 +0,0 @@
1
- require 'mittsu/core/geometry'
2
- require 'mittsu/core/object_3d'
3
- require 'mittsu/core/buffer_geometry'
4
- require 'mittsu/objects'
5
- require 'mittsu/materials'
6
- require 'mittsu/textures'
7
- require 'mittsu/scenes'
8
-
9
- require 'mittsu/renderers/opengl/core/geometry'
10
- require 'mittsu/renderers/opengl/core/object_3d'
11
- require 'mittsu/renderers/opengl/core/buffer_geometry'
12
- require 'mittsu/renderers/opengl/objects/mesh'
13
- require 'mittsu/renderers/opengl/objects/line'
14
- require 'mittsu/renderers/opengl/objects/group'
15
- require 'mittsu/renderers/opengl/objects/sprite'
16
- require 'mittsu/renderers/opengl/objects/point_cloud'
17
- require 'mittsu/renderers/opengl/scenes/scene'
18
-
19
- require 'mittsu/renderers/opengl/lights/light'
20
- require 'mittsu/renderers/opengl/lights/spot_light'
21
- require 'mittsu/renderers/opengl/lights/point_light'
22
- require 'mittsu/renderers/opengl/lights/hemisphere_light'
23
- require 'mittsu/renderers/opengl/lights/ambient_light'
24
- require 'mittsu/renderers/opengl/lights/directional_light'
25
-
26
- require 'mittsu/renderers/opengl/materials/material'
27
- require 'mittsu/renderers/opengl/materials/mesh_basic_material'
28
- require 'mittsu/renderers/opengl/materials/mesh_lambert_material'
29
- require 'mittsu/renderers/opengl/materials/mesh_phong_material'
30
- require 'mittsu/renderers/opengl/materials/line_basic_material'
31
- require 'mittsu/renderers/opengl/materials/shader_material'
32
- require 'mittsu/renderers/opengl/materials/point_cloud_material'
33
-
34
- require 'mittsu/renderers/opengl/textures/texture'
35
- require 'mittsu/renderers/opengl/textures/cube_texture'
36
- require 'mittsu/renderers/opengl/textures/data_texture'
37
- require 'mittsu/renderers/opengl/textures/compressed_texture'
@@ -1,19 +0,0 @@
1
- require 'mittsu/renderers/generic_lib'
2
-
3
- module Mittsu
4
- module OpenGLLib
5
- extend GenericLib
6
-
7
- class Linux < GenericLib::Linux
8
- def initialize(loader = Linux)
9
- @loader = loader
10
- end
11
- end
12
-
13
- class Windows < GenericLib::Base
14
- end
15
-
16
- class MacOS < GenericLib::Base
17
- end
18
- end
19
- end
@@ -1,43 +0,0 @@
1
- module Mittsu
2
- class OpenGLLightRenderer
3
- attr_accessor :lights_need_update, :cache
4
-
5
- LIGHT_CLASSES = [
6
- AmbientLight,
7
- DirectionalLight,
8
- PointLight,
9
- SpotLight,
10
- HemisphereLight
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.setup(self)
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
@@ -1,53 +0,0 @@
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
@@ -1,250 +0,0 @@
1
- require 'erb'
2
- require 'mittsu/renderers/opengl/opengl_shader'
3
-
4
- module Mittsu
5
- class OpenGLProgram
6
- attr_reader :id, :program, :uniforms
7
- attr_accessor :code, :used_times, :attributes, :vertex_shader, :fragment_shader
8
-
9
- def initialize(renderer, code, material, parameters)
10
- @id = (@@id ||= 1).tap { @@id += 1 }
11
- @renderer = renderer
12
-
13
- compile_and_link_program(material, parameters)
14
-
15
- cache_uniform_locations(material.shader[:uniforms] || {}, parameters)
16
- cache_attribute_locations(material.attributes || {}, parameters)
17
-
18
- @code = code
19
- @used_times = 2
20
- end
21
-
22
- private
23
-
24
- def compile_and_link_program(material, parameters)
25
- @program = glCreateProgram
26
-
27
- # TODO: necessary for OpenGL?
28
- # index0_attribute_name = material.index0_attribute_name
29
- #
30
- # if index0_attribute_name.nil? && parameters[:morph_targets]
31
- # # programs with morph_targets displace position of attribute 0
32
- #
33
- # index0_attribute_name = 'position'
34
- # end
35
-
36
- compile_shaders(material, parameters)
37
-
38
- # if !index0_attribute_name.nil?
39
- # TODO: is this necessary in OpenGL ???
40
- # Force a particular attribute to index 0.
41
- # because potentially expensive emulation is done by __browser__ if attribute 0 is disabled. (no browser here!)
42
- # And, color, for example is often automatically bound to index 0 so disabling it
43
-
44
- # glBindAttributeLocation(program, 0, index0_attribute_name)
45
- # end
46
-
47
- glLinkProgram(@program)
48
- check_for_link_errors
49
- post_link_clean_up
50
- end
51
-
52
- def generate_defines(defines)
53
- chunks = []
54
-
55
- defines.each do |d, value|
56
- next if value == false
57
-
58
- chunk = "#define #{d} #{value}"
59
- chunks << chunk
60
- end
61
-
62
- chunks.join("\n")
63
- end
64
-
65
- def link_status
66
- ptr = ' '*8
67
- glGetProgramiv @program, GL_LINK_STATUS, ptr
68
- ptr.unpack('L')[0]
69
- end
70
-
71
- def program_info_log
72
- ptr = ' '*8
73
- glGetProgramiv @program, GL_INFO_LOG_LENGTH, ptr
74
- length = ptr.unpack('L')[0]
75
-
76
- if length > 0
77
- log = ' '*length
78
- glGetProgramInfoLog @program, length, ptr, log
79
- log.unpack("A#{length}")[0]
80
- else
81
- ''
82
- end
83
- end
84
-
85
- def check_for_link_errors
86
- log_info = program_info_log
87
-
88
- if !link_status
89
- puts "ERROR: Mittsu::OpenGLProgram: shader error: #{glGetError}, GL_INVALID_STATUS, #{glGetProgramParameter(program, GL_VALIDATE_STATUS)}, glGetProgramParameterInfoLog, #{log_info}"
90
- end
91
-
92
- if !log_info.empty?
93
- puts "WARNING: Mittsu::OpenGLProgram: glGetProgramInfoLog, #{log_info}"
94
- # TODO: useless in OpenGL ???
95
- # puts "WARNING: #{glGetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader )}"
96
- # puts "WARNING: #{glGetExtension( 'OPENGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader )}"
97
- end
98
- end
99
-
100
- def get_shadow_map_define(shadow_map_param)
101
- case shadow_map_param
102
- when PCFShadowMap
103
- 'SHADOWMAP_TYPE_PCF'
104
- when PCFSoftShadowMap
105
- 'SHADOWMAP_TYPE_PCF_SOFT'
106
- else
107
- 'SHADOWMAP_TYPE_BASIC'
108
- end
109
- end
110
-
111
- def get_env_map_type_define(env_map_param, material)
112
- return 'ENVMAP_TYPE_CUBE' unless env_map_param
113
- case material.env_map.mapping
114
- when CubeReflectionMapping, CubeRefractionMapping
115
- 'ENVMAP_TYPE_CUBE'
116
- when EquirectangularReflectionMapping, EquirectangularRefractionMapping
117
- 'ENVMAP_TYPE_EQUIREC'
118
- when SphericalReflectionMapping
119
- 'ENVMAP_TYPE_SPHERE'
120
- else
121
- 'ENVMAP_TYPE_CUBE'
122
- end
123
- end
124
-
125
- def get_env_map_mode_define(env_map_param, material)
126
- return 'ENVMAP_MODE_REFLECTION' unless env_map_param
127
- case material.env_map.mapping
128
- when CubeRefractionMapping, EquirectangularRefractionMapping
129
- 'ENVMAP_MODE_REFRACTION'
130
- else
131
- 'ENVMAP_MODE_REFLECTION'
132
- end
133
- end
134
-
135
- def get_env_map_blending_define(env_map_param, material)
136
- return 'ENVMAP_BLENDING_MULTIPLY' unless env_map_param
137
- case material.combine
138
- when MultiplyOperation
139
- 'ENVMAP_BLENDING_MULTIPLY'
140
- when MixOperation
141
- 'ENVMAP_BLENDING_MIX'
142
- when AddOperation
143
- 'ENVMAP_BLENDING_ADD'
144
- else
145
- 'ENVMAP_BLENDING_MULTIPLY'
146
- end
147
- end
148
-
149
- def compile_shaders(material, parameters)
150
- shadow_map_type_define = get_shadow_map_define(parameters[:shadow_map_type])
151
-
152
- env_map_type_define = get_env_map_type_define(parameters[:env_map], material)
153
- env_map_mode_define = get_env_map_mode_define(parameters[:env_map], material)
154
- env_map_blending_define = get_env_map_blending_define(parameters[:env_map], material)
155
-
156
- gamma_factor_define = (@renderer.gamma_factor > 0) ? @renderer.gamma_factor : 1.0
157
-
158
- custom_defines = generate_defines(material.defines || {})
159
-
160
- if false # material.is_a?(RawShaderMaterial) # TODO: when RawShaderMaterial exists
161
- prefix_vertex = ''
162
- prefix_fragment = ''
163
- else
164
- prefix_vertex = File.read(File.expand_path('../../shaders/shader_templates/vertex.glsl.erb', __FILE__))
165
- prefix_fragment = File.read(File.expand_path('../../shaders/shader_templates/fragment.glsl.erb', __FILE__))
166
- end
167
-
168
- @vertex_shader = OpenGLShader.new(GL_VERTEX_SHADER, compile_shader_template(prefix_vertex + material.shader[:vertex_shader], binding))
169
- @fragment_shader = OpenGLShader.new(GL_FRAGMENT_SHADER, compile_shader_template(prefix_fragment + material.shader[:fragment_shader], binding))
170
-
171
- glAttachShader(@program, @vertex_shader.shader)
172
- glAttachShader(@program, @fragment_shader.shader)
173
- end
174
-
175
- def compile_shader_template(template, b)
176
- ERB.new(template).result(b)
177
- end
178
-
179
- def post_link_clean_up
180
- glDeleteShader(@vertex_shader.shader)
181
- glDeleteShader(@fragment_shader.shader)
182
- end
183
-
184
- def cache_uniform_locations(uniforms, parameters)
185
- identifiers = [
186
- 'viewMatrix',
187
- 'modelViewMatrix',
188
- 'projectionMatrix',
189
- 'normalMatrix',
190
- 'modelMatrix',
191
- 'cameraPosition',
192
- 'morphTargetInfluences',
193
- 'bindMatrix',
194
- 'bindMatrixInverse'
195
- ]
196
-
197
- if parameters[:use_vertex_texture]
198
- identifiers << 'boneTexture'
199
- identifiers << 'boneTextureWidth'
200
- identifiers << 'boneTextureHeight'
201
- else
202
- identifiers << 'boneGlobalMatrices'
203
- end
204
-
205
- if parameters[:logarithmic_depth_buffer]
206
- identifiers << 'logDepthBufFC'
207
- end
208
-
209
- uniforms.each do |k, v|
210
- identifiers << k.to_s
211
- end
212
-
213
- @uniforms = {}
214
- identifiers.each do |id|
215
- @uniforms[id] = glGetUniformLocation(program, id)
216
- end
217
- end
218
-
219
- def cache_attribute_locations(attributes, parameters)
220
- identifiers = [
221
- 'position',
222
- 'normal',
223
- 'uv',
224
- 'uv2',
225
- 'tangent',
226
- 'color',
227
- 'skinIndex',
228
- 'skinWeight',
229
- 'lineDistance'
230
- ]
231
-
232
- parameters[:max_morph_targets].times do |i|
233
- identifiers << "morphTarget#{i}"
234
- end
235
-
236
- parameters[:max_morph_normals].times do |i|
237
- identifiers << "morphNormal#{i}"
238
- end
239
-
240
- attributes.each do |k, v|
241
- identifiers << k
242
- end
243
-
244
- @attributes = {}
245
- identifiers.each do |id|
246
- @attributes[id] = glGetAttribLocation(program, id)
247
- end
248
- end
249
- end
250
- end