mittsu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/01_-_Default1noCulling.png +0 -0
- data/examples/01_scene_example.rb +14 -0
- data/examples/02_box_mesh_example.rb +30 -0
- data/examples/02_sphere_mesh_example.rb +30 -0
- data/examples/03_complex_object_example.rb +52 -0
- data/examples/04_ambient_light_example.rb +33 -0
- data/examples/04_dir_light_example.rb +36 -0
- data/examples/04_hemi_light_example.rb +30 -0
- data/examples/04_point_light_example.rb +50 -0
- data/examples/04_spot_light_example.rb +44 -0
- data/examples/05_earth_example.rb +42 -0
- data/examples/05_earth_moon_example.rb +46 -0
- data/examples/05_texture_example.rb +32 -0
- data/examples/06_cube_texture_example.rb +36 -0
- data/examples/06_skybox_example.rb +60 -0
- data/examples/07_earth_normal_example.rb +36 -0
- data/examples/08_shadow_example.rb +87 -0
- data/examples/09_line_example.rb +52 -0
- data/examples/10_obj_loader_example.rb +68 -0
- data/examples/11_character_input_example.rb +18 -0
- data/examples/11_continuous_keyboard_input_example.rb +35 -0
- data/examples/11_keyboard_input_example.rb +43 -0
- data/examples/12_mouse_click_example.rb +38 -0
- data/examples/12_mouse_motion_example.rb +35 -0
- data/examples/12_mouse_scroll_example.rb +36 -0
- data/examples/12_orbit_zoom_example.rb +68 -0
- data/examples/13_joystick_example.rb +80 -0
- data/examples/cubemap/tron_bk.png +0 -0
- data/examples/cubemap/tron_dn.png +0 -0
- data/examples/cubemap/tron_ft.png +0 -0
- data/examples/cubemap/tron_lf.png +0 -0
- data/examples/cubemap/tron_rt.png +0 -0
- data/examples/cubemap/tron_up.png +0 -0
- data/examples/earth.png +0 -0
- data/examples/earth_normal.png +0 -0
- data/examples/example_helper.rb +2 -0
- data/examples/male-02-1noCulling.png +0 -0
- data/examples/male02.mtl +54 -0
- data/examples/male02.obj +13888 -0
- data/examples/moon.png +0 -0
- data/examples/orig_02_-_Defaul1noCulling.png +0 -0
- data/examples/texture.png +0 -0
- data/lib/mittsu.rb +15 -0
- data/lib/mittsu/cameras.rb +4 -0
- data/lib/mittsu/cameras/camera.rb +34 -0
- data/lib/mittsu/cameras/cube_camera.rb +74 -0
- data/lib/mittsu/cameras/orthographic_camera.rb +53 -0
- data/lib/mittsu/cameras/perspective_camera.rb +115 -0
- data/lib/mittsu/constants.rb +160 -0
- data/lib/mittsu/core.rb +10 -0
- data/lib/mittsu/core/buffer_attribute.rb +87 -0
- data/lib/mittsu/core/buffer_geometry.rb +694 -0
- data/lib/mittsu/core/clock.rb +44 -0
- data/lib/mittsu/core/dynamic_buffer_attribute.rb +16 -0
- data/lib/mittsu/core/event_dispatcher.rb +39 -0
- data/lib/mittsu/core/face3.rb +30 -0
- data/lib/mittsu/core/geometry.rb +596 -0
- data/lib/mittsu/core/hash_array.rb +36 -0
- data/lib/mittsu/core/hash_object.rb +19 -0
- data/lib/mittsu/core/object_3d.rb +421 -0
- data/lib/mittsu/core/raycaster.rb +78 -0
- data/lib/mittsu/extras.rb +3 -0
- data/lib/mittsu/extras/geometries.rb +2 -0
- data/lib/mittsu/extras/geometries/box_geometry.rb +108 -0
- data/lib/mittsu/extras/geometries/sphere_geometry.rb +88 -0
- data/lib/mittsu/extras/helpers.rb +1 -0
- data/lib/mittsu/extras/helpers/camera_helper.rb +155 -0
- data/lib/mittsu/extras/image.rb +3 -0
- data/lib/mittsu/extras/image_utils.rb +80 -0
- data/lib/mittsu/lights.rb +7 -0
- data/lib/mittsu/lights/ambient_light.rb +16 -0
- data/lib/mittsu/lights/area_light.rb +24 -0
- data/lib/mittsu/lights/directional_light.rb +131 -0
- data/lib/mittsu/lights/hemisphere_light.rb +29 -0
- data/lib/mittsu/lights/light.rb +21 -0
- data/lib/mittsu/lights/point_light.rb +27 -0
- data/lib/mittsu/lights/spot_light.rb +104 -0
- data/lib/mittsu/loaders.rb +7 -0
- data/lib/mittsu/loaders/cache.rb +53 -0
- data/lib/mittsu/loaders/file_loader.rb +22 -0
- data/lib/mittsu/loaders/image_loader.rb +32 -0
- data/lib/mittsu/loaders/loader.rb +212 -0
- data/lib/mittsu/loaders/loading_manager.rb +17 -0
- data/lib/mittsu/loaders/mtl_loader.rb +242 -0
- data/lib/mittsu/loaders/obj_mtl_loader.rb +225 -0
- data/lib/mittsu/materials.rb +7 -0
- data/lib/mittsu/materials/line_basic_material.rb +39 -0
- data/lib/mittsu/materials/material.rb +156 -0
- data/lib/mittsu/materials/mesh_basic_material.rb +122 -0
- data/lib/mittsu/materials/mesh_face_material.rb +30 -0
- data/lib/mittsu/materials/mesh_lambert_material.rb +126 -0
- data/lib/mittsu/materials/mesh_phong_material.rb +152 -0
- data/lib/mittsu/materials/shader_material.rb +108 -0
- data/lib/mittsu/math.rb +105 -0
- data/lib/mittsu/math/box2.rb +135 -0
- data/lib/mittsu/math/box3.rb +194 -0
- data/lib/mittsu/math/color.rb +252 -0
- data/lib/mittsu/math/color_keywords.rb +151 -0
- data/lib/mittsu/math/euler.rb +182 -0
- data/lib/mittsu/math/frustum.rb +106 -0
- data/lib/mittsu/math/line3.rb +76 -0
- data/lib/mittsu/math/matrix3.rb +163 -0
- data/lib/mittsu/math/matrix4.rb +581 -0
- data/lib/mittsu/math/plane.rb +128 -0
- data/lib/mittsu/math/quaternion.rb +309 -0
- data/lib/mittsu/math/ray.rb +292 -0
- data/lib/mittsu/math/sphere.rb +91 -0
- data/lib/mittsu/math/spline.rb +128 -0
- data/lib/mittsu/math/triangle.rb +121 -0
- data/lib/mittsu/math/vector2.rb +238 -0
- data/lib/mittsu/math/vector3.rb +491 -0
- data/lib/mittsu/math/vector4.rb +414 -0
- data/lib/mittsu/objects.rb +3 -0
- data/lib/mittsu/objects/group.rb +8 -0
- data/lib/mittsu/objects/line.rb +143 -0
- data/lib/mittsu/objects/mesh.rb +243 -0
- data/lib/mittsu/renderers.rb +1 -0
- data/lib/mittsu/renderers/glfw_window.rb +216 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +38 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +402 -0
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +58 -0
- data/lib/mittsu/renderers/opengl/opengl_state.rb +207 -0
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +416 -0
- data/lib/mittsu/renderers/opengl_render_target.rb +87 -0
- data/lib/mittsu/renderers/opengl_renderer.rb +3376 -0
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +40 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +60 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +62 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +7 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +26 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +43 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +196 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +243 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +58 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +2 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +13 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +27 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +217 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +19 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +8 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +47 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_lib.rb +420 -0
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +107 -0
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +31 -0
- data/lib/mittsu/scenes.rb +1 -0
- data/lib/mittsu/scenes/scene.rb +27 -0
- data/lib/mittsu/textures.rb +5 -0
- data/lib/mittsu/textures/compressed_texture.rb +30 -0
- data/lib/mittsu/textures/cube_texture.rb +19 -0
- data/lib/mittsu/textures/data_texture.rb +17 -0
- data/lib/mittsu/textures/texture.rb +92 -0
- data/lib/mittsu/textures/video_texture.rb +17 -0
- data/lib/mittsu/version.rb +4 -0
- data/mittsu.gemspec +31 -0
- metadata +357 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifdef USE_MORPHTARGETS
|
2
|
+
|
3
|
+
vec3 morphed = vec3( 0.0 );
|
4
|
+
morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];
|
5
|
+
morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];
|
6
|
+
morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];
|
7
|
+
morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];
|
8
|
+
|
9
|
+
#ifndef USE_MORPHNORMALS
|
10
|
+
|
11
|
+
morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];
|
12
|
+
morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];
|
13
|
+
morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];
|
14
|
+
morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];
|
15
|
+
|
16
|
+
#endif
|
17
|
+
|
18
|
+
morphed += position;
|
19
|
+
|
20
|
+
#endif
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifdef USE_NORMALMAP
|
2
|
+
|
3
|
+
uniform sampler2D normalMap;
|
4
|
+
uniform vec2 normalScale;
|
5
|
+
|
6
|
+
// Per-Pixel Tangent Space Normal Mapping
|
7
|
+
// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
|
8
|
+
|
9
|
+
vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
|
10
|
+
|
11
|
+
vec3 q0 = dFdx( eye_pos.xyz );
|
12
|
+
vec3 q1 = dFdy( eye_pos.xyz );
|
13
|
+
vec2 st0 = dFdx( vUv.st );
|
14
|
+
vec2 st1 = dFdy( vUv.st );
|
15
|
+
|
16
|
+
vec3 S = normalize( q0 * st1.t - q1 * st0.t );
|
17
|
+
vec3 T = normalize( -q0 * st1.s + q1 * st0.s );
|
18
|
+
vec3 N = normalize( surf_norm );
|
19
|
+
|
20
|
+
vec3 mapN = texture( normalMap, vUv ).xyz * 2.0 - 1.0;
|
21
|
+
mapN.xy = normalScale * mapN.xy;
|
22
|
+
mat3 tsn = mat3( S, T, N );
|
23
|
+
return normalize( tsn * mapN );
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
#endif
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#ifdef USE_SHADOWMAP
|
2
|
+
|
3
|
+
#ifdef SHADOWMAP_DEBUG
|
4
|
+
|
5
|
+
vec3 frustumColors[3];
|
6
|
+
frustumColors[0] = vec3( 1.0, 0.5, 0.0 );
|
7
|
+
frustumColors[1] = vec3( 0.0, 1.0, 0.8 );
|
8
|
+
frustumColors[2] = vec3( 0.0, 0.5, 1.0 );
|
9
|
+
|
10
|
+
#endif
|
11
|
+
|
12
|
+
#ifdef SHADOWMAP_CASCADE
|
13
|
+
|
14
|
+
int inFrustumCount = 0;
|
15
|
+
|
16
|
+
#endif
|
17
|
+
|
18
|
+
float fDepth;
|
19
|
+
vec3 shadowColor = vec3( 1.0 );
|
20
|
+
|
21
|
+
for( int i = 0; i < MAX_SHADOWS; i ++ ) {
|
22
|
+
|
23
|
+
vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;
|
24
|
+
|
25
|
+
// if ( something && something ) breaks ATI OpenGL shader compiler
|
26
|
+
// if ( all( something, something ) ) using this instead
|
27
|
+
|
28
|
+
bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
|
29
|
+
bool inFrustum = all( inFrustumVec );
|
30
|
+
|
31
|
+
// don't shadow pixels outside of light frustum
|
32
|
+
// use just first frustum (for cascades)
|
33
|
+
// don't shadow pixels behind far plane of light frustum
|
34
|
+
|
35
|
+
#ifdef SHADOWMAP_CASCADE
|
36
|
+
|
37
|
+
inFrustumCount += int( inFrustum );
|
38
|
+
bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );
|
39
|
+
|
40
|
+
#else
|
41
|
+
|
42
|
+
bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
|
43
|
+
|
44
|
+
#endif
|
45
|
+
|
46
|
+
bool frustumTest = all( frustumTestVec );
|
47
|
+
|
48
|
+
if ( frustumTest ) {
|
49
|
+
|
50
|
+
shadowCoord.z += shadowBias[ i ];
|
51
|
+
|
52
|
+
#if defined( SHADOWMAP_TYPE_PCF )
|
53
|
+
|
54
|
+
// Percentage-close filtering
|
55
|
+
// (9 pixel kernel)
|
56
|
+
// http://fabiensanglard.net/shadowmappingPCF/
|
57
|
+
|
58
|
+
float shadow = 0.0;
|
59
|
+
|
60
|
+
/*
|
61
|
+
// nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
|
62
|
+
// must enroll loop manually
|
63
|
+
|
64
|
+
for ( float y = -1.25; y <= 1.25; y += 1.25 )
|
65
|
+
for ( float x = -1.25; x <= 1.25; x += 1.25 ) {
|
66
|
+
|
67
|
+
vec4 rgbaDepth = texture( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );
|
68
|
+
|
69
|
+
// doesn't seem to produce any noticeable visual difference compared to simple texture lookup
|
70
|
+
//vec4 rgbaDepth = textureProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );
|
71
|
+
|
72
|
+
float fDepth = unpackDepth( rgbaDepth );
|
73
|
+
|
74
|
+
if ( fDepth < shadowCoord.z )
|
75
|
+
shadow += 1.0;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
shadow /= 9.0;
|
80
|
+
|
81
|
+
*/
|
82
|
+
|
83
|
+
const float shadowDelta = 1.0 / 9.0;
|
84
|
+
|
85
|
+
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
|
86
|
+
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
|
87
|
+
|
88
|
+
float dx0 = -1.25 * xPixelOffset;
|
89
|
+
float dy0 = -1.25 * yPixelOffset;
|
90
|
+
float dx1 = 1.25 * xPixelOffset;
|
91
|
+
float dy1 = 1.25 * yPixelOffset;
|
92
|
+
|
93
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
|
94
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
95
|
+
|
96
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
|
97
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
98
|
+
|
99
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
|
100
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
101
|
+
|
102
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
|
103
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
104
|
+
|
105
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy ) );
|
106
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
107
|
+
|
108
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
|
109
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
110
|
+
|
111
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
|
112
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
113
|
+
|
114
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
|
115
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
116
|
+
|
117
|
+
fDepth = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
|
118
|
+
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
|
119
|
+
|
120
|
+
shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
|
121
|
+
|
122
|
+
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
|
123
|
+
|
124
|
+
// Percentage-close filtering
|
125
|
+
// (9 pixel kernel)
|
126
|
+
// http://fabiensanglard.net/shadowmappingPCF/
|
127
|
+
|
128
|
+
float shadow = 0.0;
|
129
|
+
|
130
|
+
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
|
131
|
+
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
|
132
|
+
|
133
|
+
float dx0 = -1.0 * xPixelOffset;
|
134
|
+
float dy0 = -1.0 * yPixelOffset;
|
135
|
+
float dx1 = 1.0 * xPixelOffset;
|
136
|
+
float dy1 = 1.0 * yPixelOffset;
|
137
|
+
|
138
|
+
mat3 shadowKernel;
|
139
|
+
mat3 depthKernel;
|
140
|
+
|
141
|
+
depthKernel[0][0] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
|
142
|
+
depthKernel[0][1] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
|
143
|
+
depthKernel[0][2] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
|
144
|
+
depthKernel[1][0] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
|
145
|
+
depthKernel[1][1] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy ) );
|
146
|
+
depthKernel[1][2] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
|
147
|
+
depthKernel[2][0] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
|
148
|
+
depthKernel[2][1] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
|
149
|
+
depthKernel[2][2] = unpackDepth( texture( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
|
150
|
+
|
151
|
+
vec3 shadowZ = vec3( shadowCoord.z );
|
152
|
+
shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));
|
153
|
+
shadowKernel[0] *= vec3(0.25);
|
154
|
+
|
155
|
+
shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));
|
156
|
+
shadowKernel[1] *= vec3(0.25);
|
157
|
+
|
158
|
+
shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));
|
159
|
+
shadowKernel[2] *= vec3(0.25);
|
160
|
+
|
161
|
+
vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );
|
162
|
+
|
163
|
+
shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
|
164
|
+
shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
|
165
|
+
|
166
|
+
vec4 shadowValues;
|
167
|
+
shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
|
168
|
+
shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
|
169
|
+
shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
|
170
|
+
shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
|
171
|
+
|
172
|
+
shadow = dot( shadowValues, vec4( 1.0 ) );
|
173
|
+
|
174
|
+
shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
|
175
|
+
|
176
|
+
#else
|
177
|
+
|
178
|
+
vec4 rgbaDepth = texture( shadowMap[ i ], shadowCoord.xy );
|
179
|
+
float fDepth = unpackDepth( rgbaDepth );
|
180
|
+
|
181
|
+
if ( fDepth < shadowCoord.z )
|
182
|
+
|
183
|
+
// spot with multiple shadows is darker
|
184
|
+
|
185
|
+
shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );
|
186
|
+
|
187
|
+
// spot with multiple shadows has the same color as single shadow spot
|
188
|
+
|
189
|
+
// shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );
|
190
|
+
|
191
|
+
#endif
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
#ifdef SHADOWMAP_DEBUG
|
197
|
+
|
198
|
+
#ifdef SHADOWMAP_CASCADE
|
199
|
+
|
200
|
+
if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ i ];
|
201
|
+
|
202
|
+
#else
|
203
|
+
|
204
|
+
if ( inFrustum ) outgoingLight *= frustumColors[ i ];
|
205
|
+
|
206
|
+
#endif
|
207
|
+
|
208
|
+
#endif
|
209
|
+
|
210
|
+
}
|
211
|
+
|
212
|
+
// NOTE: I am unsure if this is correct in linear space. -bhouston, Dec 29, 2014
|
213
|
+
shadowColor = inputToLinear( shadowColor );
|
214
|
+
|
215
|
+
outgoingLight = outgoingLight * shadowColor;
|
216
|
+
|
217
|
+
#endif
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifdef USE_SHADOWMAP
|
2
|
+
|
3
|
+
uniform sampler2D shadowMap[ MAX_SHADOWS ];
|
4
|
+
uniform vec2 shadowMapSize[ MAX_SHADOWS ];
|
5
|
+
|
6
|
+
uniform float shadowDarkness[ MAX_SHADOWS ];
|
7
|
+
uniform float shadowBias[ MAX_SHADOWS ];
|
8
|
+
|
9
|
+
in vec4 vShadowCoord[ MAX_SHADOWS ];
|
10
|
+
|
11
|
+
float unpackDepth( const in vec4 rgba_depth ) {
|
12
|
+
|
13
|
+
const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
|
14
|
+
float depth = dot( rgba_depth, bit_shift );
|
15
|
+
return depth;
|
16
|
+
|
17
|
+
}
|
18
|
+
|
19
|
+
#endif
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#ifdef USE_SKINNING
|
2
|
+
|
3
|
+
uniform mat4 bindMatrix;
|
4
|
+
uniform mat4 bindMatrixInverse;
|
5
|
+
|
6
|
+
#ifdef BONE_TEXTURE
|
7
|
+
|
8
|
+
uniform sampler2D boneTexture;
|
9
|
+
uniform int boneTextureWidth;
|
10
|
+
uniform int boneTextureHeight;
|
11
|
+
|
12
|
+
mat4 getBoneMatrix( const in float i ) {
|
13
|
+
|
14
|
+
float j = i * 4.0;
|
15
|
+
float x = mod( j, float( boneTextureWidth ) );
|
16
|
+
float y = floor( j / float( boneTextureWidth ) );
|
17
|
+
|
18
|
+
float dx = 1.0 / float( boneTextureWidth );
|
19
|
+
float dy = 1.0 / float( boneTextureHeight );
|
20
|
+
|
21
|
+
y = dy * ( y + 0.5 );
|
22
|
+
|
23
|
+
vec4 v1 = texture( boneTexture, vec2( dx * ( x + 0.5 ), y ) );
|
24
|
+
vec4 v2 = texture( boneTexture, vec2( dx * ( x + 1.5 ), y ) );
|
25
|
+
vec4 v3 = texture( boneTexture, vec2( dx * ( x + 2.5 ), y ) );
|
26
|
+
vec4 v4 = texture( boneTexture, vec2( dx * ( x + 3.5 ), y ) );
|
27
|
+
|
28
|
+
mat4 bone = mat4( v1, v2, v3, v4 );
|
29
|
+
|
30
|
+
return bone;
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
#else
|
35
|
+
|
36
|
+
uniform mat4 boneGlobalMatrices[ MAX_BONES ];
|
37
|
+
|
38
|
+
mat4 getBoneMatrix( const in float i ) {
|
39
|
+
|
40
|
+
mat4 bone = boneGlobalMatrices[ int(i) ];
|
41
|
+
return bone;
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#endif
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifdef USE_SKINNING
|
2
|
+
|
3
|
+
#ifdef USE_MORPHTARGETS
|
4
|
+
|
5
|
+
vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );
|
6
|
+
|
7
|
+
#else
|
8
|
+
|
9
|
+
vec4 skinVertex = bindMatrix * vec4( position, 1.0 );
|
10
|
+
|
11
|
+
#endif
|
12
|
+
|
13
|
+
vec4 skinned = vec4( 0.0 );
|
14
|
+
skinned += boneMatX * skinVertex * skinWeight.x;
|
15
|
+
skinned += boneMatY * skinVertex * skinWeight.y;
|
16
|
+
skinned += boneMatZ * skinVertex * skinWeight.z;
|
17
|
+
skinned += boneMatW * skinVertex * skinWeight.w;
|
18
|
+
skinned = bindMatrixInverse * skinned;
|
19
|
+
|
20
|
+
#endif
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifdef USE_SKINNING
|
2
|
+
|
3
|
+
mat4 skinMatrix = mat4( 0.0 );
|
4
|
+
skinMatrix += skinWeight.x * boneMatX;
|
5
|
+
skinMatrix += skinWeight.y * boneMatY;
|
6
|
+
skinMatrix += skinWeight.z * boneMatZ;
|
7
|
+
skinMatrix += skinWeight.w * boneMatW;
|
8
|
+
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
|
9
|
+
|
10
|
+
#ifdef USE_MORPHNORMALS
|
11
|
+
|
12
|
+
vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );
|
13
|
+
|
14
|
+
#else
|
15
|
+
|
16
|
+
vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );
|
17
|
+
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#endif
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )
|
2
|
+
|
3
|
+
#ifdef USE_SKINNING
|
4
|
+
|
5
|
+
vec4 worldPosition = modelMatrix * skinned;
|
6
|
+
|
7
|
+
#elif defined( USE_MORPHTARGETS )
|
8
|
+
|
9
|
+
vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );
|
10
|
+
|
11
|
+
#else
|
12
|
+
|
13
|
+
vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,420 @@
|
|
1
|
+
require 'mittsu/renderers/shaders/uniforms_utils'
|
2
|
+
require 'mittsu/renderers/shaders/uniforms_lib'
|
3
|
+
require 'mittsu/renderers/shaders/shader_chunk'
|
4
|
+
|
5
|
+
module Mittsu
|
6
|
+
class ShaderLib_Instance
|
7
|
+
attr_accessor :uniforms, :vertex_shader, :fragment_shader
|
8
|
+
def initialize(uniforms:, vertex_shader:, fragment_shader:)
|
9
|
+
@uniforms = uniforms
|
10
|
+
@vertex_shader = vertex_shader
|
11
|
+
@fragment_shader = fragment_shader
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ShaderLib = {
|
16
|
+
basic: ShaderLib_Instance.new(
|
17
|
+
uniforms: UniformsUtils.merge([
|
18
|
+
UniformsLib[:common],
|
19
|
+
UniformsLib[:fog],
|
20
|
+
UniformsLib[:shadowmap]
|
21
|
+
]),
|
22
|
+
|
23
|
+
vertex_shader: [
|
24
|
+
ShaderChunk[:common],
|
25
|
+
ShaderChunk[:map_pars_vertex],
|
26
|
+
ShaderChunk[:lightmap_pars_vertex],
|
27
|
+
ShaderChunk[:envmap_pars_vertex],
|
28
|
+
ShaderChunk[:color_pars_vertex],
|
29
|
+
ShaderChunk[:morphtarget_pars_vertex],
|
30
|
+
ShaderChunk[:skinning_pars_vertex],
|
31
|
+
ShaderChunk[:shadowmap_pars_vertex],
|
32
|
+
ShaderChunk[:logdepthbuf_pars_vertex],
|
33
|
+
|
34
|
+
"void main() {",
|
35
|
+
|
36
|
+
ShaderChunk[:map_vertex],
|
37
|
+
ShaderChunk[:lightmap_vertex],
|
38
|
+
ShaderChunk[:color_vertex],
|
39
|
+
ShaderChunk[:skinbase_vertex],
|
40
|
+
|
41
|
+
" #ifdef USE_ENVMAP",
|
42
|
+
|
43
|
+
ShaderChunk[:morphnormal_vertex],
|
44
|
+
ShaderChunk[:skinnormal_vertex],
|
45
|
+
ShaderChunk[:defaultnormal_vertex],
|
46
|
+
|
47
|
+
" #endif",
|
48
|
+
|
49
|
+
ShaderChunk[:morphtarget_vertex],
|
50
|
+
ShaderChunk[:skin_vertex],
|
51
|
+
ShaderChunk[:default_vertex],
|
52
|
+
ShaderChunk[:logdepthbuf_vertex],
|
53
|
+
|
54
|
+
ShaderChunk[:worldpos_vertex],
|
55
|
+
ShaderChunk[:envmap_vertex],
|
56
|
+
ShaderChunk[:shadowmap_vertex],
|
57
|
+
|
58
|
+
"}"
|
59
|
+
|
60
|
+
].join("\n"),
|
61
|
+
|
62
|
+
fragment_shader: [
|
63
|
+
|
64
|
+
"uniform vec3 diffuse;",
|
65
|
+
"uniform float opacity;",
|
66
|
+
|
67
|
+
ShaderChunk[:common],
|
68
|
+
ShaderChunk[:color_pars_fragment],
|
69
|
+
ShaderChunk[:map_pars_fragment],
|
70
|
+
ShaderChunk[:alphamap_pars_fragment],
|
71
|
+
ShaderChunk[:lightmap_pars_fragment],
|
72
|
+
ShaderChunk[:envmap_pars_fragment],
|
73
|
+
ShaderChunk[:fog_pars_fragment],
|
74
|
+
ShaderChunk[:shadowmap_pars_fragment],
|
75
|
+
ShaderChunk[:specularmap_pars_fragment],
|
76
|
+
ShaderChunk[:logdepthbuf_pars_fragment],
|
77
|
+
|
78
|
+
"void main() {",
|
79
|
+
|
80
|
+
" vec3 outgoingLight = vec3( 0.0 );", # outgoing light does not have an alpha, the surface does
|
81
|
+
" vec4 diffuseColor = vec4( diffuse, opacity );",
|
82
|
+
|
83
|
+
ShaderChunk[:logdepthbuf_fragment],
|
84
|
+
ShaderChunk[:map_fragment],
|
85
|
+
ShaderChunk[:color_fragment],
|
86
|
+
ShaderChunk[:alphamap_fragment],
|
87
|
+
ShaderChunk[:alphatest_fragment],
|
88
|
+
ShaderChunk[:specularmap_fragment],
|
89
|
+
|
90
|
+
" outgoingLight = diffuseColor.rgb;", # simple shader
|
91
|
+
|
92
|
+
ShaderChunk[:lightmap_fragment], # TODO: Light map on an otherwise unlit surface doesn't make sense.
|
93
|
+
ShaderChunk[:envmap_fragment],
|
94
|
+
ShaderChunk[:shadowmap_fragment], # TODO: Shadows on an otherwise unlit surface doesn't make sense.
|
95
|
+
|
96
|
+
ShaderChunk[:linear_to_gamma_fragment],
|
97
|
+
|
98
|
+
ShaderChunk[:fog_fragment],
|
99
|
+
|
100
|
+
" fragColor = vec4( outgoingLight, diffuseColor.a );", # TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
|
101
|
+
|
102
|
+
"}"
|
103
|
+
|
104
|
+
].join("\n")
|
105
|
+
),
|
106
|
+
lambert: ShaderLib_Instance.new(
|
107
|
+
uniforms: UniformsUtils.merge([
|
108
|
+
UniformsLib[:common],
|
109
|
+
UniformsLib[:fog],
|
110
|
+
UniformsLib[:lights],
|
111
|
+
UniformsLib[:shadow_map],
|
112
|
+
{
|
113
|
+
'emissive' => Uniform.new(:c, Color.new(0x000000)),
|
114
|
+
'wrapRGB' => Uniform.new(:v3, Vector3.new(1.0, 1.0, 1.0))
|
115
|
+
}
|
116
|
+
]),
|
117
|
+
vertex_shader: [
|
118
|
+
'#define LAMBERT',
|
119
|
+
'out vec3 vLightFront;',
|
120
|
+
'#ifdef DOUBLE_SIDED',
|
121
|
+
' out vec3 vLightBack;',
|
122
|
+
'#endif',
|
123
|
+
ShaderChunk[:common],
|
124
|
+
ShaderChunk[:map_pars_vertex],
|
125
|
+
ShaderChunk[:lightmap_pars_vertex],
|
126
|
+
ShaderChunk[:envmap_pars_vertex],
|
127
|
+
ShaderChunk[:lights_lambert_pars_vertex],
|
128
|
+
ShaderChunk[:color_pars_vertex],
|
129
|
+
ShaderChunk[:morphtarget_pars_vertex],
|
130
|
+
ShaderChunk[:skinning_pars_vertex],
|
131
|
+
ShaderChunk[:shadowmap_pars_vertex],
|
132
|
+
ShaderChunk[:logdepthbuf_pars_vertex],
|
133
|
+
'void main() {',
|
134
|
+
|
135
|
+
ShaderChunk[:map_vertex],
|
136
|
+
ShaderChunk[:lightmap_vertex],
|
137
|
+
ShaderChunk[:color_vertex],
|
138
|
+
|
139
|
+
ShaderChunk[:morphnormal_vertex],
|
140
|
+
ShaderChunk[:skinbase_vertex],
|
141
|
+
ShaderChunk[:skinnormal_vertex],
|
142
|
+
ShaderChunk[:defaultnormal_vertex],
|
143
|
+
|
144
|
+
ShaderChunk[:morphtarget_vertex],
|
145
|
+
ShaderChunk[:skinning_vertex],
|
146
|
+
ShaderChunk[:default_vertex],
|
147
|
+
ShaderChunk[:logdepthbuf_vertex],
|
148
|
+
|
149
|
+
ShaderChunk[:worldpos_vertex],
|
150
|
+
ShaderChunk[:envmap_vertex],
|
151
|
+
ShaderChunk[:lights_lambert_vertex],
|
152
|
+
ShaderChunk[:shadowmap_vertex],
|
153
|
+
|
154
|
+
'}',
|
155
|
+
].join("\n"),
|
156
|
+
fragment_shader: [
|
157
|
+
'uniform vec3 diffuse;',
|
158
|
+
'uniform vec3 emissive;',
|
159
|
+
'uniform float opacity;',
|
160
|
+
|
161
|
+
'in vec3 vLightFront;',
|
162
|
+
|
163
|
+
'#ifdef DOUBLE_SIDED',
|
164
|
+
' in vec3 vLightBack;',
|
165
|
+
'#endif',
|
166
|
+
|
167
|
+
ShaderChunk[:common],
|
168
|
+
ShaderChunk[:color_pars_fragment],
|
169
|
+
ShaderChunk[:map_pars_fragment],
|
170
|
+
ShaderChunk[:alphamap_pars_fragment],
|
171
|
+
ShaderChunk[:lightmap_pars_fragment],
|
172
|
+
ShaderChunk[:envmap_pars_fragment],
|
173
|
+
ShaderChunk[:fog_pars_fragment],
|
174
|
+
ShaderChunk[:shadowmap_pars_fragment],
|
175
|
+
ShaderChunk[:specularmap_pars_fragment],
|
176
|
+
ShaderChunk[:logdepthbuf_pars_fragment],
|
177
|
+
|
178
|
+
'void main() {',
|
179
|
+
|
180
|
+
' vec3 outgoingLight = vec3( 0.0 );', # outgoing light does not have an alpha, the surface does
|
181
|
+
' vec4 diffuseColor = vec4( diffuse, opacity );',
|
182
|
+
|
183
|
+
ShaderChunk[:logdepthbuf_fragment],
|
184
|
+
ShaderChunk[:map_fragment],
|
185
|
+
ShaderChunk[:color_fragment],
|
186
|
+
ShaderChunk[:alphamap_fragment],
|
187
|
+
ShaderChunk[:alphatest_fragment],
|
188
|
+
ShaderChunk[:specularmap_fragment],
|
189
|
+
|
190
|
+
' #ifdef DOUBLE_SIDED',
|
191
|
+
|
192
|
+
#'float isFront = float( gl_FrontFacing );',
|
193
|
+
#'fragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;',
|
194
|
+
|
195
|
+
' if ( gl_FrontFacing )',
|
196
|
+
' outgoingLight += diffuseColor.rgb * vLightFront + emissive;',
|
197
|
+
' else',
|
198
|
+
' outgoingLight += diffuseColor.rgb * vLightBack + emissive;',
|
199
|
+
|
200
|
+
' #else',
|
201
|
+
|
202
|
+
' outgoingLight += diffuseColor.rgb * vLightFront + emissive;',
|
203
|
+
|
204
|
+
' #endif',
|
205
|
+
|
206
|
+
ShaderChunk[:lightmap_fragment],
|
207
|
+
ShaderChunk[:envmap_fragment],
|
208
|
+
ShaderChunk[:shadowmap_fragment],
|
209
|
+
|
210
|
+
ShaderChunk[:linear_to_gamma_fragment],
|
211
|
+
|
212
|
+
ShaderChunk[:fog_fragment],
|
213
|
+
|
214
|
+
# ' fragColor = vec4( outgoingLight, diffuseColor.a );', # TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
|
215
|
+
|
216
|
+
' fragColor = vec4(outgoingLight, diffuseColor.a);',
|
217
|
+
'}'
|
218
|
+
].join("\n")
|
219
|
+
),
|
220
|
+
phong: ShaderLib_Instance.new(
|
221
|
+
uniforms: UniformsUtils.merge([
|
222
|
+
UniformsLib[:common],
|
223
|
+
UniformsLib[:bump],
|
224
|
+
UniformsLib[:normal_map],
|
225
|
+
UniformsLib[:fog],
|
226
|
+
UniformsLib[:lights],
|
227
|
+
UniformsLib[:shadow_map],
|
228
|
+
{
|
229
|
+
'emissive' => Uniform.new(:c, Color.new(0x000000)),
|
230
|
+
'specular' => Uniform.new(:c, Color.new(0x111111)),
|
231
|
+
'shininess' => Uniform.new(:f, 30.0),
|
232
|
+
'wrapRGB' => Uniform.new(:v3, Vector3.new(1.0, 1.0, 1.0))
|
233
|
+
}
|
234
|
+
]),
|
235
|
+
vertex_shader: [
|
236
|
+
'#define PHONG',
|
237
|
+
'out vec3 vViewPosition;',
|
238
|
+
'#ifndef FLAT_SHADED',
|
239
|
+
' out vec3 vNormal;',
|
240
|
+
'#endif',
|
241
|
+
|
242
|
+
ShaderChunk[:common],
|
243
|
+
ShaderChunk[:map_pars_vertex],
|
244
|
+
ShaderChunk[:lightmap_pars_vertex],
|
245
|
+
ShaderChunk[:envmap_pars_vertex],
|
246
|
+
ShaderChunk[:lights_phong_pars_vertex],
|
247
|
+
ShaderChunk[:color_pars_vertex],
|
248
|
+
ShaderChunk[:morphtarget_pars_vertex],
|
249
|
+
ShaderChunk[:skinning_pars_vertex],
|
250
|
+
ShaderChunk[:shadowmap_pars_vertex],
|
251
|
+
ShaderChunk[:logdepthbuf_pars_vertex],
|
252
|
+
|
253
|
+
'void main() {',
|
254
|
+
|
255
|
+
ShaderChunk[:map_vertex],
|
256
|
+
ShaderChunk[:lightmap_vertex],
|
257
|
+
ShaderChunk[:color_vertex],
|
258
|
+
|
259
|
+
ShaderChunk[:morphnormal_vertex],
|
260
|
+
ShaderChunk[:skinbase_vertex],
|
261
|
+
ShaderChunk[:skinnormal_vertex],
|
262
|
+
ShaderChunk[:defaultnormal_vertex],
|
263
|
+
|
264
|
+
'#ifndef FLAT_SHADED', # Normal computed with derivatives when FLAT_SHADED
|
265
|
+
' vNormal = normalize( transformedNormal );',
|
266
|
+
'#endif',
|
267
|
+
|
268
|
+
ShaderChunk[:morphtarget_vertex],
|
269
|
+
ShaderChunk[:skinning_vertex],
|
270
|
+
ShaderChunk[:default_vertex],
|
271
|
+
ShaderChunk[:logdepthbuf_vertex],
|
272
|
+
|
273
|
+
' vViewPosition = -mvPosition.xyz;',
|
274
|
+
|
275
|
+
ShaderChunk[:worldpos_vertex],
|
276
|
+
ShaderChunk[:envmap_vertex],
|
277
|
+
ShaderChunk[:lights_phong_vertex],
|
278
|
+
ShaderChunk[:shadowmap_vertex],
|
279
|
+
'}'
|
280
|
+
].join("\n"),
|
281
|
+
fragment_shader: [
|
282
|
+
'#define PHONG',
|
283
|
+
|
284
|
+
'uniform vec3 diffuse;',
|
285
|
+
'uniform vec3 emissive;',
|
286
|
+
'uniform vec3 specular;',
|
287
|
+
'uniform float shininess;',
|
288
|
+
'uniform float opacity;',
|
289
|
+
|
290
|
+
ShaderChunk[:common],
|
291
|
+
ShaderChunk[:color_pars_fragment],
|
292
|
+
ShaderChunk[:map_pars_fragment],
|
293
|
+
ShaderChunk[:alphamap_pars_fragment],
|
294
|
+
ShaderChunk[:lightmap_pars_fragment],
|
295
|
+
ShaderChunk[:envmap_pars_fragment],
|
296
|
+
ShaderChunk[:fog_pars_fragment],
|
297
|
+
ShaderChunk[:lights_phong_pars_fragment],
|
298
|
+
ShaderChunk[:shadowmap_pars_fragment],
|
299
|
+
ShaderChunk[:bumpmap_pars_fragment],
|
300
|
+
ShaderChunk[:normalmap_pars_fragment],
|
301
|
+
ShaderChunk[:specularmap_pars_fragment],
|
302
|
+
ShaderChunk[:logdepthbuf_pars_fragment],
|
303
|
+
|
304
|
+
'void main() {',
|
305
|
+
|
306
|
+
' vec3 outgoingLight = vec3( 0.0 );', # outgoing light does not have an alpha, the surface does
|
307
|
+
' vec4 diffuseColor = vec4( diffuse, opacity );',
|
308
|
+
|
309
|
+
ShaderChunk[:logdepthbuf_fragment],
|
310
|
+
ShaderChunk[:map_fragment],
|
311
|
+
ShaderChunk[:color_fragment],
|
312
|
+
ShaderChunk[:alphamap_fragment],
|
313
|
+
ShaderChunk[:alphatest_fragment],
|
314
|
+
ShaderChunk[:specularmap_fragment],
|
315
|
+
|
316
|
+
ShaderChunk[:lights_phong_fragment],
|
317
|
+
|
318
|
+
ShaderChunk[:lightmap_fragment],
|
319
|
+
ShaderChunk[:envmap_fragment],
|
320
|
+
ShaderChunk[:shadowmap_fragment],
|
321
|
+
|
322
|
+
ShaderChunk[:linear_to_gamma_fragment],
|
323
|
+
|
324
|
+
ShaderChunk[:fog_fragment],
|
325
|
+
|
326
|
+
' fragColor = vec4( outgoingLight, diffuseColor.a );', # TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
|
327
|
+
|
328
|
+
'}'
|
329
|
+
].join("\n")
|
330
|
+
),
|
331
|
+
# TODO:
|
332
|
+
# particle_basic
|
333
|
+
# dashed
|
334
|
+
# depth
|
335
|
+
# normal
|
336
|
+
cube: ShaderLib_Instance.new(
|
337
|
+
uniforms: {
|
338
|
+
'tCube' => Uniform.new(:t, nil),
|
339
|
+
'tFlip' => Uniform.new(:f, -1.0)
|
340
|
+
},
|
341
|
+
vertex_shader: [
|
342
|
+
'out vec3 vWorldPosition;',
|
343
|
+
|
344
|
+
ShaderChunk[:common],
|
345
|
+
ShaderChunk[:logdepthbuf_pars_vertex],
|
346
|
+
|
347
|
+
'void main() {',
|
348
|
+
' vWorldPosition = transformDirection( position, modelMatrix );',
|
349
|
+
' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
|
350
|
+
ShaderChunk[:logdepthbuf_vertex],
|
351
|
+
'}'
|
352
|
+
].join("\n"),
|
353
|
+
fragment_shader: [
|
354
|
+
'uniform samplerCube tCube;',
|
355
|
+
'uniform float tFlip;',
|
356
|
+
|
357
|
+
'in vec3 vWorldPosition;',
|
358
|
+
|
359
|
+
ShaderChunk[:common],
|
360
|
+
ShaderChunk[:logdepthbuf_pars_fragment],
|
361
|
+
|
362
|
+
'void main() {',
|
363
|
+
' fragColor = texture( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );',
|
364
|
+
ShaderChunk[:logdepthbuf_fragment],
|
365
|
+
'}'
|
366
|
+
].join("\n")
|
367
|
+
),
|
368
|
+
# equirect
|
369
|
+
depth_rgba: ShaderLib_Instance.new(
|
370
|
+
uniforms: {},
|
371
|
+
vertex_shader: [
|
372
|
+
ShaderChunk[:common],
|
373
|
+
ShaderChunk[:morphtarget_pars_vertex],
|
374
|
+
ShaderChunk[:skinning_pars_vertex],
|
375
|
+
ShaderChunk[:logdepthbuf_pars_vertex],
|
376
|
+
|
377
|
+
'void main() {',
|
378
|
+
ShaderChunk[:skinbase_vertex],
|
379
|
+
ShaderChunk[:morphtarget_vertex],
|
380
|
+
ShaderChunk[:skinning_vertex],
|
381
|
+
ShaderChunk[:default_vertex],
|
382
|
+
ShaderChunk[:logdepthbuf_vertex],
|
383
|
+
'}'
|
384
|
+
].join("\n"),
|
385
|
+
fragment_shader: [
|
386
|
+
ShaderChunk[:common],
|
387
|
+
ShaderChunk[:logdepthbuf_pars_fragment],
|
388
|
+
|
389
|
+
'vec4 pack_depth( const in float depth ) {',
|
390
|
+
|
391
|
+
' const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );',
|
392
|
+
' const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );',
|
393
|
+
' vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );', # ' vec4 res = fract( depth * bit_shift );',
|
394
|
+
' res -= res.xxyz * bit_mask;',
|
395
|
+
' return res;',
|
396
|
+
|
397
|
+
'}',
|
398
|
+
|
399
|
+
'void main() {',
|
400
|
+
ShaderChunk[:logdepthbuf_fragment],
|
401
|
+
|
402
|
+
' #ifdef USE_LOGDEPTHBUF_EXT',
|
403
|
+
|
404
|
+
' fragColor = pack_depth( gl_FragDepthEXT );',
|
405
|
+
|
406
|
+
' #else',
|
407
|
+
|
408
|
+
' fragColor = pack_depth( gl_FragCoord.z );',
|
409
|
+
|
410
|
+
' #endif',
|
411
|
+
|
412
|
+
#'fragColor = pack_depth( gl_FragCoord.z / gl_FragCoord.w );',
|
413
|
+
#'float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );',
|
414
|
+
#'fragColor = pack_depth( z );',
|
415
|
+
#'fragColor = vec4( z, z, z, 1.0 );',
|
416
|
+
'}'
|
417
|
+
].join("\n")
|
418
|
+
)
|
419
|
+
}
|
420
|
+
end
|