mittsu 0.4.1 → 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 +3 -38
- 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/uniform.rb +23 -0
- data/lib/mittsu/core.rb +1 -0
- data/lib/mittsu/loaders/stl_loader.rb +186 -0
- data/lib/mittsu/loaders.rb +1 -0
- 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 +28 -199
- data/install-glfw.ps1 +0 -13
- data/lib/mittsu/renderers/generic_lib.rb +0 -125
- data/lib/mittsu/renderers/glfw_lib.rb +0 -64
- 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,58 +0,0 @@
|
|
1
|
-
require 'fiddle'
|
2
|
-
|
3
|
-
module Mittsu
|
4
|
-
class OpenGLShader
|
5
|
-
attr_reader :shader
|
6
|
-
|
7
|
-
def initialize(type, string)
|
8
|
-
@shader = glCreateShader(type)
|
9
|
-
# filename = type == GL_VERTEX_SHADER ? 'vertex.glsl' : 'fragment.glsl'
|
10
|
-
# File.write filename, string
|
11
|
-
|
12
|
-
string_pointer = Fiddle::Pointer[string]
|
13
|
-
string_length = Fiddle::Pointer[string.length]
|
14
|
-
|
15
|
-
glShaderSource(@shader, 1, string_pointer.ref, string_length.ref)
|
16
|
-
glCompileShader(@shader)
|
17
|
-
|
18
|
-
if !compile_status
|
19
|
-
puts "ERROR: Mittsu::OpenGLShader: Shader couldn't compile"
|
20
|
-
end
|
21
|
-
|
22
|
-
log_info = shader_info_log
|
23
|
-
if !log_info.empty?
|
24
|
-
puts "WARNING: Mittsu::OpenGLShader: glGetShaderInfoLog, #{log_info}"
|
25
|
-
puts add_line_numbers(string)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def compile_status
|
32
|
-
ptr = ' '*8
|
33
|
-
glGetShaderiv @shader, GL_COMPILE_STATUS, ptr
|
34
|
-
ptr.unpack('L')[0]
|
35
|
-
end
|
36
|
-
|
37
|
-
def shader_info_log
|
38
|
-
ptr = ' '*8
|
39
|
-
glGetShaderiv @shader, GL_INFO_LOG_LENGTH, ptr
|
40
|
-
length = ptr.unpack('L')[0]
|
41
|
-
|
42
|
-
if length > 0
|
43
|
-
log = ' '*length
|
44
|
-
glGetShaderInfoLog @shader, length, ptr, log
|
45
|
-
log.unpack("A#{length}")[0]
|
46
|
-
else
|
47
|
-
''
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def add_line_numbers(string)
|
52
|
-
string.split("\n").each_with_index.map { |line, i|
|
53
|
-
line_number = "#{i + 1}".rjust(4, ' ')
|
54
|
-
"#{line_number}: #{line}"
|
55
|
-
}.join("\n")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,205 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class OpenGLState
|
3
|
-
def initialize
|
4
|
-
@new_attributes = Array.new(16) # Uint8Array
|
5
|
-
@enabled_attributes = Array.new(16) # Uint8Array
|
6
|
-
|
7
|
-
@current_blending = nil
|
8
|
-
@current_blend_equation = nil
|
9
|
-
@current_blend_src = nil
|
10
|
-
@current_blend_dst = nil
|
11
|
-
@current_blend_equation_alpha = nil
|
12
|
-
@current_blend_src_alpha = nil
|
13
|
-
@current_blend_dst_alpha = nil
|
14
|
-
|
15
|
-
@current_depth_test = nil
|
16
|
-
@current_depth_write = nil
|
17
|
-
|
18
|
-
@current_color_write = nil
|
19
|
-
|
20
|
-
@current_double_sided = nil
|
21
|
-
@current_flip_sided = nil
|
22
|
-
|
23
|
-
@current_line_width = nil
|
24
|
-
|
25
|
-
@current_polygon_offset = nil
|
26
|
-
@current_polygon_offset_factor = nil
|
27
|
-
@current_polygon_offset_units = nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def init_attributes
|
31
|
-
@new_attributes.length.times do |i|
|
32
|
-
@new_attributes[i] = false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def enable_attribute(attribute)
|
37
|
-
glEnableVertexAttribArray(attribute)
|
38
|
-
@new_attributes[attribute] = true
|
39
|
-
|
40
|
-
if !@enabled_attributes[attribute]
|
41
|
-
# glEnableVertexAttribArray(attribute)
|
42
|
-
@enabled_attributes[attribute] = true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def disable_unused_attributes
|
47
|
-
@enabled_attributes.length.times do |i|
|
48
|
-
if @enabled_attributes[i] && !@new_attributes[i]
|
49
|
-
glDisableVertexAttribArray(i)
|
50
|
-
@enabled_attributes[i] = false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def set_blending(blending, blend_equation = nil, blend_src = nil, blend_dst = nil, blend_equation_alpha = nil, blend_src_alpha = nil, blend_dst_alpha = nil)
|
56
|
-
if blending != @current_blending
|
57
|
-
case blending
|
58
|
-
when NoBlending
|
59
|
-
glDisable(GL_BLEND)
|
60
|
-
when AdditiveBlending
|
61
|
-
glEnable(GL_BLEND)
|
62
|
-
glBlendEquation(GL_FUNC_ADD)
|
63
|
-
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
|
64
|
-
when SubtractiveBlending
|
65
|
-
# TODO: Find blendFuncSeparate() combination ???
|
66
|
-
glEnable(GL_BLEND)
|
67
|
-
glBlendEquation(GL_FUNC_ADD)
|
68
|
-
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR)
|
69
|
-
when MultiplyBlending
|
70
|
-
# TODO: Find blendFuncSeparate() combination ???
|
71
|
-
glEnable(GL_BLEND)
|
72
|
-
glBlendEquation(GL_FUNC_ADD)
|
73
|
-
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR)
|
74
|
-
when CustomBlending
|
75
|
-
glEnable(GL_BLEND)
|
76
|
-
else
|
77
|
-
glEnable(GL_BLEND)
|
78
|
-
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD)
|
79
|
-
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
|
80
|
-
end
|
81
|
-
|
82
|
-
@current_blending = blending
|
83
|
-
end
|
84
|
-
|
85
|
-
if blending == CustomBlending
|
86
|
-
blend_equation_alpha ||= blend_equation
|
87
|
-
blend_src_alpha ||= blend_src
|
88
|
-
blend_dst_alpha ||= blend_dst
|
89
|
-
|
90
|
-
if blend_equation != @current_blend_equation || blend_equation_alpha != @current_blend_equation_alpha
|
91
|
-
glBlendEquationSeparate(GL_MITTSU_PARAMS[blend_equation], GL_MITTSU_PARAMS[blend_equation_alpha])
|
92
|
-
|
93
|
-
@current_blend_equation = blend_equation
|
94
|
-
@current_blend_equation_alpha = blend_equation_alpha
|
95
|
-
end
|
96
|
-
|
97
|
-
if blend_src != @current_blend_src || blend_dst != @current_blend_dst || blend_src_alpha != @current_blend_src_alpha || blend_dst_alpha != @current_blend_dst_alpha
|
98
|
-
glBlendFuncSeparate(GL_MITTSU_PARAMS[blend_src], GL_MITTSU_PARAMS[blend_dst], GL_MITTSU_PARAMS[blend_src_alpha], GL_MITTSU_PARAMS[blend_dst_alpha])
|
99
|
-
|
100
|
-
@current_blend_src = nil
|
101
|
-
@current_blend_dst = nil
|
102
|
-
@current_blend_src_alpha = nil
|
103
|
-
@current_blend_dst_alpha = nil
|
104
|
-
end
|
105
|
-
else
|
106
|
-
@current_blend_equation = nil
|
107
|
-
@current_blend_src = nil
|
108
|
-
@current_blend_dst = nil
|
109
|
-
@current_blend_equation_alpha = nil
|
110
|
-
@current_blend_src_alpha = nil
|
111
|
-
@current_blend_dst_alpha = nil
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def set_depth_test(depth_test)
|
116
|
-
if @current_depth_test != depth_test
|
117
|
-
if depth_test
|
118
|
-
glEnable(GL_DEPTH_TEST)
|
119
|
-
else
|
120
|
-
glDisable(GL_DEPTH_TEST)
|
121
|
-
end
|
122
|
-
|
123
|
-
@current_depth_test = depth_test
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def set_depth_write(depth_write)
|
128
|
-
if @current_depth_write != depth_write
|
129
|
-
glDepthMask(depth_write ? GL_TRUE : GL_FALSE)
|
130
|
-
@current_depth_write = depth_write
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def set_color_write(color_write)
|
135
|
-
if @current_color_write != color_write
|
136
|
-
gl_color_write = color_write ? GL_TRUE : GL_FALSE
|
137
|
-
glColorMask(gl_color_write, gl_color_write, gl_color_write, gl_color_write)
|
138
|
-
@current_color_write = color_write
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def set_double_sided(double_sided)
|
143
|
-
if @current_double_sided != double_sided
|
144
|
-
if double_sided
|
145
|
-
glDisable(GL_CULL_FACE)
|
146
|
-
else
|
147
|
-
glEnable(GL_CULL_FACE)
|
148
|
-
end
|
149
|
-
|
150
|
-
@current_double_sided = double_sided
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def set_flip_sided(flip_sided)
|
155
|
-
if @current_flip_sided != flip_sided
|
156
|
-
if flip_sided
|
157
|
-
glFrontFace(GL_CW)
|
158
|
-
else
|
159
|
-
glFrontFace(GL_CCW)
|
160
|
-
end
|
161
|
-
|
162
|
-
@current_flip_sided = flip_sided
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def set_line_width(width)
|
167
|
-
if width != @current_line_width
|
168
|
-
glLineWidth(width)
|
169
|
-
@current_line_width = width
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def set_polygon_offset(polygon_offset, factor, units)
|
174
|
-
if @current_polygon_offset != polygon_offset
|
175
|
-
if polygon_offset
|
176
|
-
glEnable(GL_POLYGON_OFFSET_FILL)
|
177
|
-
else
|
178
|
-
glDisable(GL_POLYGON_OFFSET_FILL)
|
179
|
-
end
|
180
|
-
|
181
|
-
@current_polygon_offset = polygon_offset
|
182
|
-
end
|
183
|
-
|
184
|
-
if polygon_offset && (@current_polygon_offset_factor != factor || @current_polygon_offset_units != units)
|
185
|
-
glPolygonOffset(factor, units)
|
186
|
-
|
187
|
-
@current_polygon_offset_factor = factor
|
188
|
-
@current_polygon_offset_units = units
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def reset
|
193
|
-
@enabled_attributes.length.times do |i|
|
194
|
-
@enabled_attributes[i] = false
|
195
|
-
end
|
196
|
-
|
197
|
-
@current_blending = nil
|
198
|
-
@current_depth_test = nil
|
199
|
-
@current_depth_write = nil
|
200
|
-
@current_color_write = nil
|
201
|
-
@current_double_sided = nil
|
202
|
-
@current_flip_sided = nil
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
@@ -1,417 +0,0 @@
|
|
1
|
-
require 'mittsu/math'
|
2
|
-
require 'mittsu/renderers/opengl_render_target'
|
3
|
-
|
4
|
-
module Mittsu
|
5
|
-
class ShadowMapPlugin
|
6
|
-
def initialize(renderer, lights, opengl_objects, opengl_objects_immediate)
|
7
|
-
@renderer, @lights = renderer, lights
|
8
|
-
@opengl_objects = opengl_objects
|
9
|
-
@opengl_objects_immediate = opengl_objects_immediate
|
10
|
-
|
11
|
-
@frustum = Frustum.new
|
12
|
-
@proj_screen_matrix = Matrix4.new
|
13
|
-
|
14
|
-
@min = Vector3.new
|
15
|
-
@max = Vector3.new
|
16
|
-
|
17
|
-
@matrix_position = Vector3.new
|
18
|
-
|
19
|
-
@render_list = []
|
20
|
-
|
21
|
-
depth_shader = ShaderLib[:depth_rgba]
|
22
|
-
depth_uniforms = UniformsUtils.clone(depth_shader.uniforms)
|
23
|
-
|
24
|
-
@depth_material = ShaderMaterial.new(
|
25
|
-
uniforms: depth_uniforms,
|
26
|
-
vertex_shader: depth_shader.vertex_shader,
|
27
|
-
fragment_shader: depth_shader.fragment_shader
|
28
|
-
)
|
29
|
-
|
30
|
-
@depth_material_morph = ShaderMaterial.new(
|
31
|
-
uniforms: depth_uniforms,
|
32
|
-
vertex_shader: depth_shader.vertex_shader,
|
33
|
-
fragment_shader: depth_shader.fragment_shader,
|
34
|
-
morph_targets: true
|
35
|
-
)
|
36
|
-
|
37
|
-
@depth_material_skin = ShaderMaterial.new(
|
38
|
-
uniforms: depth_uniforms,
|
39
|
-
vertex_shader: depth_shader.vertex_shader,
|
40
|
-
fragment_shader: depth_shader.fragment_shader,
|
41
|
-
skinning: true
|
42
|
-
)
|
43
|
-
|
44
|
-
@depth_material_morph_skin = ShaderMaterial.new(
|
45
|
-
uniforms: depth_uniforms,
|
46
|
-
vertex_shader: depth_shader.vertex_shader,
|
47
|
-
fragment_shader: depth_shader.fragment_shader,
|
48
|
-
morph_targets: true,
|
49
|
-
skinning: true
|
50
|
-
)
|
51
|
-
|
52
|
-
@depth_material.shadow_pass = true
|
53
|
-
@depth_material_morph.shadow_pass = true
|
54
|
-
@depth_material_skin.shadow_pass = true
|
55
|
-
@depth_material_morph_skin.shadow_pass = true
|
56
|
-
end
|
57
|
-
|
58
|
-
def render(scene, camera)
|
59
|
-
return unless @renderer.shadow_map_enabled
|
60
|
-
|
61
|
-
lights = []
|
62
|
-
fog = nil
|
63
|
-
|
64
|
-
# set GL state for depth map
|
65
|
-
|
66
|
-
glClearColor(1.0, 1.0, 1.0, 1.0)
|
67
|
-
glDisable(GL_BLEND)
|
68
|
-
|
69
|
-
glEnable(GL_CULL_FACE)
|
70
|
-
glFrontFace(GL_CCW)
|
71
|
-
|
72
|
-
if @renderer.shadow_map_cull_face = CullFaceFront
|
73
|
-
glCullFace(GL_FRONT)
|
74
|
-
else
|
75
|
-
glCullFace(GL_BACK)
|
76
|
-
end
|
77
|
-
|
78
|
-
@renderer.state.set_depth_test(true)
|
79
|
-
|
80
|
-
# process lights
|
81
|
-
# - skip lights that are not casting shadows
|
82
|
-
# - create virtual lights for cascaded shadow maps
|
83
|
-
|
84
|
-
@lights.select(&:cast_shadow).each do |light|
|
85
|
-
if light.is_a?(DirectionalLight) && light.shadow_cascade
|
86
|
-
light.shadow_cascade_count.times do |n|
|
87
|
-
if !light.shadow_cascade_array[n]
|
88
|
-
virtual_light = create_virtual_light(light, n)
|
89
|
-
virtual_light.original_camera = camera
|
90
|
-
|
91
|
-
gyro = Gyroscope.new
|
92
|
-
gyro.position.copy(light.shadow_cascade_offset)
|
93
|
-
|
94
|
-
gyro.add(virtual_light)
|
95
|
-
gyro.add(virtual_light.target)
|
96
|
-
|
97
|
-
camera.add(gyro)
|
98
|
-
|
99
|
-
light.shadow_cascade_array[n] = virtual_light
|
100
|
-
else
|
101
|
-
virtual_light = light.shadow_cascade_array[n]
|
102
|
-
end
|
103
|
-
|
104
|
-
update_virtual_light(light, n)
|
105
|
-
|
106
|
-
lights << virtual_light
|
107
|
-
end
|
108
|
-
else
|
109
|
-
lights << light
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# render depth map
|
114
|
-
|
115
|
-
lights.each do |light|
|
116
|
-
if !light.shadow_map
|
117
|
-
shadow_filter = LinearFilter
|
118
|
-
if @renderer.shadow_map_type == PCFSoftShadowMap
|
119
|
-
shadow_filter = NearestFilter
|
120
|
-
end
|
121
|
-
|
122
|
-
pars = { min_filter: shadow_filter, mag_filter: shadow_filter, format: RGBAFormat }
|
123
|
-
|
124
|
-
light.shadow_map = OpenGLRenderTarget.new(light.shadow_map_width, light.shadow_map_height, pars)
|
125
|
-
light.shadow_map.renderer = @renderer
|
126
|
-
light.shadow_map_size = Vector2.new(light.shadow_map_width, light.shadow_map_height)
|
127
|
-
|
128
|
-
light.shadow_matrix = Matrix4.new
|
129
|
-
end
|
130
|
-
|
131
|
-
if !light.shadow_camera
|
132
|
-
case light
|
133
|
-
when SpotLight
|
134
|
-
light.shadow_camera = PerspectiveCamera.new(light.shadow_camera_fov, light.shadow_map_width / light.shadow_map_height, light.shadow_camera_near, light.shadow_camera_far)
|
135
|
-
when DirectionalLight
|
136
|
-
light.shadow_camera = OrthographicCamera.new(light.shadow_camera_left, light.shadow_camera_right, light.shadow_camera_top, light.shadow_camera_bottom, light.shadow_camera_near, light.shadow_camera_far)
|
137
|
-
else
|
138
|
-
puts "ERROR: Mittsu::ShadowMapPlugin: Unsupported light type for shadow #{light.inspect}"
|
139
|
-
next
|
140
|
-
end
|
141
|
-
|
142
|
-
scene.add(light.shadow_camera)
|
143
|
-
scene.update_matrix_world if scene.auto_update
|
144
|
-
end
|
145
|
-
|
146
|
-
if light.shadow_camera_visible && !light.camera_helper
|
147
|
-
light.camera_helper = CameraHelper.new(light.shadow_camera)
|
148
|
-
scene.add(light.camera_helper)
|
149
|
-
end
|
150
|
-
|
151
|
-
if light.virtual? && virtual_light.original_camera == camera
|
152
|
-
update_shadow_camera(camera, light)
|
153
|
-
end
|
154
|
-
|
155
|
-
shadow_map = light.shadow_map
|
156
|
-
shadow_matrix = light.shadow_matrix
|
157
|
-
shadow_camera = light.shadow_camera
|
158
|
-
|
159
|
-
#
|
160
|
-
|
161
|
-
shadow_camera.position.set_from_matrix_position(light.matrix_world)
|
162
|
-
@matrix_position.set_from_matrix_position(light.target.matrix_world)
|
163
|
-
shadow_camera.look_at(@matrix_position)
|
164
|
-
shadow_camera.update_matrix_world
|
165
|
-
|
166
|
-
shadow_camera.matrix_world_inverse.inverse(shadow_camera.matrix_world)
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
|
171
|
-
light.camera_helper.visible = light.shadow_camera_visible if light.camera_helper
|
172
|
-
light.camera_helper.update_points if light.shadow_camera_visible
|
173
|
-
|
174
|
-
# compute shadow matrix
|
175
|
-
|
176
|
-
shadow_matrix.set(
|
177
|
-
0.5, 0.0, 0.0, 0.5,
|
178
|
-
0.0, 0.5, 0.0, 0.5,
|
179
|
-
0.0, 0.0, 0.5, 0.5,
|
180
|
-
0.0, 0.0, 0.0, 1.0
|
181
|
-
)
|
182
|
-
|
183
|
-
shadow_matrix.multiply(shadow_camera.projection_matrix)
|
184
|
-
shadow_matrix.multiply(shadow_camera.matrix_world_inverse)
|
185
|
-
|
186
|
-
# update camera matrices and frustum
|
187
|
-
|
188
|
-
@proj_screen_matrix.multiply_matrices(shadow_camera.projection_matrix, shadow_camera.matrix_world_inverse)
|
189
|
-
@frustum.set_from_matrix(@proj_screen_matrix)
|
190
|
-
|
191
|
-
# render shadow map
|
192
|
-
|
193
|
-
@renderer.set_render_target(shadow_map)
|
194
|
-
@renderer.clear
|
195
|
-
|
196
|
-
# set object matrices & frustum culling
|
197
|
-
|
198
|
-
@render_list.clear
|
199
|
-
|
200
|
-
project_object(scene, scene, shadow_camera)
|
201
|
-
|
202
|
-
# render regular obejcts
|
203
|
-
|
204
|
-
@render_list.each do |opengl_object|
|
205
|
-
object = opengl_object[:object]
|
206
|
-
buffer = opengl_object[:buffer]
|
207
|
-
|
208
|
-
# culling is overridden globally for all objects
|
209
|
-
# while rendering depth map
|
210
|
-
|
211
|
-
# need to deal with MeshFaceMaterial somehow
|
212
|
-
# in that case just use the first of material.materials for now
|
213
|
-
# (proper solution would require to break objects by materials
|
214
|
-
# similarly to regular rendering and then set corresponding
|
215
|
-
# depth materials per each chunk instead of just once per object)
|
216
|
-
|
217
|
-
object_material = get_object_material(object)
|
218
|
-
|
219
|
-
# TODO: SkinnedMesh/morph_targets
|
220
|
-
# use_morphing = !object.geometry.morph_targets.nil? && !object.geometry.morph_targets.empty?
|
221
|
-
# use_skinning = object.is_a?(SkinnedMesh) && object_material.skinning
|
222
|
-
|
223
|
-
# TODO: SkinnedMesh/morph_targets
|
224
|
-
# if object.custom_depth_material
|
225
|
-
# material = object.custom_depth_material
|
226
|
-
# elsif use_skinning
|
227
|
-
# material = use_morphing ? @depth_material_morph_skin : @depth_material_skin
|
228
|
-
# elsif use_morphing
|
229
|
-
# material = @deptth_material_morph
|
230
|
-
# else
|
231
|
-
material = @depth_material
|
232
|
-
# end
|
233
|
-
|
234
|
-
@renderer.set_material_faces(object_material)
|
235
|
-
|
236
|
-
if buffer.is_a?(BufferGeometry)
|
237
|
-
@renderer.render_buffer_direct(shadow_camera, @lights, fog, material, buffer, object)
|
238
|
-
else
|
239
|
-
@renderer.render_buffer(shadow_camera, @lights, fog, material, buffer, object)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
# set materices and rendr immeidate objects
|
244
|
-
|
245
|
-
@opengl_objects_immediate.each do |opengl_object_immediate|
|
246
|
-
opengl_object = opengl_object_immediate
|
247
|
-
object = opengl_object[:object]
|
248
|
-
|
249
|
-
if object.visible && object.cast_shadow
|
250
|
-
object[:_model_view_matrix].multiply_matrices(shadow_camera.matrix_womatrix_world_inverse, object.matrix_world)
|
251
|
-
@renderer.render_immediate_object(shadow_camera, @lights, fog, @depth_material, object)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# restore GL state
|
257
|
-
|
258
|
-
clear_color = @renderer.get_clear_color
|
259
|
-
clear_alpha = @renderer.get_clear_alpha
|
260
|
-
|
261
|
-
glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_alpha)
|
262
|
-
glEnable(GL_BLEND)
|
263
|
-
|
264
|
-
if @renderer.shadow_map_cull_face == CullFaceFront
|
265
|
-
glCullFace(GL_BACK)
|
266
|
-
end
|
267
|
-
|
268
|
-
@renderer.reset_gl_state
|
269
|
-
end
|
270
|
-
|
271
|
-
def project_object(scene, object, shadow_camera)
|
272
|
-
if object.visible
|
273
|
-
opengl_objects = @opengl_objects[object.id]
|
274
|
-
|
275
|
-
if opengl_objects && object.cast_shadow && (object.frustum_culled == false || @frustum.intersects_object?(object) == true)
|
276
|
-
opengl_objects.each do |opengl_object|
|
277
|
-
object.model_view_matrix.multiply_matrices(shadow_camera.matrix_world_inverse, object.matrix_world)
|
278
|
-
@render_list << opengl_object
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
object.children.each do |child|
|
283
|
-
project_object(scene, child, shadow_camera)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def create_virtual_light(light, cascade)
|
289
|
-
DirectionalLight.new.tap do |virtual_light|
|
290
|
-
virtual_light.is_virtual = true
|
291
|
-
|
292
|
-
virtual_light.only_shadow = true
|
293
|
-
virtual_light.cast_shadow = true
|
294
|
-
|
295
|
-
virtual_light.shadow_camera_near = light.shadow_camera_near
|
296
|
-
virtual_light.shadow_camera_far = light.shadow_camera_far
|
297
|
-
|
298
|
-
virtual_light.shadow_camera_left = light.shadow_camera_left
|
299
|
-
virtual_light.shadow_camera_right = light.shadow_camera_right
|
300
|
-
virtual_light.shadow_camera_bottom = light.shadow_camera_bottom
|
301
|
-
virtual_light.shadow_camera_top = light.shadow_camera_top
|
302
|
-
|
303
|
-
virtual_light.shadow_camera_visible = light.shadow_camera_visible
|
304
|
-
|
305
|
-
virtual_light.shadow_darkness = light.shadow_darkness
|
306
|
-
|
307
|
-
virtual_light.shadow_darkness = light.shadow_darkness
|
308
|
-
|
309
|
-
virtual_light.shadow_bias = light.shadow_cascade_bias[cascade]
|
310
|
-
virtual_light.shadow_map_width = light.shadow_cascade_width[cascade]
|
311
|
-
virtual_light.shadow_map_height = light.shadow_cascade_height[cascade]
|
312
|
-
|
313
|
-
points_world = virtual_light.points_world = []
|
314
|
-
points_frustum = virtual_light.points_frustum = []
|
315
|
-
|
316
|
-
8.times do
|
317
|
-
points_world << Vector3.new
|
318
|
-
points_frustum << Vector3.new
|
319
|
-
end
|
320
|
-
|
321
|
-
near_z = light.shadow_cascade_near_z[cascade]
|
322
|
-
far_z = light.shadow_cascade_far_z[cascade]
|
323
|
-
|
324
|
-
points_frustum[0].set(-1.0, -1.0, near_z)
|
325
|
-
points_frustum[1].set( 1.0, -1.0, near_z)
|
326
|
-
points_frustum[2].set(-1.0, 1.0, near_z)
|
327
|
-
points_frustum[3].set( 1.0, 1.0, near_z)
|
328
|
-
|
329
|
-
points_frustum[4].set(-1.0, -1.0, far_z)
|
330
|
-
points_frustum[5].set( 1.0, -1.0, far_z)
|
331
|
-
points_frustum[6].set(-1.0, 1.0, far_z)
|
332
|
-
points_frustum[7].set( 1.0, 1.0, far_z)
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
# synchronize virtual light with the original light
|
337
|
-
|
338
|
-
def update_virtual_light(light, cascade)
|
339
|
-
virtual_light = light.shadow_cascade_array[cascade]
|
340
|
-
|
341
|
-
virtual_light.position.copy(light.position)
|
342
|
-
virtual_light.target.position.copy(light.target.position)
|
343
|
-
virtual_light.look_at(virtual_light.target)
|
344
|
-
|
345
|
-
virtual_light.shadow_camera_visible = light.shadow_camera_visible
|
346
|
-
virtual_light.shadow_darkness = light.shadow_darkness
|
347
|
-
|
348
|
-
virtual_light.shadow_bias = light.shadow_cascade_bias[cascade]
|
349
|
-
|
350
|
-
near_z = light.shadow_cascade_near_z[cascade]
|
351
|
-
far_z = light.shadow_cascade_far_z[cascade]
|
352
|
-
|
353
|
-
points_frustum = virtual_light.points_frustum
|
354
|
-
|
355
|
-
points_frustum[0].z = near_z
|
356
|
-
points_frustum[1].z = near_z
|
357
|
-
points_frustum[2].z = near_z
|
358
|
-
points_frustum[3].z = near_z
|
359
|
-
|
360
|
-
points_frustum[4].z = far_z
|
361
|
-
points_frustum[5].z = far_z
|
362
|
-
points_frustum[6].z = far_z
|
363
|
-
points_frustum[7].z = far_z
|
364
|
-
end
|
365
|
-
|
366
|
-
# fit shadow camera's ortho frustum to camera frustum
|
367
|
-
|
368
|
-
def update_shadow_camera(camera, light)
|
369
|
-
shadow_camera = light.shadow_camera
|
370
|
-
points_frustum = light.pointa_frustum
|
371
|
-
points_world = light.points_world
|
372
|
-
|
373
|
-
@min.set(Float::INFINITY, Float::INFINITY, Float::INFINITY)
|
374
|
-
@max.set(-Float::INFINITY, -Float::INFINITY, -Float::INFINITY)
|
375
|
-
|
376
|
-
8.times do |i|
|
377
|
-
p = points_world[i]
|
378
|
-
|
379
|
-
p.copy(points_frustum[i])
|
380
|
-
p.unproject(camera)
|
381
|
-
|
382
|
-
p.apply_matrix4(shadow_camera.matrix_world_inverse)
|
383
|
-
|
384
|
-
@min.x = p.x if (p.x < @min.x)
|
385
|
-
@max.x = p.x if (p.x > @max.x)
|
386
|
-
|
387
|
-
@min.y = p.y if (p.y < @min.y)
|
388
|
-
@max.y = p.y if (p.y > @max.y)
|
389
|
-
|
390
|
-
@min.z = p.z if (p.z < @min.z)
|
391
|
-
@max.z = p.z if (p.z > @max.z)
|
392
|
-
end
|
393
|
-
|
394
|
-
shadow_camera.left = @min.x
|
395
|
-
shadow_camera.right = @max.x
|
396
|
-
shadow_camera.top = @max.y
|
397
|
-
shadow_camera.bottom = @min.y
|
398
|
-
|
399
|
-
# can't really fit near/far
|
400
|
-
# shadow_camera.near = @min.x
|
401
|
-
# shadow_camera.far = @max.z
|
402
|
-
|
403
|
-
shadow_camera.update_projection_matrix
|
404
|
-
end
|
405
|
-
|
406
|
-
# For the moment just ignore objects that have multiple materials with different animation methods
|
407
|
-
# Only the frst material will be taken into account for deciding which depth material to use for shadow maps
|
408
|
-
|
409
|
-
def get_object_material(object)
|
410
|
-
if object.material.is_a?(MeshFaceMaterial)
|
411
|
-
object.material.materials[0]
|
412
|
-
else
|
413
|
-
object.material
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|