mittsu 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-workflow.yml +5 -44
- data/Gemfile +0 -4
- data/README.md +16 -130
- data/bin/console +0 -4
- data/lib/mittsu/cameras/cube_camera.rb +1 -1
- data/lib/mittsu/core/geometry.rb +3 -3
- data/lib/mittsu/core/object_3d.rb +29 -47
- data/lib/mittsu/core/uniform.rb +23 -0
- data/lib/mittsu/core.rb +1 -0
- data/lib/mittsu/loaders/obj_loader.rb +11 -5
- data/lib/mittsu/loaders/stl_loader.rb +186 -0
- data/lib/mittsu/loaders.rb +1 -0
- data/lib/mittsu/math/box3.rb +4 -4
- data/lib/mittsu/objects/line.rb +1 -3
- data/lib/mittsu/objects/mesh.rb +9 -12
- data/lib/mittsu/objects/point_cloud.rb +3 -3
- data/lib/mittsu/textures/render_target.rb +93 -0
- data/lib/mittsu/textures/render_target_cube.rb +8 -0
- data/lib/mittsu/textures/texture.rb +1 -1
- data/lib/mittsu/textures.rb +2 -0
- data/lib/mittsu/version.rb +1 -1
- data/lib/mittsu.rb +0 -1
- data/mittsu.gemspec +8 -12
- metadata +33 -204
- data/install-glfw.ps1 +0 -13
- data/lib/mittsu/renderers/generic_lib.rb +0 -122
- data/lib/mittsu/renderers/glfw_lib.rb +0 -62
- data/lib/mittsu/renderers/glfw_window.rb +0 -233
- data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
- data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
- data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
- data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
- data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
- data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
- data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
- data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
- data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
- data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
- data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
- data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
- data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
- data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
- data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
- data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
- data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
- data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
- data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
- data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
- data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
- data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
- data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
- data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
- data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
- data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
- data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
- data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
- data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
- data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
- data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
- data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
- data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
- data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
- data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
- data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
- data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
- 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 +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
- data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
- data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
- data/lib/mittsu/renderers.rb +0 -1
@@ -1,47 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class SpotLight
|
3
|
-
TYPE = :spot
|
4
|
-
|
5
|
-
class Cache < Struct.new(:length, :count, :colors, :directions, :distances, :positions, :exponents, :angles_cos, :decays)
|
6
|
-
def initialize
|
7
|
-
super(0, 0, [], [], [], [], [], [], [])
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
self.length = 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup_specific(index)
|
16
|
-
offset = index * 3
|
17
|
-
|
18
|
-
OpenGLHelper.set_color_linear(@cache.colors, offset, color, intensity)
|
19
|
-
|
20
|
-
@_direction.set_from_matrix_position(matrix_world)
|
21
|
-
|
22
|
-
positions = @cache.positions
|
23
|
-
positions[offset] = @_direction.x
|
24
|
-
positions[offset + 1] = @_direction.y
|
25
|
-
positions[offset + 2] = @_direction.z
|
26
|
-
|
27
|
-
@cache.distances[index] = distance
|
28
|
-
|
29
|
-
@_vector3.set_from_matrix_position(target.matrix_world)
|
30
|
-
@_direction.sub(@_vector3)
|
31
|
-
@_direction.normalize
|
32
|
-
|
33
|
-
directions = @cache.directions
|
34
|
-
directions[offset] = @_direction.x
|
35
|
-
directions[offset + 1] = @_direction.y
|
36
|
-
directions[offset + 2] = @_direction.z
|
37
|
-
|
38
|
-
@cache.angles_cos[index] = ::Math.cos(angle)
|
39
|
-
@cache.exponents[index] = exponent;
|
40
|
-
@cache.decays[index] = distance.zero? ? 0.0 : decay
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_sym
|
44
|
-
:spot
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class LineBasicMaterial
|
3
|
-
def refresh_uniforms(uniforms)
|
4
|
-
uniforms['diffuse'].value = color
|
5
|
-
uniforms['opacity'].value = opacity
|
6
|
-
end
|
7
|
-
|
8
|
-
def init_shader
|
9
|
-
@shader = ShaderLib.create_shader(shader_id)
|
10
|
-
end
|
11
|
-
|
12
|
-
def shader_id
|
13
|
-
:basic
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,274 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class Material
|
3
|
-
# TODO: init_shader for these material-types
|
4
|
-
# MeshDepthMaterial => :depth, # TODO...
|
5
|
-
# MeshNormalMaterial => :normal, # TODO...
|
6
|
-
# LineDashedMaterial => :dashed, # TODO...
|
7
|
-
# PointCloudMaterial => :particle_basic # TODO...
|
8
|
-
|
9
|
-
attr_accessor :shadow_pass
|
10
|
-
attr_reader :shader, :uniforms_list
|
11
|
-
|
12
|
-
def init(lights, fog, object, renderer)
|
13
|
-
@renderer = renderer
|
14
|
-
|
15
|
-
add_event_listener(:dispose, @renderer.method(:on_material_dispose))
|
16
|
-
|
17
|
-
init_shader
|
18
|
-
|
19
|
-
self.program = find_or_create_program(lights, fog, object)
|
20
|
-
|
21
|
-
count_supported_morph_attributes(program.attributes)
|
22
|
-
|
23
|
-
@uniforms_list = get_uniforms_list
|
24
|
-
end
|
25
|
-
|
26
|
-
def set(renderer)
|
27
|
-
@renderer = renderer
|
28
|
-
|
29
|
-
if transparent
|
30
|
-
@renderer.state.set_blending(blending, blend_equation, blend_src, blend_dst, blend_equation_alpha, blend_src_alpha, blend_dst_alpha)
|
31
|
-
else
|
32
|
-
@renderer.state.set_blending(NoBlending)
|
33
|
-
end
|
34
|
-
|
35
|
-
@renderer.state.set_depth_test(depth_test)
|
36
|
-
@renderer.state.set_depth_write(depth_write)
|
37
|
-
@renderer.state.set_color_write(color_write)
|
38
|
-
@renderer.state.set_polygon_offset(polygon_offset, polygon_offset_factor, polygon_offset_units)
|
39
|
-
end
|
40
|
-
|
41
|
-
def needs_face_normals?
|
42
|
-
shading == FlatShading
|
43
|
-
end
|
44
|
-
|
45
|
-
def clear_custom_attributes
|
46
|
-
attributes.each do |attribute|
|
47
|
-
attribute.needs_update = false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def custom_attributes_dirty?
|
52
|
-
attributes.each do |attribute|
|
53
|
-
return true if attribute.needs_update
|
54
|
-
end
|
55
|
-
false
|
56
|
-
end
|
57
|
-
|
58
|
-
def refresh_uniforms(_)
|
59
|
-
# NOOP
|
60
|
-
end
|
61
|
-
|
62
|
-
def needs_camera_position_uniform?
|
63
|
-
env_map
|
64
|
-
end
|
65
|
-
|
66
|
-
def needs_view_matrix_uniform?
|
67
|
-
skinning
|
68
|
-
end
|
69
|
-
|
70
|
-
def needs_lights?
|
71
|
-
lights
|
72
|
-
end
|
73
|
-
|
74
|
-
protected
|
75
|
-
|
76
|
-
def init_shader
|
77
|
-
@shader = {
|
78
|
-
uniforms: uniforms,
|
79
|
-
vertex_shader: vertex_shader,
|
80
|
-
fragment_shader: fragment_shader
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def shader_id
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def allocate_lights(lights)
|
91
|
-
lights.reject { |light|
|
92
|
-
light.only_shadow || !light.visible
|
93
|
-
}.each_with_object({
|
94
|
-
directional: 0, point: 0, spot: 0, hemi: 0, other: 0
|
95
|
-
}) { |light, counts|
|
96
|
-
counts[light.to_sym] += 1
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
def allocate_shadows(lights)
|
101
|
-
max_shadows = 0
|
102
|
-
|
103
|
-
lights.each do |light|
|
104
|
-
next unless light.cast_shadow
|
105
|
-
|
106
|
-
max_shadows += 1 if light.is_a?(SpotLight)
|
107
|
-
max_shadows += 1 if light.is_a?(DirectionalLight) && !light.shadow_cascade
|
108
|
-
end
|
109
|
-
|
110
|
-
max_shadows
|
111
|
-
end
|
112
|
-
|
113
|
-
def allocate_bones(object = nil)
|
114
|
-
if @renderer.supports_bone_textures? && object && object.skeleton && object.skeleton.use_vertex_texture
|
115
|
-
return 1024
|
116
|
-
end
|
117
|
-
|
118
|
-
# default for when object is not specified
|
119
|
-
# ( for example when prebuilding shader
|
120
|
-
# to be used with multiple objects )
|
121
|
-
#
|
122
|
-
# - leave some extra space for other uniforms
|
123
|
-
# - limit here is ANGLE's 254 max uniform vectors
|
124
|
-
# (up to 54 should be safe)
|
125
|
-
|
126
|
-
n_vertex_uniforms = (glGetParameter(GL_MAX_VERTEX_UNIFORM_COMPONENTS) / 4.0).floor
|
127
|
-
n_vertex_matrices = ((n_vertex_uniforms - 20) / 4.0).floor
|
128
|
-
|
129
|
-
max_bones = n_vertex_matrices
|
130
|
-
|
131
|
-
# TODO: when SkinnedMesh exists
|
132
|
-
# if !object.nil? && object.is_a?(SkinnedMesh)
|
133
|
-
# max_bones = [object.skeleton.bones.length, max_bones].min
|
134
|
-
#
|
135
|
-
# if max_bones < object.skeleton.bones.length
|
136
|
-
# puts "WARNING: OpenGLRenderer: too many bones - #{object.skeleton.bones.length}, this GPU supports just #{max_bones}"
|
137
|
-
# end
|
138
|
-
# end
|
139
|
-
|
140
|
-
max_bones
|
141
|
-
end
|
142
|
-
|
143
|
-
def count_supported_morph_attributes(attributes)
|
144
|
-
if morph_targets
|
145
|
-
self.num_supported_morph_normals = count_supported_morph_attribute(attributes, 'morphTarget', @renderer.max_morph_normals)
|
146
|
-
end
|
147
|
-
if morph_normals
|
148
|
-
self.num_supported_morph_normals = count_supported_morph_attribute(attributes, 'morphNormal', @renderer.max_morph_normals)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def count_supported_morph_attribute(attributes, base, max)
|
153
|
-
max.times.reduce do |num, i|
|
154
|
-
attribute = attributes["#{base}#{i}"]
|
155
|
-
attribute && attribute >= 0 ? num + 1 : num
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def get_uniforms_list
|
160
|
-
@shader[:uniforms].map { |(key, uniform)|
|
161
|
-
location = program.uniforms[key]
|
162
|
-
if location
|
163
|
-
[uniform, location]
|
164
|
-
end
|
165
|
-
}.compact
|
166
|
-
end
|
167
|
-
|
168
|
-
def program_parameters(lights, fog, object)
|
169
|
-
# heuristics to create shader paramaters according to lights in the scene
|
170
|
-
# (not to blow over max_lights budget)
|
171
|
-
|
172
|
-
max_light_count = allocate_lights(lights)
|
173
|
-
max_shadows = allocate_shadows(lights)
|
174
|
-
max_bones = allocate_bones(object)
|
175
|
-
|
176
|
-
{
|
177
|
-
supports_vertex_textures: @renderer.supports_vertex_textures?,
|
178
|
-
|
179
|
-
map: !!map,
|
180
|
-
env_map: !!env_map,
|
181
|
-
env_map_mode: env_map && env_map.mapping,
|
182
|
-
light_map: !!light_map,
|
183
|
-
bump_map: !!light_map,
|
184
|
-
normal_map: !!normal_map,
|
185
|
-
specular_map: !!specular_map,
|
186
|
-
alpha_map: !!alpha_map,
|
187
|
-
|
188
|
-
combine: combine,
|
189
|
-
|
190
|
-
vertex_colors: vertex_colors,
|
191
|
-
|
192
|
-
fog: fog,
|
193
|
-
use_fog: fog,
|
194
|
-
# fog_exp: fog.is_a?(FogExp2), # TODO: when FogExp2 exists
|
195
|
-
|
196
|
-
flat_shading: shading == FlatShading,
|
197
|
-
|
198
|
-
size_attenuation: size_attenuation,
|
199
|
-
logarithmic_depth_buffer: @renderer.logarithmic_depth_buffer,
|
200
|
-
|
201
|
-
skinning: skinning,
|
202
|
-
max_bones: max_bones,
|
203
|
-
use_vertex_texture: @renderer.supports_bone_textures?,
|
204
|
-
|
205
|
-
morph_targets: morph_targets,
|
206
|
-
morph_normals: morph_normals,
|
207
|
-
max_morph_targets: @renderer.max_morph_targets,
|
208
|
-
max_morph_normals: @renderer.max_morph_normals,
|
209
|
-
|
210
|
-
max_dir_lights: max_light_count[:directional],
|
211
|
-
max_point_lights: max_light_count[:point],
|
212
|
-
max_spot_lights: max_light_count[:spot],
|
213
|
-
max_hemi_lights: max_light_count[:hemi],
|
214
|
-
|
215
|
-
max_shadows: max_shadows,
|
216
|
-
shadow_map_enabled: @renderer.shadow_map_enabled? && object.receive_shadow && max_shadows > 0,
|
217
|
-
shadow_map_type: @renderer.shadow_map_type,
|
218
|
-
shadow_map_debug: @renderer.shadow_map_debug,
|
219
|
-
shadow_map_cascade: @renderer.shadow_map_cascade,
|
220
|
-
|
221
|
-
alpha_test: alpha_test,
|
222
|
-
metal: metal,
|
223
|
-
wrap_around: wrap_around,
|
224
|
-
double_sided: side == DoubleSide,
|
225
|
-
flip_sided: side == BackSide
|
226
|
-
}
|
227
|
-
end
|
228
|
-
|
229
|
-
def program_slug(parameters)
|
230
|
-
chunks = []
|
231
|
-
|
232
|
-
if shader_id
|
233
|
-
chunks << shader_id
|
234
|
-
else
|
235
|
-
chunks << fragment_shader
|
236
|
-
chunks << vertex_shader
|
237
|
-
end
|
238
|
-
|
239
|
-
if !defines.nil?
|
240
|
-
defines.each do |(name, define)|
|
241
|
-
chunks << name
|
242
|
-
chunks << define
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
parameters.each do |(name, parameter)|
|
247
|
-
chunks << name
|
248
|
-
chunks << parameter
|
249
|
-
end
|
250
|
-
|
251
|
-
chunks.join
|
252
|
-
end
|
253
|
-
|
254
|
-
def find_or_create_program(lights, fog, object)
|
255
|
-
parameters = program_parameters(lights, fog, object)
|
256
|
-
code = program_slug(parameters)
|
257
|
-
|
258
|
-
program = @renderer.programs.find do |program_info|
|
259
|
-
program_info.code == code
|
260
|
-
end
|
261
|
-
|
262
|
-
if program.nil?
|
263
|
-
program = OpenGLProgram.new(@renderer, code, self, parameters)
|
264
|
-
@renderer.programs.push(program)
|
265
|
-
|
266
|
-
@renderer.info[:memory][:programs] = @renderer.programs.length
|
267
|
-
else
|
268
|
-
program.used_times += 1
|
269
|
-
end
|
270
|
-
|
271
|
-
program
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'mittsu/renderers/opengl/materials/opengl_material_basics'
|
2
|
-
|
3
|
-
module Mittsu
|
4
|
-
class MeshBasicMaterial
|
5
|
-
include OpenGLMaterialBasics
|
6
|
-
|
7
|
-
def refresh_uniforms(uniforms)
|
8
|
-
refresh_uniforms_basic(uniforms)
|
9
|
-
end
|
10
|
-
|
11
|
-
protected
|
12
|
-
|
13
|
-
def init_shader
|
14
|
-
@shader = ShaderLib.create_shader(shader_id)
|
15
|
-
end
|
16
|
-
|
17
|
-
def shader_id
|
18
|
-
:basic
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'mittsu/renderers/opengl/materials/opengl_material_basics'
|
2
|
-
|
3
|
-
module Mittsu
|
4
|
-
class MeshLambertMaterial
|
5
|
-
include OpenGLMaterialBasics
|
6
|
-
|
7
|
-
def refresh_uniforms(uniforms)
|
8
|
-
refresh_uniforms_basic(uniforms)
|
9
|
-
|
10
|
-
uniforms['emissive'].value = emissive
|
11
|
-
|
12
|
-
if wrap_around
|
13
|
-
uniforms['wrapRGB'].value.copy(wrap_rgb)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def needs_view_matrix_uniform?
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def needs_lights?
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
def init_shader
|
26
|
-
@shader = ShaderLib.create_shader(shader_id)
|
27
|
-
end
|
28
|
-
|
29
|
-
def shader_id
|
30
|
-
:lambert
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'mittsu/renderers/opengl/materials/opengl_material_basics'
|
2
|
-
|
3
|
-
module Mittsu
|
4
|
-
class MeshPhongMaterial
|
5
|
-
include OpenGLMaterialBasics
|
6
|
-
|
7
|
-
def needs_face_normals?
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
def refresh_uniforms(uniforms)
|
12
|
-
refresh_uniforms_basic(uniforms)
|
13
|
-
|
14
|
-
uniforms['shininess'].value = shininess
|
15
|
-
|
16
|
-
uniforms['emissive'].value = emissive
|
17
|
-
uniforms['specular'].value = specular
|
18
|
-
|
19
|
-
if wrap_around
|
20
|
-
uniforms['wrapRGB'].value.copy(wrap_rgb)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def needs_camera_position_uniform?
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
def needs_view_matrix_uniform?
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
def needs_lights?
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
def init_shader
|
37
|
-
@shader = ShaderLib.create_shader(shader_id)
|
38
|
-
end
|
39
|
-
|
40
|
-
def shader_id
|
41
|
-
:phong
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
module OpenGLMaterialBasics
|
3
|
-
def refresh_uniforms_basic(uniforms)
|
4
|
-
refresh_map_uniforms(uniforms)
|
5
|
-
refresh_env_map_uniforms(uniforms)
|
6
|
-
refresh_other_uniforms(uniforms)
|
7
|
-
end
|
8
|
-
|
9
|
-
def refresh_map_uniforms(uniforms)
|
10
|
-
uniforms['map'].value = map
|
11
|
-
uniforms['lightMap'].value = light_map
|
12
|
-
uniforms['specularMap'].value = specular_map
|
13
|
-
uniforms['alphaMap'].value = alpha_map
|
14
|
-
|
15
|
-
if bump_map
|
16
|
-
uniforms['bumpMap'].value = bump_map
|
17
|
-
uniforms['bumpScale'].value = bump_scale
|
18
|
-
end
|
19
|
-
|
20
|
-
if normal_map
|
21
|
-
uniforms['normalMap'].value = normal_map
|
22
|
-
uniforms['normalScale'].value.copy(normal_scale)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def refresh_env_map_uniforms(uniforms)
|
27
|
-
uv_scale_map = get_uv_scale_map
|
28
|
-
|
29
|
-
if uv_scale_map
|
30
|
-
offset = uv_scale_map.offset
|
31
|
-
repeat = uv_scale_map.repeat
|
32
|
-
|
33
|
-
uniforms['offsetRepeat'].value.set(offset.x, offset.y, repeat.x, repeat.y)
|
34
|
-
end
|
35
|
-
|
36
|
-
uniforms['envMap'].value = env_map
|
37
|
-
# TODO: when OpenGLRenderTargetCube exists
|
38
|
-
# uniforms['flipEnvMap'].value = envMap.is_a?(OpenGLRenderTargetCube) ? 1 : - 1
|
39
|
-
end
|
40
|
-
|
41
|
-
def refresh_other_uniforms(uniforms)
|
42
|
-
uniforms['opacity'].value = opacity
|
43
|
-
uniforms['diffuse'].value = color
|
44
|
-
|
45
|
-
uniforms['reflectivity'].value = reflectivity
|
46
|
-
uniforms['refractionRatio'].value = refraction_ratio
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_uv_scale_map
|
50
|
-
map ||
|
51
|
-
specular_map ||
|
52
|
-
normal_map ||
|
53
|
-
bump_map ||
|
54
|
-
alpha_map
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class PointCloudMaterial
|
3
|
-
def refresh_uniforms(uniforms)
|
4
|
-
uniforms['psColor'].value = color
|
5
|
-
uniforms['opacity'].value = opacity
|
6
|
-
uniforms['size'].value = size
|
7
|
-
# uniforms['scale'].value = _canvas.height / 2.0 # TODO get window height?
|
8
|
-
|
9
|
-
uniforms['map'].value = map
|
10
|
-
|
11
|
-
if !map.nil?
|
12
|
-
offset = material.map.offset
|
13
|
-
repeat = material.map.repeat
|
14
|
-
|
15
|
-
uniforms['offsetRepeat'].value.set(offset.x, offset.y, repeat.x, repeat.y)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def init_shader
|
20
|
-
@shader = ShaderLib.create_shader(shader_id)
|
21
|
-
end
|
22
|
-
|
23
|
-
def shader_id
|
24
|
-
:particle_basic
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class Line
|
3
|
-
def render_buffer(camera, lights, fog, material, geometry_group, update_buffers)
|
4
|
-
opengl_mode = mode == LineStrip ? GL_LINE_STRIP : GL_LINES
|
5
|
-
|
6
|
-
@renderer.state.set_line_width(material.line_width * @renderer.pixel_ratio)
|
7
|
-
|
8
|
-
glDrawArrays(opengl_mode, 0, geometry_group.line_count)
|
9
|
-
|
10
|
-
@renderer.info[:render][:calls] += 1
|
11
|
-
end
|
12
|
-
|
13
|
-
def update
|
14
|
-
# TODO: glBindVertexArray ???
|
15
|
-
material = buffer_material(geometry)
|
16
|
-
custom_attributes_dirty = material.attributes && material.custom_attributes_dirty?
|
17
|
-
|
18
|
-
if geometry.vertices_need_update || geometry.colors_need_update || geometry.line_distances_need_update || custom_attributes_dirty
|
19
|
-
geometry.set_line_buffers(GL_DYNAMIC_DRAW)
|
20
|
-
end
|
21
|
-
|
22
|
-
geometry.vertices_need_update = false
|
23
|
-
geometry.colors_need_update = false
|
24
|
-
geometry.line_distances_need_update = false
|
25
|
-
|
26
|
-
material.attributes && material.clear_custom_attributes
|
27
|
-
end
|
28
|
-
|
29
|
-
def init_geometry
|
30
|
-
geometry.renderer = @renderer
|
31
|
-
if geometry.vertex_buffer.nil?
|
32
|
-
geometry.create_line_buffers
|
33
|
-
geometry.init_line_buffers(self)
|
34
|
-
|
35
|
-
geometry.vertices_need_update = true
|
36
|
-
geometry.colors_need_update = true
|
37
|
-
geometry.line_distances_need_update = true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def add_opengl_object
|
42
|
-
@renderer.add_opengl_object(geometry, self)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class Mesh
|
3
|
-
attr_accessor :renderer
|
4
|
-
|
5
|
-
def render_buffer(camera, lights, fog, material, geometry_group, update_buffers)
|
6
|
-
type = GL_UNSIGNED_INT # geometry_group.type_array == Uint32Array ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT
|
7
|
-
|
8
|
-
# wireframe
|
9
|
-
if material.wireframe
|
10
|
-
@renderer.state.set_line_width(material.wireframe_linewidth * @renderer.pixel_ratio)
|
11
|
-
|
12
|
-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry_group.line_buffer) if update_buffers
|
13
|
-
glDrawElements(GL_LINES, geometry_group.line_count, type, 0)
|
14
|
-
|
15
|
-
# triangles
|
16
|
-
else
|
17
|
-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry_group.face_buffer) if update_buffers
|
18
|
-
glDrawElements(GL_TRIANGLES, geometry_group.face_count, type, 0)
|
19
|
-
end
|
20
|
-
|
21
|
-
@renderer.info[:render][:calls] += 1
|
22
|
-
@renderer.info[:render][:vertices] += geometry_group.face_count
|
23
|
-
@renderer.info[:render][:faces] += geometry_group.face_count / 3
|
24
|
-
end
|
25
|
-
|
26
|
-
def update
|
27
|
-
# check all geometry groubs
|
28
|
-
mat = nil
|
29
|
-
geometry.groups.each do |geometry_group|
|
30
|
-
# TODO: place to put this???
|
31
|
-
# glBindVertexArray(geometry_group.vertex_array_object)
|
32
|
-
mat = buffer_material(geometry_group)
|
33
|
-
|
34
|
-
custom_attributes_dirty = mat.attributes && mat.custom_attributes_dirty?
|
35
|
-
|
36
|
-
if geometry.vertices_need_update || geometry.morph_targets_need_update || geometry.elements_need_update || geometry.uvs_need_update || geometry.normals_need_update || geometry.colors_need_update || geometry.tangents_need_update || custom_attributes_dirty
|
37
|
-
geometry_group.set_mesh_buffers(self, GL_DYNAMIC_DRAW, !geometry.dynamic, mat)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
geometry.vertices_need_update = false
|
42
|
-
geometry.morph_targets_need_update = false
|
43
|
-
geometry.elements_need_update = false
|
44
|
-
geometry.uvs_need_update = false
|
45
|
-
geometry.normals_need_update = false
|
46
|
-
geometry.colors_need_update = false
|
47
|
-
geometry.tangents_need_update = false
|
48
|
-
|
49
|
-
mat.attributes && mat.clear_custom_attributes
|
50
|
-
end
|
51
|
-
|
52
|
-
def init_geometry
|
53
|
-
geometry.renderer = @renderer
|
54
|
-
geometry.init_geometry_groups(self)
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_opengl_object
|
58
|
-
case geometry
|
59
|
-
when BufferGeometry
|
60
|
-
@renderer.add_opengl_object(geometry, self)
|
61
|
-
when Geometry
|
62
|
-
geometry.groups.each do |group|
|
63
|
-
@renderer.add_opengl_object(group, self)
|
64
|
-
end
|
65
|
-
else
|
66
|
-
raise "GEOMETRY IS NULL"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class PointCloud
|
3
|
-
def render_buffer(camera, lights, fog, material, geometry_group, update_buffers)
|
4
|
-
glDrawArrays(GL_POINTS, 0, geometry_group.particle_count)
|
5
|
-
|
6
|
-
@renderer.info[:render][:calls] += 1
|
7
|
-
@renderer.info[:render][:points] += geometry_group.particle_count
|
8
|
-
end
|
9
|
-
|
10
|
-
def update
|
11
|
-
material = buffer_material(geometry)
|
12
|
-
custom_attributes_dirty = material.attributes && material.custom_attributes_dirty?
|
13
|
-
|
14
|
-
if geometry.vertices_need_update || geometry.colors_need_update || custom_attributes_dirty
|
15
|
-
geometry.set_particle_buffers(GL_DYNAMIC_DRAW)
|
16
|
-
end
|
17
|
-
|
18
|
-
geometry.vertices_need_update = false
|
19
|
-
geometry.colors_need_update = false
|
20
|
-
|
21
|
-
material.attributes && material.clear_custom_attributes
|
22
|
-
end
|
23
|
-
|
24
|
-
def init_geometry
|
25
|
-
geometry.renderer = @renderer
|
26
|
-
if geometry.vertex_buffer.nil?
|
27
|
-
geometry.create_particle_buffers
|
28
|
-
geometry.init_particle_buffers(self)
|
29
|
-
|
30
|
-
geometry.vertices_need_update = true
|
31
|
-
geometry.colors_need_update = true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_opengl_object
|
36
|
-
@renderer.add_opengl_object(geometry, self)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|