mittsu-opengl 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +18 -0
  3. data/.github/workflows/build-workflow.yml +67 -0
  4. data/.gitignore +12 -0
  5. data/.rubocop.yml +1158 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +195 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/install-glfw.ps1 +13 -0
  14. data/lib/mittsu/generic_lib.rb +116 -0
  15. data/lib/mittsu/glfw/lib.rb +58 -0
  16. data/lib/mittsu/glfw/window.rb +231 -0
  17. data/lib/mittsu/opengl/buffer.rb +13 -0
  18. data/lib/mittsu/opengl/default_target.rb +50 -0
  19. data/lib/mittsu/opengl/geometry_group.rb +758 -0
  20. data/lib/mittsu/opengl/geometry_like.rb +132 -0
  21. data/lib/mittsu/opengl/gl_debug.rb +85 -0
  22. data/lib/mittsu/opengl/gl_extensions.rb +42 -0
  23. data/lib/mittsu/opengl/gl_mittsu_params.rb +53 -0
  24. data/lib/mittsu/opengl/helper.rb +120 -0
  25. data/lib/mittsu/opengl/implementation.rb +31 -0
  26. data/lib/mittsu/opengl/lib.rb +19 -0
  27. data/lib/mittsu/opengl/light_renderer.rb +43 -0
  28. data/lib/mittsu/opengl/material_basics.rb +57 -0
  29. data/lib/mittsu/opengl/plugins/shadow_map_plugin.rb +416 -0
  30. data/lib/mittsu/opengl/plugins/sprite_fragment.glsl +38 -0
  31. data/lib/mittsu/opengl/plugins/sprite_plugin.rb +250 -0
  32. data/lib/mittsu/opengl/plugins/sprite_vertex.glsl +31 -0
  33. data/lib/mittsu/opengl/program.rb +250 -0
  34. data/lib/mittsu/opengl/renderer.rb +1028 -0
  35. data/lib/mittsu/opengl/shader/chunk.rb +11 -0
  36. data/lib/mittsu/opengl/shader/chunks/alphamap_fragment.glsl +5 -0
  37. data/lib/mittsu/opengl/shader/chunks/alphamap_pars_fragment.glsl +5 -0
  38. data/lib/mittsu/opengl/shader/chunks/alphatest_fragment.glsl +5 -0
  39. data/lib/mittsu/opengl/shader/chunks/bumpmap_pars_fragment.glsl +40 -0
  40. data/lib/mittsu/opengl/shader/chunks/color_fragment.glsl +5 -0
  41. data/lib/mittsu/opengl/shader/chunks/color_pars_fragment.glsl +5 -0
  42. data/lib/mittsu/opengl/shader/chunks/color_pars_vertex.glsl +5 -0
  43. data/lib/mittsu/opengl/shader/chunks/color_vertex.glsl +5 -0
  44. data/lib/mittsu/opengl/shader/chunks/common.glsl +60 -0
  45. data/lib/mittsu/opengl/shader/chunks/default_vertex.glsl +15 -0
  46. data/lib/mittsu/opengl/shader/chunks/defaultnormal_vertex.glsl +21 -0
  47. data/lib/mittsu/opengl/shader/chunks/envmap_fragment.glsl +62 -0
  48. data/lib/mittsu/opengl/shader/chunks/envmap_pars_fragment.glsl +21 -0
  49. data/lib/mittsu/opengl/shader/chunks/envmap_pars_vertex.glsl +7 -0
  50. data/lib/mittsu/opengl/shader/chunks/envmap_vertex.glsl +17 -0
  51. data/lib/mittsu/opengl/shader/chunks/fog_fragment.glsl +26 -0
  52. data/lib/mittsu/opengl/shader/chunks/fog_pars_fragment.glsl +15 -0
  53. data/lib/mittsu/opengl/shader/chunks/lightmap_fragment.glsl +5 -0
  54. data/lib/mittsu/opengl/shader/chunks/lightmap_pars_fragment.glsl +6 -0
  55. data/lib/mittsu/opengl/shader/chunks/lightmap_pars_vertex.glsl +5 -0
  56. data/lib/mittsu/opengl/shader/chunks/lightmap_vertex.glsl +5 -0
  57. data/lib/mittsu/opengl/shader/chunks/lights_lambert_pars_vertex.glsl +43 -0
  58. data/lib/mittsu/opengl/shader/chunks/lights_lambert_vertex.glsl +196 -0
  59. data/lib/mittsu/opengl/shader/chunks/lights_phong_fragment.glsl +243 -0
  60. data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_fragment.glsl +58 -0
  61. data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_vertex.glsl +5 -0
  62. data/lib/mittsu/opengl/shader/chunks/lights_phong_vertex.glsl +5 -0
  63. data/lib/mittsu/opengl/shader/chunks/linear_to_gamma_fragment.glsl +2 -0
  64. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_fragment.glsl +5 -0
  65. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_fragment.glsl +12 -0
  66. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_vertex.glsl +11 -0
  67. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_vertex.glsl +15 -0
  68. data/lib/mittsu/opengl/shader/chunks/map_fragment.glsl +9 -0
  69. data/lib/mittsu/opengl/shader/chunks/map_pars_fragment.glsl +11 -0
  70. data/lib/mittsu/opengl/shader/chunks/map_pars_vertex.glsl +6 -0
  71. data/lib/mittsu/opengl/shader/chunks/map_particle_fragment.glsl +5 -0
  72. data/lib/mittsu/opengl/shader/chunks/map_particle_pars_fragment.glsl +6 -0
  73. data/lib/mittsu/opengl/shader/chunks/map_vertex.glsl +5 -0
  74. data/lib/mittsu/opengl/shader/chunks/morphnormal_vertex.glsl +12 -0
  75. data/lib/mittsu/opengl/shader/chunks/morphtarget_pars_vertex.glsl +13 -0
  76. data/lib/mittsu/opengl/shader/chunks/morphtarget_vertex.glsl +20 -0
  77. data/lib/mittsu/opengl/shader/chunks/normalmap_pars_fragment.glsl +27 -0
  78. data/lib/mittsu/opengl/shader/chunks/shadowmap_fragment.glsl +216 -0
  79. data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_fragment.glsl +19 -0
  80. data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_vertex.glsl +6 -0
  81. data/lib/mittsu/opengl/shader/chunks/shadowmap_vertex.glsl +9 -0
  82. data/lib/mittsu/opengl/shader/chunks/skinbase_vertex.glsl +8 -0
  83. data/lib/mittsu/opengl/shader/chunks/skinning_pars_vertex.glsl +47 -0
  84. data/lib/mittsu/opengl/shader/chunks/skinning_vertex.glsl +20 -0
  85. data/lib/mittsu/opengl/shader/chunks/skinnormal_vertex.glsl +20 -0
  86. data/lib/mittsu/opengl/shader/chunks/specularmap_fragment.glsl +12 -0
  87. data/lib/mittsu/opengl/shader/chunks/specularmap_pars_fragment.glsl +5 -0
  88. data/lib/mittsu/opengl/shader/chunks/worldpos_vertex.glsl +17 -0
  89. data/lib/mittsu/opengl/shader/lib/basic/basic_fragment.rbsl +37 -0
  90. data/lib/mittsu/opengl/shader/lib/basic/basic_uniforms.rbslu +3 -0
  91. data/lib/mittsu/opengl/shader/lib/basic/basic_vertex.rbsl +33 -0
  92. data/lib/mittsu/opengl/shader/lib/cube/cube_fragment.rbsl +12 -0
  93. data/lib/mittsu/opengl/shader/lib/cube/cube_uniforms.rbslu +2 -0
  94. data/lib/mittsu/opengl/shader/lib/cube/cube_vertex.rbsl +12 -0
  95. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_fragment.rbsl +26 -0
  96. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
  97. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_vertex.rbsl +12 -0
  98. data/lib/mittsu/opengl/shader/lib/lambert/lambert_fragment.rbsl +56 -0
  99. data/lib/mittsu/opengl/shader/lib/lambert/lambert_uniforms.rbslu +7 -0
  100. data/lib/mittsu/opengl/shader/lib/lambert/lambert_vertex.rbsl +37 -0
  101. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_fragment.rbsl +27 -0
  102. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_uniforms.rbslu +2 -0
  103. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_vertex.rbsl +25 -0
  104. data/lib/mittsu/opengl/shader/lib/phong/phong_fragment.rbsl +45 -0
  105. data/lib/mittsu/opengl/shader/lib/phong/phong_uniforms.rbslu +11 -0
  106. data/lib/mittsu/opengl/shader/lib/phong/phong_vertex.rbsl +43 -0
  107. data/lib/mittsu/opengl/shader/lib.rb +45 -0
  108. data/lib/mittsu/opengl/shader/rbsl_loader.rb +168 -0
  109. data/lib/mittsu/opengl/shader/templates/fragment.glsl.erb +105 -0
  110. data/lib/mittsu/opengl/shader/templates/vertex.glsl.erb +143 -0
  111. data/lib/mittsu/opengl/shader/uniforms_lib.rb +86 -0
  112. data/lib/mittsu/opengl/shader/uniforms_utils.rb +31 -0
  113. data/lib/mittsu/opengl/shader.rb +56 -0
  114. data/lib/mittsu/opengl/state.rb +205 -0
  115. data/lib/mittsu/opengl/version.rb +5 -0
  116. data/lib/mittsu/opengl.rb +2 -0
  117. data/lib/mittsu/opengl_implementation/core/buffer_geometry.rb +11 -0
  118. data/lib/mittsu/opengl_implementation/core/geometry.rb +346 -0
  119. data/lib/mittsu/opengl_implementation/core/object_3d.rb +134 -0
  120. data/lib/mittsu/opengl_implementation/lights/ambient_light.rb +26 -0
  121. data/lib/mittsu/opengl_implementation/lights/directional_light.rb +35 -0
  122. data/lib/mittsu/opengl_implementation/lights/hemisphere_light.rb +39 -0
  123. data/lib/mittsu/opengl_implementation/lights/light.rb +55 -0
  124. data/lib/mittsu/opengl_implementation/lights/point_light.rb +36 -0
  125. data/lib/mittsu/opengl_implementation/lights/spot_light.rb +47 -0
  126. data/lib/mittsu/opengl_implementation/materials/line_basic_material.rb +16 -0
  127. data/lib/mittsu/opengl_implementation/materials/material.rb +274 -0
  128. data/lib/mittsu/opengl_implementation/materials/mesh_basic_material.rb +21 -0
  129. data/lib/mittsu/opengl_implementation/materials/mesh_lambert_material.rb +33 -0
  130. data/lib/mittsu/opengl_implementation/materials/mesh_phong_material.rb +44 -0
  131. data/lib/mittsu/opengl_implementation/materials/point_cloud_material.rb +27 -0
  132. data/lib/mittsu/opengl_implementation/materials/shader_material.rb +11 -0
  133. data/lib/mittsu/opengl_implementation/objects/group.rb +9 -0
  134. data/lib/mittsu/opengl_implementation/objects/line.rb +45 -0
  135. data/lib/mittsu/opengl_implementation/objects/mesh.rb +70 -0
  136. data/lib/mittsu/opengl_implementation/objects/point_cloud.rb +39 -0
  137. data/lib/mittsu/opengl_implementation/objects/sprite.rb +12 -0
  138. data/lib/mittsu/opengl_implementation/scenes/scene.rb +9 -0
  139. data/lib/mittsu/opengl_implementation/textures/compressed_texture.rb +20 -0
  140. data/lib/mittsu/opengl_implementation/textures/cube_texture.rb +77 -0
  141. data/lib/mittsu/opengl_implementation/textures/data_texture.rb +21 -0
  142. data/lib/mittsu/opengl_implementation/textures/render_target.rb +124 -0
  143. data/lib/mittsu/opengl_implementation/textures/texture.rb +107 -0
  144. data/mittsu-opengl.gemspec +36 -0
  145. metadata +314 -0
