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,11 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class OpenGL::Shader
|
3
|
+
Chunk = Hash.new do |chunks, key|
|
4
|
+
file_name = "#{key.to_s}.glsl"
|
5
|
+
file_path = File.join(__dir__, 'chunks', file_name)
|
6
|
+
chunk = File.read(file_path)
|
7
|
+
# chunk = "// #{chunk_name}\n#{chunk}"
|
8
|
+
chunks[key] = chunk
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#ifdef USE_BUMPMAP
|
2
|
+
|
3
|
+
uniform sampler2D bumpMap;
|
4
|
+
uniform float bumpScale;
|
5
|
+
|
6
|
+
// Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen
|
7
|
+
// http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html
|
8
|
+
|
9
|
+
// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
|
10
|
+
|
11
|
+
vec2 dHdxy_fwd() {
|
12
|
+
|
13
|
+
vec2 dSTdx = dFdx( vUv );
|
14
|
+
vec2 dSTdy = dFdy( vUv );
|
15
|
+
|
16
|
+
float Hll = bumpScale * texture( bumpMap, vUv ).x;
|
17
|
+
float dBx = bumpScale * texture( bumpMap, vUv + dSTdx ).x - Hll;
|
18
|
+
float dBy = bumpScale * texture( bumpMap, vUv + dSTdy ).x - Hll;
|
19
|
+
|
20
|
+
return vec2( dBx, dBy );
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {
|
25
|
+
|
26
|
+
vec3 vSigmaX = dFdx( surf_pos );
|
27
|
+
vec3 vSigmaY = dFdy( surf_pos );
|
28
|
+
vec3 vN = surf_norm; // normalized
|
29
|
+
|
30
|
+
vec3 R1 = cross( vSigmaY, vN );
|
31
|
+
vec3 R2 = cross( vN, vSigmaX );
|
32
|
+
|
33
|
+
float fDet = dot( vSigmaX, R1 );
|
34
|
+
|
35
|
+
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
|
36
|
+
return normalize( abs( fDet ) * surf_norm - vGrad );
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
#endif
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#define PI 3.14159
|
2
|
+
#define PI2 6.28318
|
3
|
+
#define RECIPROCAL_PI2 0.15915494
|
4
|
+
#define LOG2 1.442695
|
5
|
+
#define EPSILON 1e-6
|
6
|
+
|
7
|
+
float square( in float a ) { return a*a; }
|
8
|
+
vec2 square( in vec2 a ) { return vec2( a.x*a.x, a.y*a.y ); }
|
9
|
+
vec3 square( in vec3 a ) { return vec3( a.x*a.x, a.y*a.y, a.z*a.z ); }
|
10
|
+
vec4 square( in vec4 a ) { return vec4( a.x*a.x, a.y*a.y, a.z*a.z, a.w*a.w ); }
|
11
|
+
float saturate( in float a ) { return clamp( a, 0.0, 1.0 ); }
|
12
|
+
vec2 saturate( in vec2 a ) { return clamp( a, 0.0, 1.0 ); }
|
13
|
+
vec3 saturate( in vec3 a ) { return clamp( a, 0.0, 1.0 ); }
|
14
|
+
vec4 saturate( in vec4 a ) { return clamp( a, 0.0, 1.0 ); }
|
15
|
+
float average( in float a ) { return a; }
|
16
|
+
float average( in vec2 a ) { return ( a.x + a.y) * 0.5; }
|
17
|
+
float average( in vec3 a ) { return ( a.x + a.y + a.z) / 3.0; }
|
18
|
+
float average( in vec4 a ) { return ( a.x + a.y + a.z + a.w) * 0.25; }
|
19
|
+
float whiteCompliment( in float a ) { return saturate( 1.0 - a ); }
|
20
|
+
vec2 whiteCompliment( in vec2 a ) { return saturate( vec2(1.0) - a ); }
|
21
|
+
vec3 whiteCompliment( in vec3 a ) { return saturate( vec3(1.0) - a ); }
|
22
|
+
vec4 whiteCompliment( in vec4 a ) { return saturate( vec4(1.0) - a ); }
|
23
|
+
vec3 transformDirection( in vec3 normal, in mat4 matrix ) {
|
24
|
+
return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );
|
25
|
+
}
|
26
|
+
// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations
|
27
|
+
vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {
|
28
|
+
return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );
|
29
|
+
}
|
30
|
+
vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal) {
|
31
|
+
float distance = dot( planeNormal, point-pointOnPlane );
|
32
|
+
return point - distance * planeNormal;
|
33
|
+
}
|
34
|
+
float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
|
35
|
+
return sign( dot( point - pointOnPlane, planeNormal ) );
|
36
|
+
}
|
37
|
+
vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
|
38
|
+
return pointOnLine + lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) );
|
39
|
+
}
|
40
|
+
float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
|
41
|
+
if ( decayExponent > 0.0 ) {
|
42
|
+
return pow( saturate( 1.0 - lightDistance / cutoffDistance ), decayExponent );
|
43
|
+
}
|
44
|
+
return 1.0;
|
45
|
+
}
|
46
|
+
|
47
|
+
vec3 inputToLinear( in vec3 a ) {
|
48
|
+
#ifdef GAMMA_INPUT
|
49
|
+
return pow( a, vec3( float( GAMMA_FACTOR ) ) );
|
50
|
+
#else
|
51
|
+
return a;
|
52
|
+
#endif
|
53
|
+
}
|
54
|
+
vec3 linearToOutput( in vec3 a ) {
|
55
|
+
#ifdef GAMMA_OUTPUT
|
56
|
+
return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );
|
57
|
+
#else
|
58
|
+
return a;
|
59
|
+
#endif
|
60
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifdef USE_SKINNING
|
2
|
+
|
3
|
+
vec4 mvPosition = modelViewMatrix * skinned;
|
4
|
+
|
5
|
+
#elif defined( USE_MORPHTARGETS )
|
6
|
+
|
7
|
+
vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );
|
8
|
+
|
9
|
+
#else
|
10
|
+
|
11
|
+
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
12
|
+
|
13
|
+
#endif
|
14
|
+
|
15
|
+
gl_Position = projectionMatrix * mvPosition;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifdef USE_SKINNING
|
2
|
+
|
3
|
+
vec3 objectNormal = skinnedNormal.xyz;
|
4
|
+
|
5
|
+
#elif defined( USE_MORPHNORMALS )
|
6
|
+
|
7
|
+
vec3 objectNormal = morphedNormal;
|
8
|
+
|
9
|
+
#else
|
10
|
+
|
11
|
+
vec3 objectNormal = normal;
|
12
|
+
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#ifdef FLIP_SIDED
|
16
|
+
|
17
|
+
objectNormal = -objectNormal;
|
18
|
+
|
19
|
+
#endif
|
20
|
+
|
21
|
+
vec3 transformedNormal = normalMatrix * objectNormal;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#ifdef USE_ENVMAP
|
2
|
+
|
3
|
+
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
|
4
|
+
|
5
|
+
vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
|
6
|
+
|
7
|
+
// Transforming Normal Vectors with the Inverse Transformation
|
8
|
+
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
9
|
+
|
10
|
+
#ifdef ENVMAP_MODE_REFLECTION
|
11
|
+
|
12
|
+
vec3 reflectVec = reflect( cameraToVertex, worldNormal );
|
13
|
+
|
14
|
+
#else
|
15
|
+
|
16
|
+
vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );
|
17
|
+
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#else
|
21
|
+
|
22
|
+
vec3 reflectVec = vReflect;
|
23
|
+
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#ifdef DOUBLE_SIDED
|
27
|
+
float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );
|
28
|
+
#else
|
29
|
+
float flipNormal = 1.0;
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifdef ENVMAP_TYPE_CUBE
|
33
|
+
vec4 envColor = texture( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
|
34
|
+
|
35
|
+
#elif defined( ENVMAP_TYPE_EQUIREC )
|
36
|
+
vec2 sampleUV;
|
37
|
+
sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
|
38
|
+
sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
|
39
|
+
vec4 envColor = texture( envMap, sampleUV );
|
40
|
+
|
41
|
+
#elif defined( ENVMAP_TYPE_SPHERE )
|
42
|
+
vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));
|
43
|
+
vec4 envColor = texture( envMap, reflectView.xy * 0.5 + 0.5 );
|
44
|
+
#endif
|
45
|
+
|
46
|
+
envColor.xyz = inputToLinear( envColor.xyz );
|
47
|
+
|
48
|
+
#ifdef ENVMAP_BLENDING_MULTIPLY
|
49
|
+
|
50
|
+
outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
|
51
|
+
|
52
|
+
#elif defined( ENVMAP_BLENDING_MIX )
|
53
|
+
|
54
|
+
outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
|
55
|
+
|
56
|
+
#elif defined( ENVMAP_BLENDING_ADD )
|
57
|
+
|
58
|
+
outgoingLight += envColor.xyz * specularStrength * reflectivity;
|
59
|
+
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#endif
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifdef USE_ENVMAP
|
2
|
+
|
3
|
+
uniform float reflectivity;
|
4
|
+
#ifdef ENVMAP_TYPE_CUBE
|
5
|
+
uniform samplerCube envMap;
|
6
|
+
#else
|
7
|
+
uniform sampler2D envMap;
|
8
|
+
#endif
|
9
|
+
uniform float flipEnvMap;
|
10
|
+
|
11
|
+
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
|
12
|
+
|
13
|
+
uniform float refractionRatio;
|
14
|
+
|
15
|
+
#else
|
16
|
+
|
17
|
+
in vec3 vReflect;
|
18
|
+
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )
|
2
|
+
|
3
|
+
vec3 worldNormal = transformDirection( objectNormal, modelMatrix );
|
4
|
+
|
5
|
+
vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
|
6
|
+
|
7
|
+
#ifdef ENVMAP_MODE_REFLECTION
|
8
|
+
|
9
|
+
vReflect = reflect( cameraToVertex, worldNormal );
|
10
|
+
|
11
|
+
#else
|
12
|
+
|
13
|
+
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#ifdef USE_FOG
|
2
|
+
|
3
|
+
#ifdef USE_LOGDEPTHBUF_EXT
|
4
|
+
|
5
|
+
float depth = gl_FragDepthEXT / gl_FragCoord.w;
|
6
|
+
|
7
|
+
#else
|
8
|
+
|
9
|
+
float depth = gl_FragCoord.z / gl_FragCoord.w;
|
10
|
+
|
11
|
+
#endif
|
12
|
+
|
13
|
+
#ifdef FOG_EXP2
|
14
|
+
|
15
|
+
float fogFactor = exp2( - square( fogDensity ) * square( depth ) * LOG2 );
|
16
|
+
fogFactor = whiteCompliment( fogFactor );
|
17
|
+
|
18
|
+
#else
|
19
|
+
|
20
|
+
float fogFactor = smoothstep( fogNear, fogFar, depth );
|
21
|
+
|
22
|
+
#endif
|
23
|
+
|
24
|
+
outgoingLight = mix( outgoingLight, fogColor, fogFactor );
|
25
|
+
|
26
|
+
#endif
|
@@ -0,0 +1,43 @@
|
|
1
|
+
uniform vec3 ambientLightColor;
|
2
|
+
|
3
|
+
#if MAX_DIR_LIGHTS > 0
|
4
|
+
|
5
|
+
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
|
6
|
+
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
|
7
|
+
|
8
|
+
#endif
|
9
|
+
|
10
|
+
#if MAX_HEMI_LIGHTS > 0
|
11
|
+
|
12
|
+
uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];
|
13
|
+
uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];
|
14
|
+
uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];
|
15
|
+
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#if MAX_POINT_LIGHTS > 0
|
19
|
+
|
20
|
+
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
|
21
|
+
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
|
22
|
+
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
|
23
|
+
uniform float pointLightDecay[ MAX_POINT_LIGHTS ];
|
24
|
+
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#if MAX_SPOT_LIGHTS > 0
|
28
|
+
|
29
|
+
uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];
|
30
|
+
uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];
|
31
|
+
uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];
|
32
|
+
uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];
|
33
|
+
uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];
|
34
|
+
uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];
|
35
|
+
uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];
|
36
|
+
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#ifdef WRAP_AROUND
|
40
|
+
|
41
|
+
uniform vec3 wrapRGB;
|
42
|
+
|
43
|
+
#endif
|
@@ -0,0 +1,196 @@
|
|
1
|
+
vLightFront = vec3( 0.0 );
|
2
|
+
|
3
|
+
#ifdef DOUBLE_SIDED
|
4
|
+
|
5
|
+
vLightBack = vec3( 0.0 );
|
6
|
+
|
7
|
+
#endif
|
8
|
+
|
9
|
+
transformedNormal = normalize( transformedNormal );
|
10
|
+
|
11
|
+
#if MAX_DIR_LIGHTS > 0
|
12
|
+
|
13
|
+
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
|
14
|
+
|
15
|
+
vec3 dirVector = transformDirection( directionalLightDirection[ i ], viewMatrix );
|
16
|
+
|
17
|
+
float dotProduct = dot( transformedNormal, dirVector );
|
18
|
+
vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );
|
19
|
+
|
20
|
+
#ifdef DOUBLE_SIDED
|
21
|
+
|
22
|
+
vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );
|
23
|
+
|
24
|
+
#ifdef WRAP_AROUND
|
25
|
+
|
26
|
+
vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );
|
27
|
+
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifdef WRAP_AROUND
|
33
|
+
|
34
|
+
vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );
|
35
|
+
directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );
|
36
|
+
|
37
|
+
#ifdef DOUBLE_SIDED
|
38
|
+
|
39
|
+
directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );
|
40
|
+
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#endif
|
44
|
+
|
45
|
+
vLightFront += directionalLightColor[ i ] * directionalLightWeighting;
|
46
|
+
|
47
|
+
#ifdef DOUBLE_SIDED
|
48
|
+
|
49
|
+
vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;
|
50
|
+
|
51
|
+
#endif
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if MAX_POINT_LIGHTS > 0
|
58
|
+
|
59
|
+
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
|
60
|
+
|
61
|
+
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
|
62
|
+
vec3 lVector = lPosition.xyz - mvPosition.xyz;
|
63
|
+
|
64
|
+
float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );
|
65
|
+
|
66
|
+
lVector = normalize( lVector );
|
67
|
+
float dotProduct = dot( transformedNormal, lVector );
|
68
|
+
|
69
|
+
vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );
|
70
|
+
|
71
|
+
#ifdef DOUBLE_SIDED
|
72
|
+
|
73
|
+
vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );
|
74
|
+
|
75
|
+
#ifdef WRAP_AROUND
|
76
|
+
|
77
|
+
vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );
|
78
|
+
|
79
|
+
#endif
|
80
|
+
|
81
|
+
#endif
|
82
|
+
|
83
|
+
#ifdef WRAP_AROUND
|
84
|
+
|
85
|
+
vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );
|
86
|
+
pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );
|
87
|
+
|
88
|
+
#ifdef DOUBLE_SIDED
|
89
|
+
|
90
|
+
pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );
|
91
|
+
|
92
|
+
#endif
|
93
|
+
|
94
|
+
#endif
|
95
|
+
|
96
|
+
vLightFront += pointLightColor[ i ] * pointLightWeighting * attenuation;
|
97
|
+
|
98
|
+
#ifdef DOUBLE_SIDED
|
99
|
+
|
100
|
+
vLightBack += pointLightColor[ i ] * pointLightWeightingBack * attenuation;
|
101
|
+
|
102
|
+
#endif
|
103
|
+
|
104
|
+
}
|
105
|
+
|
106
|
+
#endif
|
107
|
+
|
108
|
+
#if MAX_SPOT_LIGHTS > 0
|
109
|
+
|
110
|
+
for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
|
111
|
+
|
112
|
+
vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );
|
113
|
+
vec3 lVector = lPosition.xyz - mvPosition.xyz;
|
114
|
+
|
115
|
+
float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - worldPosition.xyz ) );
|
116
|
+
|
117
|
+
if ( spotEffect > spotLightAngleCos[ i ] ) {
|
118
|
+
|
119
|
+
spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );
|
120
|
+
|
121
|
+
float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );
|
122
|
+
|
123
|
+
lVector = normalize( lVector );
|
124
|
+
|
125
|
+
float dotProduct = dot( transformedNormal, lVector );
|
126
|
+
vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );
|
127
|
+
|
128
|
+
#ifdef DOUBLE_SIDED
|
129
|
+
|
130
|
+
vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );
|
131
|
+
|
132
|
+
#ifdef WRAP_AROUND
|
133
|
+
|
134
|
+
vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );
|
135
|
+
|
136
|
+
#endif
|
137
|
+
|
138
|
+
#endif
|
139
|
+
|
140
|
+
#ifdef WRAP_AROUND
|
141
|
+
|
142
|
+
vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );
|
143
|
+
spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );
|
144
|
+
|
145
|
+
#ifdef DOUBLE_SIDED
|
146
|
+
|
147
|
+
spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );
|
148
|
+
|
149
|
+
#endif
|
150
|
+
|
151
|
+
#endif
|
152
|
+
|
153
|
+
vLightFront += spotLightColor[ i ] * spotLightWeighting * attenuation * spotEffect;
|
154
|
+
|
155
|
+
#ifdef DOUBLE_SIDED
|
156
|
+
|
157
|
+
vLightBack += spotLightColor[ i ] * spotLightWeightingBack * attenuation * spotEffect;
|
158
|
+
|
159
|
+
#endif
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
#endif
|
166
|
+
|
167
|
+
#if MAX_HEMI_LIGHTS > 0
|
168
|
+
|
169
|
+
for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
|
170
|
+
|
171
|
+
vec3 lVector = transformDirection( hemisphereLightDirection[ i ], viewMatrix );
|
172
|
+
|
173
|
+
float dotProduct = dot( transformedNormal, lVector );
|
174
|
+
|
175
|
+
float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;
|
176
|
+
float hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;
|
177
|
+
|
178
|
+
vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
|
179
|
+
|
180
|
+
#ifdef DOUBLE_SIDED
|
181
|
+
|
182
|
+
vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );
|
183
|
+
|
184
|
+
#endif
|
185
|
+
|
186
|
+
}
|
187
|
+
|
188
|
+
#endif
|
189
|
+
|
190
|
+
vLightFront += ambientLightColor;
|
191
|
+
|
192
|
+
#ifdef DOUBLE_SIDED
|
193
|
+
|
194
|
+
vLightBack += ambientLightColor;
|
195
|
+
|
196
|
+
#endif
|