mittsu-opengl 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +18 -0
- data/.github/workflows/build-workflow.yml +67 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +1158 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +195 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/install-glfw.ps1 +13 -0
- data/lib/mittsu/generic_lib.rb +116 -0
- data/lib/mittsu/glfw/lib.rb +58 -0
- data/lib/mittsu/glfw/window.rb +231 -0
- data/lib/mittsu/opengl/buffer.rb +13 -0
- data/lib/mittsu/opengl/default_target.rb +50 -0
- data/lib/mittsu/opengl/geometry_group.rb +758 -0
- data/lib/mittsu/opengl/geometry_like.rb +132 -0
- data/lib/mittsu/opengl/gl_debug.rb +85 -0
- data/lib/mittsu/opengl/gl_extensions.rb +42 -0
- data/lib/mittsu/opengl/gl_mittsu_params.rb +53 -0
- data/lib/mittsu/opengl/helper.rb +120 -0
- data/lib/mittsu/opengl/implementation.rb +31 -0
- data/lib/mittsu/opengl/lib.rb +19 -0
- data/lib/mittsu/opengl/light_renderer.rb +43 -0
- data/lib/mittsu/opengl/material_basics.rb +57 -0
- data/lib/mittsu/opengl/plugins/shadow_map_plugin.rb +416 -0
- data/lib/mittsu/opengl/plugins/sprite_fragment.glsl +38 -0
- data/lib/mittsu/opengl/plugins/sprite_plugin.rb +250 -0
- data/lib/mittsu/opengl/plugins/sprite_vertex.glsl +31 -0
- data/lib/mittsu/opengl/program.rb +250 -0
- data/lib/mittsu/opengl/renderer.rb +1028 -0
- data/lib/mittsu/opengl/shader/chunk.rb +11 -0
- data/lib/mittsu/opengl/shader/chunks/alphamap_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/alphamap_pars_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/alphatest_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/bumpmap_pars_fragment.glsl +40 -0
- data/lib/mittsu/opengl/shader/chunks/color_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/color_pars_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/color_pars_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/color_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/common.glsl +60 -0
- data/lib/mittsu/opengl/shader/chunks/default_vertex.glsl +15 -0
- data/lib/mittsu/opengl/shader/chunks/defaultnormal_vertex.glsl +21 -0
- data/lib/mittsu/opengl/shader/chunks/envmap_fragment.glsl +62 -0
- data/lib/mittsu/opengl/shader/chunks/envmap_pars_fragment.glsl +21 -0
- data/lib/mittsu/opengl/shader/chunks/envmap_pars_vertex.glsl +7 -0
- data/lib/mittsu/opengl/shader/chunks/envmap_vertex.glsl +17 -0
- data/lib/mittsu/opengl/shader/chunks/fog_fragment.glsl +26 -0
- data/lib/mittsu/opengl/shader/chunks/fog_pars_fragment.glsl +15 -0
- data/lib/mittsu/opengl/shader/chunks/lightmap_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/lightmap_pars_fragment.glsl +6 -0
- data/lib/mittsu/opengl/shader/chunks/lightmap_pars_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/lightmap_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/lights_lambert_pars_vertex.glsl +43 -0
- data/lib/mittsu/opengl/shader/chunks/lights_lambert_vertex.glsl +196 -0
- data/lib/mittsu/opengl/shader/chunks/lights_phong_fragment.glsl +243 -0
- data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_fragment.glsl +58 -0
- data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/lights_phong_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/linear_to_gamma_fragment.glsl +2 -0
- data/lib/mittsu/opengl/shader/chunks/logdepthbuf_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_fragment.glsl +12 -0
- data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_vertex.glsl +11 -0
- data/lib/mittsu/opengl/shader/chunks/logdepthbuf_vertex.glsl +15 -0
- data/lib/mittsu/opengl/shader/chunks/map_fragment.glsl +9 -0
- data/lib/mittsu/opengl/shader/chunks/map_pars_fragment.glsl +11 -0
- data/lib/mittsu/opengl/shader/chunks/map_pars_vertex.glsl +6 -0
- data/lib/mittsu/opengl/shader/chunks/map_particle_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/map_particle_pars_fragment.glsl +6 -0
- data/lib/mittsu/opengl/shader/chunks/map_vertex.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/morphnormal_vertex.glsl +12 -0
- data/lib/mittsu/opengl/shader/chunks/morphtarget_pars_vertex.glsl +13 -0
- data/lib/mittsu/opengl/shader/chunks/morphtarget_vertex.glsl +20 -0
- data/lib/mittsu/opengl/shader/chunks/normalmap_pars_fragment.glsl +27 -0
- data/lib/mittsu/opengl/shader/chunks/shadowmap_fragment.glsl +216 -0
- data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_fragment.glsl +19 -0
- data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_vertex.glsl +6 -0
- data/lib/mittsu/opengl/shader/chunks/shadowmap_vertex.glsl +9 -0
- data/lib/mittsu/opengl/shader/chunks/skinbase_vertex.glsl +8 -0
- data/lib/mittsu/opengl/shader/chunks/skinning_pars_vertex.glsl +47 -0
- data/lib/mittsu/opengl/shader/chunks/skinning_vertex.glsl +20 -0
- data/lib/mittsu/opengl/shader/chunks/skinnormal_vertex.glsl +20 -0
- data/lib/mittsu/opengl/shader/chunks/specularmap_fragment.glsl +12 -0
- data/lib/mittsu/opengl/shader/chunks/specularmap_pars_fragment.glsl +5 -0
- data/lib/mittsu/opengl/shader/chunks/worldpos_vertex.glsl +17 -0
- data/lib/mittsu/opengl/shader/lib/basic/basic_fragment.rbsl +37 -0
- data/lib/mittsu/opengl/shader/lib/basic/basic_uniforms.rbslu +3 -0
- data/lib/mittsu/opengl/shader/lib/basic/basic_vertex.rbsl +33 -0
- data/lib/mittsu/opengl/shader/lib/cube/cube_fragment.rbsl +12 -0
- data/lib/mittsu/opengl/shader/lib/cube/cube_uniforms.rbslu +2 -0
- data/lib/mittsu/opengl/shader/lib/cube/cube_vertex.rbsl +12 -0
- data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_fragment.rbsl +26 -0
- data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
- data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_vertex.rbsl +12 -0
- data/lib/mittsu/opengl/shader/lib/lambert/lambert_fragment.rbsl +56 -0
- data/lib/mittsu/opengl/shader/lib/lambert/lambert_uniforms.rbslu +7 -0
- data/lib/mittsu/opengl/shader/lib/lambert/lambert_vertex.rbsl +37 -0
- data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_fragment.rbsl +27 -0
- data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_uniforms.rbslu +2 -0
- data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_vertex.rbsl +25 -0
- data/lib/mittsu/opengl/shader/lib/phong/phong_fragment.rbsl +45 -0
- data/lib/mittsu/opengl/shader/lib/phong/phong_uniforms.rbslu +11 -0
- data/lib/mittsu/opengl/shader/lib/phong/phong_vertex.rbsl +43 -0
- data/lib/mittsu/opengl/shader/lib.rb +45 -0
- data/lib/mittsu/opengl/shader/rbsl_loader.rb +168 -0
- data/lib/mittsu/opengl/shader/templates/fragment.glsl.erb +105 -0
- data/lib/mittsu/opengl/shader/templates/vertex.glsl.erb +143 -0
- data/lib/mittsu/opengl/shader/uniforms_lib.rb +86 -0
- data/lib/mittsu/opengl/shader/uniforms_utils.rb +31 -0
- data/lib/mittsu/opengl/shader.rb +56 -0
- data/lib/mittsu/opengl/state.rb +205 -0
- data/lib/mittsu/opengl/version.rb +5 -0
- data/lib/mittsu/opengl.rb +2 -0
- data/lib/mittsu/opengl_implementation/core/buffer_geometry.rb +11 -0
- data/lib/mittsu/opengl_implementation/core/geometry.rb +346 -0
- data/lib/mittsu/opengl_implementation/core/object_3d.rb +134 -0
- data/lib/mittsu/opengl_implementation/lights/ambient_light.rb +26 -0
- data/lib/mittsu/opengl_implementation/lights/directional_light.rb +35 -0
- data/lib/mittsu/opengl_implementation/lights/hemisphere_light.rb +39 -0
- data/lib/mittsu/opengl_implementation/lights/light.rb +55 -0
- data/lib/mittsu/opengl_implementation/lights/point_light.rb +36 -0
- data/lib/mittsu/opengl_implementation/lights/spot_light.rb +47 -0
- data/lib/mittsu/opengl_implementation/materials/line_basic_material.rb +16 -0
- data/lib/mittsu/opengl_implementation/materials/material.rb +274 -0
- data/lib/mittsu/opengl_implementation/materials/mesh_basic_material.rb +21 -0
- data/lib/mittsu/opengl_implementation/materials/mesh_lambert_material.rb +33 -0
- data/lib/mittsu/opengl_implementation/materials/mesh_phong_material.rb +44 -0
- data/lib/mittsu/opengl_implementation/materials/point_cloud_material.rb +27 -0
- data/lib/mittsu/opengl_implementation/materials/shader_material.rb +11 -0
- data/lib/mittsu/opengl_implementation/objects/group.rb +9 -0
- data/lib/mittsu/opengl_implementation/objects/line.rb +45 -0
- data/lib/mittsu/opengl_implementation/objects/mesh.rb +70 -0
- data/lib/mittsu/opengl_implementation/objects/point_cloud.rb +39 -0
- data/lib/mittsu/opengl_implementation/objects/sprite.rb +12 -0
- data/lib/mittsu/opengl_implementation/scenes/scene.rb +9 -0
- data/lib/mittsu/opengl_implementation/textures/compressed_texture.rb +20 -0
- data/lib/mittsu/opengl_implementation/textures/cube_texture.rb +77 -0
- data/lib/mittsu/opengl_implementation/textures/data_texture.rb +21 -0
- data/lib/mittsu/opengl_implementation/textures/render_target.rb +124 -0
- data/lib/mittsu/opengl_implementation/textures/texture.rb +107 -0
- data/mittsu-opengl.gemspec +36 -0
- metadata +314 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
uniform float size;
|
2
|
+
// uniform float scale; // TODO
|
3
|
+
|
4
|
+
#include common
|
5
|
+
#include color_pars_vertex
|
6
|
+
#include shadowmap_pars_vertex
|
7
|
+
#include logdepthbuf_pars_vertex
|
8
|
+
|
9
|
+
void main() {
|
10
|
+
#include color_vertex
|
11
|
+
|
12
|
+
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
13
|
+
|
14
|
+
// #ifdef USE_SIZEATTENUATION
|
15
|
+
// gl_PointSize = size * (scale / length(mvPosition.xyz));
|
16
|
+
// #else
|
17
|
+
gl_PointSize = size;
|
18
|
+
// #endif
|
19
|
+
|
20
|
+
gl_Position = projectionMatrix * mvPosition;
|
21
|
+
|
22
|
+
#include logdepthbuf_vertex
|
23
|
+
#include worldpos_vertex
|
24
|
+
#include shadowmap_vertex
|
25
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#define PHONG
|
2
|
+
|
3
|
+
uniform vec3 diffuse;
|
4
|
+
uniform vec3 emissive;
|
5
|
+
uniform vec3 specular;
|
6
|
+
uniform float shininess;
|
7
|
+
uniform float opacity;
|
8
|
+
|
9
|
+
#include common
|
10
|
+
#include color_pars_fragment
|
11
|
+
#include map_pars_fragment
|
12
|
+
#include alphamap_pars_fragment
|
13
|
+
#include lightmap_pars_fragment
|
14
|
+
#include envmap_pars_fragment
|
15
|
+
#include fog_pars_fragment
|
16
|
+
#include lights_phong_pars_fragment
|
17
|
+
#include shadowmap_pars_fragment
|
18
|
+
#include bumpmap_pars_fragment
|
19
|
+
#include normalmap_pars_fragment
|
20
|
+
#include specularmap_pars_fragment
|
21
|
+
#include logdepthbuf_pars_fragment
|
22
|
+
|
23
|
+
void main() {
|
24
|
+
vec3 outgoingLight = vec3( 0.0 ); // outgoing light does not have an alpha, the surface does
|
25
|
+
vec4 diffuseColor = vec4( diffuse, opacity );
|
26
|
+
|
27
|
+
#include logdepthbuf_fragment
|
28
|
+
#include map_fragment
|
29
|
+
#include color_fragment
|
30
|
+
#include alphamap_fragment
|
31
|
+
#include alphatest_fragment
|
32
|
+
#include specularmap_fragment
|
33
|
+
|
34
|
+
#include lights_phong_fragment
|
35
|
+
|
36
|
+
#include lightmap_fragment
|
37
|
+
#include envmap_fragment
|
38
|
+
#include shadowmap_fragment
|
39
|
+
|
40
|
+
#include linear_to_gamma_fragment
|
41
|
+
|
42
|
+
#include fog_fragment
|
43
|
+
|
44
|
+
fragColor = vec4( outgoingLight, diffuseColor.a ); // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
|
45
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#include common
|
2
|
+
#include bump
|
3
|
+
#include normal_map
|
4
|
+
#include fog
|
5
|
+
#include lights
|
6
|
+
#include shadow_map
|
7
|
+
|
8
|
+
uniform color emissive = color(0.0, 0.0, 0.0);
|
9
|
+
uniform color specular = color(0.667, 0.667, 0.667);
|
10
|
+
uniform float shininess = 30.0;
|
11
|
+
uniform vec3 wrapRGB = vec3(1.0, 1.0, 1.0);
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#define PHONG
|
2
|
+
out vec3 vViewPosition;
|
3
|
+
#ifndef FLAT_SHADED
|
4
|
+
out vec3 vNormal;
|
5
|
+
#endif
|
6
|
+
|
7
|
+
#include common
|
8
|
+
#include map_pars_vertex
|
9
|
+
#include lightmap_pars_vertex
|
10
|
+
#include envmap_pars_vertex
|
11
|
+
#include lights_phong_pars_vertex
|
12
|
+
#include color_pars_vertex
|
13
|
+
#include morphtarget_pars_vertex
|
14
|
+
#include skinning_pars_vertex
|
15
|
+
#include shadowmap_pars_vertex
|
16
|
+
#include logdepthbuf_pars_vertex
|
17
|
+
|
18
|
+
void main() {
|
19
|
+
#include map_vertex
|
20
|
+
#include lightmap_vertex
|
21
|
+
#include color_vertex
|
22
|
+
|
23
|
+
#include morphnormal_vertex
|
24
|
+
#include skinbase_vertex
|
25
|
+
#include skinnormal_vertex
|
26
|
+
#include defaultnormal_vertex
|
27
|
+
|
28
|
+
#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED
|
29
|
+
vNormal = normalize( transformedNormal );
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#include morphtarget_vertex
|
33
|
+
#include skinning_vertex
|
34
|
+
#include default_vertex
|
35
|
+
#include logdepthbuf_vertex
|
36
|
+
|
37
|
+
vViewPosition = -mvPosition.xyz;
|
38
|
+
|
39
|
+
#include worldpos_vertex
|
40
|
+
#include envmap_vertex
|
41
|
+
#include lights_phong_vertex
|
42
|
+
#include shadowmap_vertex
|
43
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mittsu/opengl/shader/uniforms_utils'
|
2
|
+
require 'mittsu/opengl/shader/uniforms_lib'
|
3
|
+
require 'mittsu/opengl/shader/chunk'
|
4
|
+
require 'mittsu/opengl/shader/rbsl_loader'
|
5
|
+
|
6
|
+
module Mittsu
|
7
|
+
class OpenGL::Shader
|
8
|
+
module Lib
|
9
|
+
class Instance
|
10
|
+
attr_accessor :uniforms, :vertex_shader, :fragment_shader
|
11
|
+
def initialize(options = {})
|
12
|
+
@uniforms = options.fetch(:uniforms)
|
13
|
+
@vertex_shader = options.fetch(:vertex_shader)
|
14
|
+
@fragment_shader = options.fetch(:fragment_shader)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_from_file(name)
|
18
|
+
Instance.new(
|
19
|
+
uniforms: RBSLLoader.load_uniforms(File.read(File.join(__dir__, 'lib', name, "#{name}_uniforms.rbslu")), UniformsLib),
|
20
|
+
vertex_shader: RBSLLoader.load_shader(File.read(File.join(__dir__, 'lib', name, "#{name}_vertex.rbsl")), Chunk),
|
21
|
+
fragment_shader: RBSLLoader.load_shader(File.read(File.join(__dir__, 'lib', name, "#{name}_fragment.rbsl")), Chunk)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
private_constant :Instance
|
26
|
+
|
27
|
+
SHADER_LIB_HASH = Hash.new { |h, k|
|
28
|
+
h[k] = Instance.load_from_file(k.to_s)
|
29
|
+
}
|
30
|
+
|
31
|
+
def self.create_shader(id, options={})
|
32
|
+
shader = self[id]
|
33
|
+
{
|
34
|
+
uniforms: UniformsUtils.clone(shader.uniforms),
|
35
|
+
vertex_shader: shader.vertex_shader,
|
36
|
+
fragment_shader: shader.fragment_shader
|
37
|
+
}.merge(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.[](id)
|
41
|
+
SHADER_LIB_HASH[id]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class OpenGL::Shader
|
3
|
+
module RBSLLoader
|
4
|
+
UNIFORM_RGX = /uniform\s+(\S+)\s+(\w+)(|\s+\=\s+(.+));/
|
5
|
+
COLOR_RGX = /color\(([^\)]*)\)/
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def load_shader(shader, chunks)
|
9
|
+
shader.lines.flat_map(&:chomp).map{ |line|
|
10
|
+
if line =~ /(\s*)#include\s+(\w+)/
|
11
|
+
indentation = $1
|
12
|
+
chunk_name = $2.to_sym
|
13
|
+
|
14
|
+
chunks[chunk_name].lines.map(&:chomp).map{ |l|
|
15
|
+
"#{indentation}#{l}"
|
16
|
+
}
|
17
|
+
else
|
18
|
+
line
|
19
|
+
end
|
20
|
+
}.join("\n") + "\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def extract_array_contents(str)
|
24
|
+
/\[([^\]]+)\]/.match(str)[1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_int(str)
|
28
|
+
str.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
(2..4).each do |n|
|
32
|
+
define_method("parse_ivec#{n}") do |str|
|
33
|
+
str =~ /ivec#{n}\(([^\)]+)\)/
|
34
|
+
$1.split(',').map(&:strip).map(&:to_i).take(n)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_float(str)
|
39
|
+
str.to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_single_color(values)
|
43
|
+
if values.length == 1
|
44
|
+
values = values.map(&:to_i)
|
45
|
+
else
|
46
|
+
values = values.map(&:to_f)
|
47
|
+
end
|
48
|
+
Color.new(*values)
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_color(str)
|
52
|
+
str =~ COLOR_RGX
|
53
|
+
values = $1.split(',').map(&:strip)
|
54
|
+
parse_single_color(values)
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_color_array(str)
|
58
|
+
str = extract_array_contents(str)
|
59
|
+
str.scan(COLOR_RGX).map{ |m|
|
60
|
+
values = m.first.split(',').map(&:strip)
|
61
|
+
parse_single_color(values)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_int_array(str)
|
66
|
+
str = extract_array_contents(str)
|
67
|
+
str.split(',').map(&:strip).map(&:to_i)
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_float_array(str)
|
71
|
+
str = extract_array_contents(str)
|
72
|
+
str.split(',').map(&:strip).map(&:to_f)
|
73
|
+
end
|
74
|
+
|
75
|
+
[Vector2, Vector3, Vector4].each do |vectorClass|
|
76
|
+
define_method("parse_vec#{vectorClass::DIMENSIONS}") do |str|
|
77
|
+
str =~ /vec#{vectorClass::DIMENSIONS}\(([^\)]+)\)/
|
78
|
+
values = $1.split(',').map(&:strip).map(&:to_f).take(vectorClass::DIMENSIONS)
|
79
|
+
vectorClass.new(*values)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
(2..4).each do |n|
|
84
|
+
define_method("parse_ivec#{n}_array") do |str|
|
85
|
+
str = extract_array_contents(str)
|
86
|
+
str.scan(/ivec#{n}\(([^\)]+)\)/).map{ |m| m.first.split(',').map(&:strip).map(&:to_i).take(n) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
[Vector2, Vector3, Vector4].each do |vectorClass|
|
91
|
+
define_method("parse_vec#{vectorClass::DIMENSIONS}_array") do |str|
|
92
|
+
str = extract_array_contents(str)
|
93
|
+
str.scan(/vec#{vectorClass::DIMENSIONS}\(([^\)]+)\)/).map{ |m|
|
94
|
+
values = m.first.split(',').map(&:strip).map(&:to_f).take(vectorClass::DIMENSIONS)
|
95
|
+
vectorClass.new(*values)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
[Matrix3, Matrix4].each do |matrixClass|
|
101
|
+
define_method("parse_mat#{matrixClass::DIMENSIONS}") do |str|
|
102
|
+
str =~ /mat#{matrixClass::DIMENSIONS}\(([^\)]+)\)/
|
103
|
+
values = $1.split(',').map(&:strip).map(&:to_f).take(matrixClass::DIMENSIONS * matrixClass::DIMENSIONS)
|
104
|
+
matrixClass.new().tap { |mat| mat.set(*values) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
[Matrix3, Matrix4].each do |matrixClass|
|
109
|
+
define_method("parse_mat#{matrixClass::DIMENSIONS}_array") do |str|
|
110
|
+
str = extract_array_contents(str)
|
111
|
+
str.scan(/mat#{matrixClass::DIMENSIONS}\(([^\)]+)\)/).map{ |m|
|
112
|
+
values = m.first.split(',').map(&:strip).map(&:to_f).take(matrixClass::DIMENSIONS * matrixClass::DIMENSIONS)
|
113
|
+
matrixClass.new().tap { |mat| mat.set(*values) }
|
114
|
+
}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def parse_texture(_str)
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
|
122
|
+
def parse_texture_array(_str)
|
123
|
+
[]
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse_uniform(uniform)
|
127
|
+
uniform =~ UNIFORM_RGX
|
128
|
+
type_str = $1
|
129
|
+
type = type_str.to_sym
|
130
|
+
is_array = type_str.end_with?('[]')
|
131
|
+
name = $2
|
132
|
+
value_str = $4
|
133
|
+
value = is_array ? [] : nil
|
134
|
+
if value_str && !value_str.empty?
|
135
|
+
value = send("parse_#{type.to_s.gsub(/\[\]/, '_array')}".to_s, value_str)
|
136
|
+
end
|
137
|
+
[name, Uniform.new(type, value)]
|
138
|
+
end
|
139
|
+
|
140
|
+
def load_uniforms(uniforms, uniforms_lib)
|
141
|
+
uniform_strings = nil;
|
142
|
+
in_uniform = false
|
143
|
+
|
144
|
+
uniforms.lines.map(&:strip).each_with_object({}) { |line, hash|
|
145
|
+
if in_uniform
|
146
|
+
uniform_strings << line
|
147
|
+
if line.end_with?(';')
|
148
|
+
in_uniform = false
|
149
|
+
name, value = parse_uniform(uniform_strings.join(' '))
|
150
|
+
hash[name] = value
|
151
|
+
end
|
152
|
+
elsif line =~ /#include\s+(\w+)/
|
153
|
+
uniforms_lib[$1.to_sym].map { |(k, v)| hash[k] = v.clone }
|
154
|
+
elsif line.start_with?('uniform')
|
155
|
+
if line.end_with?(';')
|
156
|
+
name, value = parse_uniform(line)
|
157
|
+
hash[name] = value
|
158
|
+
else
|
159
|
+
in_uniform = true
|
160
|
+
uniform_strings = [line]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
}
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#version 330
|
2
|
+
|
3
|
+
// (parameters[:bump_map] || parameters[:normal_map] || parameters[:flat_shading]) ? '#extension GL_OES_standard_derivatives : enable' : '', # TODO: does extension exist in OpenGL?
|
4
|
+
|
5
|
+
<%= custom_defines %>
|
6
|
+
|
7
|
+
#define MAX_DIR_LIGHTS <%= parameters[:max_dir_lights] %>
|
8
|
+
#define MAX_POINT_LIGHTS <%= parameters[:max_point_lights] %>
|
9
|
+
#define MAX_SPOT_LIGHTS <%= parameters[:max_spot_lights] %>
|
10
|
+
#define MAX_HEMI_LIGHTS <%= parameters[:max_hemi_lights] %>
|
11
|
+
|
12
|
+
#define MAX_SHADOWS <%= parameters[:max_shadows] %>
|
13
|
+
|
14
|
+
<% if parameters[:alpha_test] %>
|
15
|
+
#define ALPHATEST <%= parameters[:alpha_test].to_f %>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<% if @renderer.gamma_input %>
|
19
|
+
#define GAMMA_INPUT
|
20
|
+
<% end %>
|
21
|
+
<% if @renderer.gamma_output %>
|
22
|
+
#define GAMMA_OUTPUT
|
23
|
+
<% end %>
|
24
|
+
#define GAMMA_FACTOR <%= gamma_factor_define %>
|
25
|
+
|
26
|
+
<% if parameters[:use_fog] && parameters[:fog] %>
|
27
|
+
#define USE_FOG
|
28
|
+
<% end %>
|
29
|
+
<% if parameters[:use_fog] && parameters[:fog_exp] %>
|
30
|
+
#define FOG_EXP2
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<% if parameters[:map] %>
|
34
|
+
#define USE_MAP
|
35
|
+
<% end %>
|
36
|
+
<% if parameters[:env_map] %>
|
37
|
+
#define USE_ENVMAP
|
38
|
+
<% end %>
|
39
|
+
<% if parameters[:env_map] %>
|
40
|
+
#define <%= env_map_type_define %>
|
41
|
+
<% end %>
|
42
|
+
<% if parameters[:env_map] %>
|
43
|
+
#define <%= env_map_mode_define %>
|
44
|
+
<% end %>
|
45
|
+
<% if parameters[:env_map] %>
|
46
|
+
#define <%= env_map_blending_define %>
|
47
|
+
<% end %>
|
48
|
+
<% if parameters[:light_map] %>
|
49
|
+
#define USE_LIGHTMAP
|
50
|
+
<% end %>
|
51
|
+
<% if parameters[:bump_map] %>
|
52
|
+
#define USE_BUMPMAP
|
53
|
+
<% end %>
|
54
|
+
<% if parameters[:normal_map] %>
|
55
|
+
#define USE_NORMALMAP
|
56
|
+
<% end %>
|
57
|
+
<% if parameters[:specular_map] %>
|
58
|
+
#define USE_SPECULARMAP
|
59
|
+
<% end %>
|
60
|
+
<% if parameters[:alpha_map] %>
|
61
|
+
#define USE_ALPHAMAP
|
62
|
+
<% end %>
|
63
|
+
<% if parameters[:vertex_colors] %>
|
64
|
+
#define USE_COLOR
|
65
|
+
<% end %>
|
66
|
+
|
67
|
+
<% if parameters[:flat_shading] %>
|
68
|
+
#define FLAT_SHADED
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
<% if parameters[:metal] %>
|
72
|
+
#define METAL
|
73
|
+
<% end %>
|
74
|
+
<% if parameters[:wrap_around] %>
|
75
|
+
#define WRAP_AROUND
|
76
|
+
<% end %>
|
77
|
+
<% if parameters[:double_sided] %>
|
78
|
+
#define DOUBLE_SIDED
|
79
|
+
<% end %>
|
80
|
+
<% if parameters[:flip_sided] %>
|
81
|
+
#define FLIP_SIDED
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
<% if parameters[:shadow_map_enabled] %>
|
85
|
+
#define USE_SHADOWMAP
|
86
|
+
<% end %>
|
87
|
+
<% if parameters[:shadow_map_enabled] %>
|
88
|
+
#define <%= shadow_map_type_define %>
|
89
|
+
<% end %>
|
90
|
+
<% if parameters[:shadow_map_debug] %>
|
91
|
+
#define SHADOWMAP_DEBUG
|
92
|
+
<% end %>
|
93
|
+
<% if parameters[:'shadow_map_cascade'] %>
|
94
|
+
#define SHADOWMAP_CASCADE
|
95
|
+
<% end %>
|
96
|
+
|
97
|
+
<% if parameters[:logarithmic_depth_buffer] %>
|
98
|
+
#define USE_LOGDEPTHBUF
|
99
|
+
<% end %>
|
100
|
+
// @renderer._GL.ExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
101
|
+
|
102
|
+
uniform mat4 viewMatrix;
|
103
|
+
uniform vec3 cameraPosition;
|
104
|
+
|
105
|
+
layout(location = 0) out vec4 fragColor;
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#version 330
|
2
|
+
|
3
|
+
<%= custom_defines %>
|
4
|
+
|
5
|
+
<% if parameters[:supports_vertex_textures] %>
|
6
|
+
#define VERTEX_TEXTURES
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% if @renderer.gamma_input %>
|
10
|
+
#define GAMMA_INPUT
|
11
|
+
<% end %>
|
12
|
+
<% if @renderer.gamma_output %>
|
13
|
+
#define GAMMA_OUTPUT
|
14
|
+
<% end %>
|
15
|
+
#define GAMMA_FACTOR <%= gamma_factor_define %>
|
16
|
+
|
17
|
+
#define MAX_DIR_LIGHTS <%= parameters[:max_dir_lights] %>
|
18
|
+
#define MAX_POINT_LIGHTS <%= parameters[:max_point_lights] %>
|
19
|
+
#define MAX_SPOT_LIGHTS <%= parameters[:max_spot_lights] %>
|
20
|
+
#define MAX_HEMI_LIGHTS <%= parameters[:max_hemi_lights] %>
|
21
|
+
|
22
|
+
#define MAX_SHADOWS <%= parameters[:max_shadows] %>
|
23
|
+
|
24
|
+
#define MAX_BONES <%= parameters[:max_bones] %>
|
25
|
+
|
26
|
+
<% if parameters[:map] %>
|
27
|
+
#define USE_MAP
|
28
|
+
<% end %>
|
29
|
+
<% if parameters[:env_map] %>
|
30
|
+
#define USE_ENVMAP
|
31
|
+
<% end %>
|
32
|
+
<% if parameters[:env_map] %>
|
33
|
+
#define <%= env_map_mode_define %>
|
34
|
+
<% end %>
|
35
|
+
<% if parameters[:light_map] %>
|
36
|
+
#define USE_LIGHTMAP
|
37
|
+
<% end %>
|
38
|
+
<% if parameters[:bump_map] %>
|
39
|
+
#define USE_BUMPMAP
|
40
|
+
<% end %>
|
41
|
+
<% if parameters[:normal_map] %>
|
42
|
+
#define USE_NORMALMAP
|
43
|
+
<% end %>
|
44
|
+
<% if parameters[:specular_map] %>
|
45
|
+
#define USE_SPECULARMAP
|
46
|
+
<% end %>
|
47
|
+
<% if parameters[:alpha_map] %>
|
48
|
+
#define USE_ALPHAMAP
|
49
|
+
<% end %>
|
50
|
+
<% if parameters[:vertex_colors] %>
|
51
|
+
#define USE_COLOR
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<% if parameters[:flat_shading] %>
|
55
|
+
#define FLAT_SHADED
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<% if parameters[:skinning] %>
|
59
|
+
#define USE_SKINNING
|
60
|
+
<% end %>
|
61
|
+
<% if parameters[:use_vertex_texture] %>
|
62
|
+
#define BONE_TEXTURE
|
63
|
+
<% end %>
|
64
|
+
|
65
|
+
<% if parameters[:morph_targets] %>
|
66
|
+
#define USE_MORPHTARGETS
|
67
|
+
<% end %>
|
68
|
+
<% if parameters[:morph_normals] %>
|
69
|
+
#define USE_MORPHNORMALS
|
70
|
+
<% end %>
|
71
|
+
<% if parameters[:wrap_around] %>
|
72
|
+
#define WRAP_AROUND
|
73
|
+
<% end %>
|
74
|
+
<% if parameters[:double_sided] %>
|
75
|
+
#define DOUBLE_SIDED
|
76
|
+
<% end %>
|
77
|
+
<% if parameters[:flip_sided] %>
|
78
|
+
#define FLIP_SIDED
|
79
|
+
<% end %>
|
80
|
+
|
81
|
+
<% if parameters[:shadow_map_enabled] %>
|
82
|
+
#define USE_SHADOWMAP
|
83
|
+
<% end %>
|
84
|
+
<% if parameters[:shadow_map_enabled] %>
|
85
|
+
#define <%= shadow_map_type_define %>
|
86
|
+
<% end %>
|
87
|
+
<% if parameters[:shadow_map_debug] %>
|
88
|
+
#define SHADOWMAP_DEBUG
|
89
|
+
<% end %>
|
90
|
+
<% if parameters[:shadow_map_cascade] %>
|
91
|
+
#define SHADOWMAP_CASCADE
|
92
|
+
<% end %>
|
93
|
+
|
94
|
+
<% if parameters[:size_attenuation] %>
|
95
|
+
#define USE_SIZEATTENUATION
|
96
|
+
<% end %>
|
97
|
+
|
98
|
+
<% if parameters[:logarithmic_depth_buffer] %>
|
99
|
+
#define USE_LOGDEPTHBUF
|
100
|
+
<% end %>
|
101
|
+
// @renderer._GL.ExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
102
|
+
|
103
|
+
|
104
|
+
uniform mat4 modelMatrix;
|
105
|
+
uniform mat4 modelViewMatrix;
|
106
|
+
uniform mat4 projectionMatrix;
|
107
|
+
uniform mat4 viewMatrix;
|
108
|
+
uniform mat3 normalMatrix;
|
109
|
+
uniform vec3 cameraPosition;
|
110
|
+
|
111
|
+
in vec3 position;
|
112
|
+
in vec3 normal;
|
113
|
+
in vec2 uv;
|
114
|
+
in vec2 uv2;
|
115
|
+
|
116
|
+
#ifdef USE_COLOR
|
117
|
+
in vec3 color;
|
118
|
+
#endif
|
119
|
+
|
120
|
+
#ifdef USE_MORPHTARGETS
|
121
|
+
in vec3 morphTarget0;
|
122
|
+
in vec3 morphTarget1;
|
123
|
+
in vec3 morphTarget2;
|
124
|
+
in vec3 morphTarget3;
|
125
|
+
|
126
|
+
#ifdef USE_MORPHNORMALS
|
127
|
+
in vec3 morphNormal0;
|
128
|
+
in vec3 morphNormal1;
|
129
|
+
in vec3 morphNormal2;
|
130
|
+
in vec3 morphNormal3;
|
131
|
+
#else
|
132
|
+
in vec3 morphTarget4;
|
133
|
+
in vec3 morphTarget5;
|
134
|
+
in vec3 morphTarget6;
|
135
|
+
in vec3 morphTarget7;
|
136
|
+
#endif
|
137
|
+
|
138
|
+
#endif
|
139
|
+
|
140
|
+
#ifdef USE_SKINNING
|
141
|
+
in vec4 skinIndex;
|
142
|
+
in vec4 skinWeight;
|
143
|
+
#endif
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'mittsu/math'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class OpenGL::Shader
|
5
|
+
UniformsLib = {
|
6
|
+
common: {
|
7
|
+
'diffuse' => Uniform.new(:color, Color.new(0xeeeeee)),
|
8
|
+
'opacity' => Uniform.new(:float, 1.0),
|
9
|
+
|
10
|
+
'map' => Uniform.new(:texture, nil),
|
11
|
+
'offsetRepeat' => Uniform.new(:vec4, Vector4.new(0.0, 0.0, 1.0, 1.0)),
|
12
|
+
|
13
|
+
'lightMap' => Uniform.new(:texture, nil),
|
14
|
+
'specularMap' => Uniform.new(:texture, nil),
|
15
|
+
'alphaMap' => Uniform.new(:texture, nil),
|
16
|
+
|
17
|
+
'envMap' => Uniform.new(:texture, nil),
|
18
|
+
'flipEnvMap' => Uniform.new(:float, -1.0),
|
19
|
+
'reflectivity' => Uniform.new(:float, 1.0),
|
20
|
+
'refractionRatio' => Uniform.new(:float, 0.98),
|
21
|
+
|
22
|
+
'morphTargetInfluences' => Uniform.new(:float, 0.0)
|
23
|
+
},
|
24
|
+
|
25
|
+
bump: {
|
26
|
+
'bumpMap' => Uniform.new(:texture, nil),
|
27
|
+
'bumpScale' => Uniform.new(:float, 1.0)
|
28
|
+
},
|
29
|
+
|
30
|
+
normal_map: {
|
31
|
+
'normalMap' => Uniform.new(:texture, nil),
|
32
|
+
'normalScale' => Uniform.new(:vec2, Vector2.new(1.0, 1.0))
|
33
|
+
},
|
34
|
+
|
35
|
+
fog: {
|
36
|
+
'fogDensity' => Uniform.new(:float, 0.00025),
|
37
|
+
'fogNear' => Uniform.new(:float, 1.0),
|
38
|
+
'fogFar' => Uniform.new(:float, 2000.0),
|
39
|
+
'fogColor' => Uniform.new(:color, Color.new(0xffffff))
|
40
|
+
},
|
41
|
+
|
42
|
+
lights: {
|
43
|
+
'ambientLightColor' => Uniform.new(:color, Color.new(0xffffff)),
|
44
|
+
|
45
|
+
'directionalLightDirection' => Uniform.new(:'vec3[]', []),
|
46
|
+
'directionalLightColor' => Uniform.new(:'color[]', []),
|
47
|
+
|
48
|
+
'hemisphereLightDirection' => Uniform.new(:'vec3[]', []),
|
49
|
+
'hemisphereLightSkyColor' => Uniform.new(:'color[]', []),
|
50
|
+
'hemisphereLightGroundColor' => Uniform.new(:'color[]', []),
|
51
|
+
|
52
|
+
'pointLightColor' => Uniform.new(:'color[]', []),
|
53
|
+
'pointLightPosition' => Uniform.new(:'vec3[]', []),
|
54
|
+
'pointLightDistance' => Uniform.new(:'float[]', []),
|
55
|
+
'pointLightDecay' => Uniform.new(:'float[]', []),
|
56
|
+
|
57
|
+
'spotLightColor' => Uniform.new(:'color[]', []),
|
58
|
+
'spotLightPosition' => Uniform.new(:'vec3[]', []),
|
59
|
+
'spotLightDirection' => Uniform.new(:'vec3[]', []),
|
60
|
+
'spotLightDistance' => Uniform.new(:'float[]', []),
|
61
|
+
'spotLightAngleCos' => Uniform.new(:'float[]', []),
|
62
|
+
'spotLightExponent' => Uniform.new(:'float[]', []),
|
63
|
+
'spotLightDecay' => Uniform.new(:'float[]', [])
|
64
|
+
},
|
65
|
+
|
66
|
+
particle: {
|
67
|
+
'psColor' => Uniform.new(:color, Color.new(0xeeeeee)),
|
68
|
+
'opacity' => Uniform.new(:float, 1.0),
|
69
|
+
'size' => Uniform.new(:float, 1.0),
|
70
|
+
'scale' => Uniform.new(:float, 1.0),
|
71
|
+
'map' => Uniform.new(:texture, nil),
|
72
|
+
'offsetRepeat' => Uniform.new(:vec4, Vector4.new(0.0, 0.0, 1.0, 1.0))
|
73
|
+
},
|
74
|
+
|
75
|
+
shadow_map: {
|
76
|
+
'shadowMap' => Uniform.new(:'texture[]', []),
|
77
|
+
'shadowMapSize' => Uniform.new(:'vec2[]', []),
|
78
|
+
|
79
|
+
'shadowBias' => Uniform.new(:'float[]', []),
|
80
|
+
'shadowDarkness' => Uniform.new(:'float[]', []),
|
81
|
+
|
82
|
+
'shadowMatrix' => Uniform.new(:'mat4[]', [])
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|