@@ -0,0 +1,216 @@
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
+ <% parameters[:max_shadows].times do |i| %>
22
+ vec3 shadowCoord = vShadowCoord[ <%= i %> ].xyz / vShadowCoord[ <%= i %> ].w;
23
+
24
+ // if ( something && something ) breaks ATI OpenGL shader compiler
25
+ // if ( all( something, something ) ) using this instead
26
+
27
+ bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
28
+ bool inFrustum = all( inFrustumVec );
29
+
30
+ // don't shadow pixels outside of light frustum
31
+ // use just first frustum (for cascades)
32
+ // don't shadow pixels behind far plane of light frustum
33
+
34
+ #ifdef SHADOWMAP_CASCADE
35
+
36
+ inFrustumCount += int( inFrustum );
37
+ bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );
38
+
39
+ #else
40
+
41
+ bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
42
+
43
+ #endif
44
+
45
+ bool frustumTest = all( frustumTestVec );
46
+
47
+ if ( frustumTest ) {
48
+
49
+ shadowCoord.z += shadowBias[ <%= i %> ];
50
+
51
+ #if defined( SHADOWMAP_TYPE_PCF )
52
+
53
+ // Percentage-close filtering
54
+ // (9 pixel kernel)
55
+ // http://fabiensanglard.net/shadowmappingPCF/
56
+
57
+ float shadow = 0.0;
58
+
59
+ /*
60
+ // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
61
+ // must enroll loop manually
62
+
63
+ for ( float y = -1.25; y <= 1.25; y += 1.25 )
64
+ for ( float x = -1.25; x <= 1.25; x += 1.25 ) {
65
+
66
+ vec4 rgbaDepth = texture( shadowMap[ <%= i %> ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );
67
+
68
+ // doesn't seem to produce any noticeable visual difference compared to simple texture lookup
69
+ //vec4 rgbaDepth = textureProj( shadowMap[ <%= i %> ], vec4( vShadowCoord[ <%= i %> ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ <%= i %> ].w ) );
70
+
71
+ float fDepth = unpackDepth( rgbaDepth );
72
+
73
+ if ( fDepth < shadowCoord.z )
74
+ shadow += 1.0;
75
+
76
+ }
77
+
78
+ shadow /= 9.0;
79
+
80
+ */
81
+
82
+ const float shadowDelta = 1.0 / 9.0;
83
+
84
+ float xPixelOffset = 1.0 / shadowMapSize[ <%= i %> ].x;
85
+ float yPixelOffset = 1.0 / shadowMapSize[ <%= i %> ].y;
86
+
87
+ float dx0 = -1.25 * xPixelOffset;
88
+ float dy0 = -1.25 * yPixelOffset;
89
+ float dx1 = 1.25 * xPixelOffset;
90
+ float dy1 = 1.25 * yPixelOffset;
91
+
92
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
93
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
94
+
95
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
96
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
97
+
98
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
99
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
100
+
101
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
102
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
103
+
104
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy ) );
105
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
106
+
107
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
108
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
109
+
110
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
111
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
112
+
113
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
114
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
115
+
116
+ fDepth = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
117
+ if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
118
+
119
+ shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ <%= i %> ] * shadow ) );
120
+
121
+ #elif defined( SHADOWMAP_TYPE_PCF_SOFT )
122
+
123
+ // Percentage-close filtering
124
+ // (9 pixel kernel)
125
+ // http://fabiensanglard.net/shadowmappingPCF/
126
+
127
+ float shadow = 0.0;
128
+
129
+ float xPixelOffset = 1.0 / shadowMapSize[ <%= i %> ].x;
130
+ float yPixelOffset = 1.0 / shadowMapSize[ <%= i %> ].y;
131
+
132
+ float dx0 = -1.0 * xPixelOffset;
133
+ float dy0 = -1.0 * yPixelOffset;
134
+ float dx1 = 1.0 * xPixelOffset;
135
+ float dy1 = 1.0 * yPixelOffset;
136
+
137
+ mat3 shadowKernel;
138
+ mat3 depthKernel;
139
+
140
+ depthKernel[0][0] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
141
+ depthKernel[0][1] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
142
+ depthKernel[0][2] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
143
+ depthKernel[1][0] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
144
+ depthKernel[1][1] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy ) );
145
+ depthKernel[1][2] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
146
+ depthKernel[2][0] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
147
+ depthKernel[2][1] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
148
+ depthKernel[2][2] = unpackDepth( texture( shadowMap[ <%= i %> ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
149
+
150
+ vec3 shadowZ = vec3( shadowCoord.z );
151
+ shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));
152
+ shadowKernel[0] *= vec3(0.25);
153
+
154
+ shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));
155
+ shadowKernel[1] *= vec3(0.25);
156
+
157
+ shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));
158
+ shadowKernel[2] *= vec3(0.25);
159
+
160
+ vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[<%= i %>].xy );
161
+
162
+ shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
163
+ shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
164
+
165
+ vec4 shadowValues;
166
+ shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
167
+ shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
168
+ shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
169
+ shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
170
+
171
+ shadow = dot( shadowValues, vec4( 1.0 ) );
172
+
173
+ shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ <%= i %> ] * shadow ) );
174
+
175
+ #else
176
+
177
+ vec4 rgbaDepth = texture( shadowMap[ <%= i %> ], shadowCoord.xy );
178
+ float fDepth = unpackDepth( rgbaDepth );
179
+
180
+ if ( fDepth < shadowCoord.z )
181
+
182
+ // spot with multiple shadows is darker
183
+
184
+ shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ <%= i %> ] );
185
+
186
+ // spot with multiple shadows has the same color as single shadow spot
187
+
188
+ // shadowColor = min( shadowColor, vec3( shadowDarkness[ <%= i %> ] ) );
189
+
190
+ #endif
191
+
192
+ }
193
+
194
+
195
+ #ifdef SHADOWMAP_DEBUG
196
+
197
+ #ifdef SHADOWMAP_CASCADE
198
+
199
+ if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ <%= i %> ];
200
+
201
+ #else
202
+
203
+ if ( inFrustum ) outgoingLight *= frustumColors[ <%= i %> ];
204
+
205
+ #endif
206
+
207
+ #endif
208
+
209
+ <% end %>
210
+
211
+ // NOTE: I am unsure if this is correct in linear space. -bhouston, Dec 29, 2014
212
+ shadowColor = inputToLinear( shadowColor );
213
+
214
+ outgoingLight = outgoingLight * shadowColor;
215
+
216
+ #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,6 @@
1
+ #ifdef USE_SHADOWMAP
2
+
3
+ out vec4 vShadowCoord[ MAX_SHADOWS ];
4
+ uniform mat4 shadowMatrix[ MAX_SHADOWS ];
5
+
6
+ #endif
@@ -0,0 +1,9 @@
1
+ #ifdef USE_SHADOWMAP
2
+
3
+ for( int i = 0; i < MAX_SHADOWS; i ++ ) {
4
+
5
+ vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;
6
+
7
+ }
8
+
9
+ #endif
@@ -0,0 +1,8 @@
1
+ #ifdef USE_SKINNING
2
+
3
+ mat4 boneMatX = getBoneMatrix( skinIndex.x );
4
+ mat4 boneMatY = getBoneMatrix( skinIndex.y );
5
+ mat4 boneMatZ = getBoneMatrix( skinIndex.z );
6
+ mat4 boneMatW = getBoneMatrix( skinIndex.w );
7
+
8
+ #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,12 @@
1
+ float specularStrength;
2
+
3
+ #ifdef USE_SPECULARMAP
4
+
5
+ vec4 texelSpecular = texture( specularMap, vUv );
6
+ specularStrength = texelSpecular.r;
7
+
8
+ #else
9
+
10
+ specularStrength = 1.0;
11
+
12
+ #endif
@@ -0,0 +1,5 @@
1
+ #ifdef USE_SPECULARMAP
2
+
3
+ uniform sampler2D specularMap;
4
+
5
+ #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,37 @@
1
+ uniform vec3 diffuse;
2
+ uniform float opacity;
3
+
4
+ #include common
5
+ #include color_pars_fragment
6
+ #include map_pars_fragment
7
+ #include alphamap_pars_fragment
8
+ #include lightmap_pars_fragment
9
+ #include envmap_pars_fragment
10
+ #include fog_pars_fragment
11
+ #include shadowmap_pars_fragment
12
+ #include specularmap_pars_fragment
13
+ #include logdepthbuf_pars_fragment
14
+
15
+ void main() {
16
+ vec3 outgoingLight = vec3( 0.0 ); // outgoing light does not have an alpha, the surface does
17
+ vec4 diffuseColor = vec4( diffuse, opacity );
18
+
19
+ #include logdepthbuf_fragment
20
+ #include map_fragment
21
+ #include color_fragment
22
+ #include alphamap_fragment
23
+ #include alphatest_fragment
24
+ #include specularmap_fragment
25
+
26
+ outgoingLight = diffuseColor.rgb; // simple shader
27
+
28
+ #include lightmap_fragment // TODO: Light map on an otherwise unlit surface doesn't make sense.
29
+ #include envmap_fragment
30
+ #include shadowmap_fragment // TODO: Shadows on an otherwise unlit surface doesn't make sense.
31
+
32
+ #include linear_to_gamma_fragment
33
+
34
+ #include fog_fragment
35
+
36
+ fragColor = vec4( outgoingLight, diffuseColor.a ); // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
37
+ }
@@ -0,0 +1,3 @@
1
+ #include common
2
+ #include fog
3
+ #include shadow_map
@@ -0,0 +1,33 @@
1
+ #include common
2
+ #include map_pars_vertex
3
+ #include lightmap_pars_vertex
4
+ #include envmap_pars_vertex
5
+ #include color_pars_vertex
6
+ #include morphtarget_pars_vertex
7
+ #include skinning_pars_vertex
8
+ #include shadowmap_pars_vertex
9
+ #include logdepthbuf_pars_vertex
10
+
11
+ void main() {
12
+ #include map_vertex
13
+ #include lightmap_vertex
14
+ #include color_vertex
15
+ #include skinbase_vertex
16
+
17
+ #ifdef USE_ENVMAP
18
+
19
+ #include morphnormal_vertex
20
+ #include skinnormal_vertex
21
+ #include defaultnormal_vertex
22
+
23
+ #endif
24
+
25
+ #include morphtarget_vertex
26
+ #include skinning_vertex
27
+ #include default_vertex
28
+ #include logdepthbuf_vertex
29
+
30
+ #include worldpos_vertex
31
+ #include envmap_vertex
32
+ #include shadowmap_vertex
33
+ }
@@ -0,0 +1,12 @@
1
+ uniform samplerCube tCube;
2
+ uniform float tFlip;
3
+
4
+ in vec3 vWorldPosition;
5
+
6
+ #include common
7
+ #include logdepthbuf_pars_fragment
8
+
9
+ void main() {
10
+ fragColor = texture( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );
11
+ #include logdepthbuf_fragment
12
+ }
@@ -0,0 +1,2 @@
1
+ uniform texture tCube;
2
+ uniform float tFlip = -1.0;
@@ -0,0 +1,12 @@
1
+ out vec3 vWorldPosition;
2
+
3
+ #include common
4
+
5
+ #include logdepthbuf_pars_vertex
6
+
7
+ void main() {
8
+ vWorldPosition = transformDirection( position, modelMatrix );
9
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
10
+
11
+ #include logdepthbuf_vertex
12
+ }
@@ -0,0 +1,26 @@
1
+ #include common
2
+ #include logdepthbuf_pars_fragment
3
+
4
+ vec4 pack_depth( const in float depth ) {
5
+ const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
6
+ const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
7
+ vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );
8
+ // vec4 res = fract( depth * bit_shift );
9
+ res -= res.xxyz * bit_mask;
10
+ return res;
11
+ }
12
+
13
+ void main() {
14
+ #include logdepthbuf_fragment
15
+
16
+ #ifdef USE_LOGDEPTHBUF_EXT
17
+ fragColor = pack_depth( gl_FragDepthEXT );
18
+ #else
19
+ fragColor = pack_depth( gl_FragCoord.z );
20
+ #endif
21
+
22
+ // fragColor = pack_depth( gl_FragCoord.z / gl_FragCoord.w );
23
+ // float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );
24
+ // fragColor = pack_depth( z );
25
+ // fragColor = vec4( z, z, z, 1.0 );
26
+ }
@@ -0,0 +1,12 @@
1
+ #include common
2
+ #include morphtarget_pars_vertex
3
+ #include skinning_pars_vertex
4
+ #include logdepthbuf_pars_vertex
5
+
6
+ void main() {
7
+ #include skinbase_vertex
8
+ #include morphtarget_vertex
9
+ #include skinning_vertex
10
+ #include default_vertex
11
+ #include logdepthbuf_vertex
12
+ }
@@ -0,0 +1,56 @@
1
+ uniform vec3 diffuse;
2
+ uniform vec3 emissive;
3
+ uniform float opacity;
4
+
5
+ in vec3 vLightFront;
6
+
7
+ #ifdef DOUBLE_SIDED
8
+ in vec3 vLightBack;
9
+ #endif
10
+
11
+ #include common
12
+ #include color_pars_fragment
13
+ #include map_pars_fragment
14
+ #include alphamap_pars_fragment
15
+ #include lightmap_pars_fragment
16
+ #include envmap_pars_fragment
17
+ #include fog_pars_fragment
18
+ #include shadowmap_pars_fragment
19
+ #include specularmap_pars_fragment
20
+ #include logdepthbuf_pars_fragment
21
+
22
+ void main() {
23
+ vec3 outgoingLight = vec3( 0.0 ); // outgoing light does not have an alpha, the surface does
24
+ vec4 diffuseColor = vec4( diffuse, opacity );
25
+
26
+ #include logdepthbuf_fragment
27
+ #include map_fragment
28
+ #include color_fragment
29
+ #include alphamap_fragment
30
+ #include alphatest_fragment
31
+ #include specularmap_fragment
32
+
33
+ #ifdef DOUBLE_SIDED
34
+ float isFront = float( gl_FrontFacing );
35
+ fragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;
36
+
37
+ if ( gl_FrontFacing )
38
+ outgoingLight += diffuseColor.rgb * vLightFront + emissive;
39
+ else
40
+ outgoingLight += diffuseColor.rgb * vLightBack + emissive;
41
+ #else
42
+ outgoingLight += diffuseColor.rgb * vLightFront + emissive;
43
+ #endif
44
+
45
+ #include lightmap_fragment
46
+ #include envmap_fragment
47
+ #include shadowmap_fragment
48
+
49
+ #include linear_to_gamma_fragment
50
+
51
+ #include fog_fragment
52
+
53
+ // fragColor = vec4( outgoingLight, diffuseColor.a ); // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
54
+
55
+ fragColor = vec4(outgoingLight, diffuseColor.a);
56
+ }
@@ -0,0 +1,7 @@
1
+ #include common
2
+ #include fog
3
+ #include lights
4
+ #include shadow_map
5
+
6
+ uniform color emissive = color(0.0, 0.0, 0.0);
7
+ uniform vec3 wrapRGB = vec3(1.0, 1.0, 1.0);
@@ -0,0 +1,37 @@
1
+ #define LAMBERT
2
+ out vec3 vLightFront;
3
+ #ifdef DOUBLE_SIDED
4
+ out vec3 vLightBack;
5
+ #endif
6
+
7
+ #include common
8
+ #include map_pars_vertex
9
+ #include lightmap_pars_vertex
10
+ #include envmap_pars_vertex
11
+ #include lights_lambert_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
+ #include morphtarget_vertex
29
+ #include skinning_vertex
30
+ #include default_vertex
31
+ #include logdepthbuf_vertex
32
+
33
+ #include worldpos_vertex
34
+ #include envmap_vertex
35
+ #include lights_lambert_vertex
36
+ #include shadowmap_vertex
37
+ }
@@ -0,0 +1,27 @@
1
+ uniform vec3 psColor;
2
+ uniform float opacity;
3
+
4
+ #include common
5
+ #include color_pars_fragment
6
+ #include map_particle_pars_fragment
7
+ #include fog_pars_fragment
8
+ #include shadowmap_pars_fragment
9
+ #include logdepthbuf_pars_fragment
10
+
11
+ void main() {
12
+ vec3 outgoingLight = vec3( 0.0 ); // outgoing light does not have an alpha, the surface does
13
+ vec4 diffuseColor = vec4( psColor, opacity );
14
+
15
+ #include logdepthbuf_fragment
16
+ #include map_particle_fragment
17
+ #include color_fragment
18
+ #include alphatest_fragment
19
+
20
+ outgoingLight = diffuseColor.rgb; // simple shader
21
+
22
+ #include shadowmap_fragment
23
+ #include fog_fragment
24
+
25
+
26
+ fragColor = vec4( outgoingLight, diffuseColor.a ); // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
27
+ }
@@ -0,0 +1,2 @@
1
+ #include particle
2
+ #include shadow_map