chorama 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.configs/tsconfig.lib.json +43 -0
  2. package/.configs/tsconfig.website.json +34 -0
  3. package/.github/workflows/static.yml +88 -0
  4. package/.vscode/launch.json +29 -0
  5. package/.vscode/tasks.json +19 -0
  6. package/README.md +127 -0
  7. package/assets/images/disappointed.jpg +0 -0
  8. package/assets/images/skybox/grimmnight_back.png +0 -0
  9. package/assets/images/skybox/grimmnight_bottom.png +0 -0
  10. package/assets/images/skybox/grimmnight_front.png +0 -0
  11. package/assets/images/skybox/grimmnight_left.png +0 -0
  12. package/assets/images/skybox/grimmnight_right.png +0 -0
  13. package/assets/images/skybox/grimmnight_top.png +0 -0
  14. package/assets/images/skybox/miramar_back.png +0 -0
  15. package/assets/images/skybox/miramar_bottom.png +0 -0
  16. package/assets/images/skybox/miramar_front.png +0 -0
  17. package/assets/images/skybox/miramar_left.png +0 -0
  18. package/assets/images/skybox/miramar_right.png +0 -0
  19. package/assets/images/skybox/miramar_top.png +0 -0
  20. package/assets/images/uv.jpg +0 -0
  21. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
  22. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
  23. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
  24. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
  25. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
  26. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
  27. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
  28. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
  29. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
  30. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
  31. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
  32. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
  33. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
  34. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
  35. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
  36. package/assets/models/gltf/flight_helmet/index.bin +0 -0
  37. package/assets/models/gltf/flight_helmet/index.gltf +705 -0
  38. package/assets/models/gltf/object.gltf +23 -0
  39. package/assets/models/gltf/pirate_girl/index.bin +0 -0
  40. package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
  41. package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
  42. package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
  43. package/astro.config.mjs +45 -0
  44. package/content/guide/api-map.md +89 -0
  45. package/content/guide/camera-and-controls.md +98 -0
  46. package/content/guide/first-scene.md +176 -0
  47. package/content/guide/index.md +72 -0
  48. package/content/guide/installation.md +179 -0
  49. package/content/guide/materials-and-lighting.md +138 -0
  50. package/content/guide/plugins-and-render-pipeline.md +124 -0
  51. package/content/guide/render-targets-and-views.md +147 -0
  52. package/content/guide/scene-graph-and-transforms.md +113 -0
  53. package/content/guide/textures-and-assets.md +120 -0
  54. package/content/guide/troubleshooting.md +49 -0
  55. package/env.d.ts +19 -0
  56. package/examples/addons/rendergraph_gui.js +580 -0
  57. package/examples/camera/orthographic.js +120 -0
  58. package/examples/camera/perspective.js +138 -0
  59. package/examples/lights/directional.js +397 -0
  60. package/examples/lights/multiple_spot_lights.js +304 -0
  61. package/examples/lights/point.js +337 -0
  62. package/examples/lights/spot.js +366 -0
  63. package/examples/loader/gltf_material.js +111 -0
  64. package/examples/loader/gltfloader.js +78 -0
  65. package/examples/loader/objloader.js +95 -0
  66. package/examples/material/cullface.js +111 -0
  67. package/examples/material/materials.js +126 -0
  68. package/examples/material/standard/basic.js +164 -0
  69. package/examples/mesh/circle.js +117 -0
  70. package/examples/mesh/cuboid.js +151 -0
  71. package/examples/mesh/cylinder.js +139 -0
  72. package/examples/mesh/geometries.js +108 -0
  73. package/examples/mesh/meshTopology.js +103 -0
  74. package/examples/mesh/plane.js +117 -0
  75. package/examples/mesh/skinning.js +136 -0
  76. package/examples/mesh/uvsphere.js +113 -0
  77. package/examples/other/rotatingCube.js +93 -0
  78. package/examples/other/rotatingSphere.js +96 -0
  79. package/examples/rendertarget/basic_canvas.js +130 -0
  80. package/examples/rendertarget/depth_texture.js +130 -0
  81. package/examples/rendertarget/image_target.js +140 -0
  82. package/examples/rendertarget/multiple_views.js +158 -0
  83. package/examples/rendertarget/render_masks.js +173 -0
  84. package/examples/rendertarget/split_screen.js +123 -0
  85. package/examples/rendertarget/split_view.js +137 -0
  86. package/examples/skybox/skybox.js +111 -0
  87. package/examples/texture/arrays.js +156 -0
  88. package/examples/texture/textureWrap.js +118 -0
  89. package/examples/transform/propagation.js +92 -0
  90. package/package.json +55 -0
  91. package/rollup.config.js +66 -0
  92. package/scripts/stage-chorama.mjs +29 -0
  93. package/src/caches/cache.js +420 -0
  94. package/src/caches/index.js +2 -0
  95. package/src/caches/uniformbuffers.js +104 -0
  96. package/src/cameracontrols/index.js +258 -0
  97. package/src/constants/index.js +3 -0
  98. package/src/constants/mesh.js +197 -0
  99. package/src/constants/others.js +218 -0
  100. package/src/constants/texture.js +183 -0
  101. package/src/core/constants.js +14 -0
  102. package/src/core/extensions.js +42 -0
  103. package/src/core/index.js +7 -0
  104. package/src/core/layouts/index.js +4 -0
  105. package/src/core/layouts/meshvertex.js +60 -0
  106. package/src/core/layouts/uniform.js +21 -0
  107. package/src/core/layouts/uniformbuffer.js +15 -0
  108. package/src/core/layouts/vertexbuffer.js +43 -0
  109. package/src/core/limits.js +247 -0
  110. package/src/core/resources/blendparams.js +89 -0
  111. package/src/core/resources/framebuffer.js +127 -0
  112. package/src/core/resources/gpubuffer.js +32 -0
  113. package/src/core/resources/gpumesh.js +43 -0
  114. package/src/core/resources/gputexture.js +73 -0
  115. package/src/core/resources/index.js +5 -0
  116. package/src/core/shader.js +62 -0
  117. package/src/core/webgl/bindgroup.js +89 -0
  118. package/src/core/webgl/descriptors.js +104 -0
  119. package/src/core/webgl/index.js +5 -0
  120. package/src/core/webgl/renderpassencoder.js +96 -0
  121. package/src/core/webgl/renderpipeline.js +54 -0
  122. package/src/core/webgl/utils.js +371 -0
  123. package/src/core/webgl/webglrenderdevice.js +235 -0
  124. package/src/function.js +358 -0
  125. package/src/index.js +15 -0
  126. package/src/loader/gltf.js +2172 -0
  127. package/src/loader/index.js +3 -0
  128. package/src/loader/loader.js +174 -0
  129. package/src/loader/obj.js +188 -0
  130. package/src/loader/texture.js +85 -0
  131. package/src/loader/utils.js +16 -0
  132. package/src/material/basic.js +75 -0
  133. package/src/material/depth.js +73 -0
  134. package/src/material/index.js +8 -0
  135. package/src/material/lambert.js +73 -0
  136. package/src/material/material.js +106 -0
  137. package/src/material/normal.js +30 -0
  138. package/src/material/phong.js +86 -0
  139. package/src/material/raw.js +52 -0
  140. package/src/material/standard.js +221 -0
  141. package/src/math/index.js +3 -0
  142. package/src/math/transform.js +38 -0
  143. package/src/mesh/attribute/attribute.js +79 -0
  144. package/src/mesh/attribute/index.js +1 -0
  145. package/src/mesh/attributedata/index.js +1 -0
  146. package/src/mesh/attributedata/separate.js +180 -0
  147. package/src/mesh/builders/base.js +41 -0
  148. package/src/mesh/builders/circle.js +63 -0
  149. package/src/mesh/builders/cuboid.js +135 -0
  150. package/src/mesh/builders/cylinder.js +131 -0
  151. package/src/mesh/builders/index.js +7 -0
  152. package/src/mesh/builders/plane.js +73 -0
  153. package/src/mesh/builders/utils.js +20 -0
  154. package/src/mesh/builders/uvsphere.js +80 -0
  155. package/src/mesh/builders/wireframe.js +62 -0
  156. package/src/mesh/index.js +4 -0
  157. package/src/mesh/mesh.js +149 -0
  158. package/src/objects/bone.js +17 -0
  159. package/src/objects/camera/camera.js +56 -0
  160. package/src/objects/camera/index.js +2 -0
  161. package/src/objects/camera/projection.js +203 -0
  162. package/src/objects/debug/index.js +1 -0
  163. package/src/objects/debug/skeleton.js +28 -0
  164. package/src/objects/index.js +7 -0
  165. package/src/objects/light/ambient.js +20 -0
  166. package/src/objects/light/directional.js +29 -0
  167. package/src/objects/light/index.js +5 -0
  168. package/src/objects/light/point.js +32 -0
  169. package/src/objects/light/shadow/index.js +1 -0
  170. package/src/objects/light/shadow/shadow.js +67 -0
  171. package/src/objects/light/spot.js +56 -0
  172. package/src/objects/mesh.js +141 -0
  173. package/src/objects/object3d.js +167 -0
  174. package/src/objects/skybox.js +38 -0
  175. package/src/plugins/camera/camera.js +19 -0
  176. package/src/plugins/camera/index.js +2 -0
  177. package/src/plugins/camera/nodes/cameraview.js +46 -0
  178. package/src/plugins/camera/nodes/index.js +2 -0
  179. package/src/plugins/camera/nodes/opaquepass.js +79 -0
  180. package/src/plugins/index.js +6 -0
  181. package/src/plugins/light/index.js +2 -0
  182. package/src/plugins/light/light.js +23 -0
  183. package/src/plugins/light/nodes/index.js +1 -0
  184. package/src/plugins/light/nodes/light.js +127 -0
  185. package/src/plugins/meshmaterial/index.js +3 -0
  186. package/src/plugins/meshmaterial/meshmaterial.js +381 -0
  187. package/src/plugins/meshmaterial/nodes/index.js +1 -0
  188. package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
  189. package/src/plugins/meshmaterial/resources/index.js +1 -0
  190. package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
  191. package/src/plugins/shadow/index.js +3 -0
  192. package/src/plugins/shadow/nodes/index.js +3 -0
  193. package/src/plugins/shadow/nodes/shadow.js +272 -0
  194. package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
  195. package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
  196. package/src/plugins/shadow/resources/ShadowMap.js +99 -0
  197. package/src/plugins/shadow/resources/index.js +2 -0
  198. package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
  199. package/src/plugins/shadow/shadow.js +31 -0
  200. package/src/plugins/skeletonhelper/index.js +1 -0
  201. package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
  202. package/src/plugins/skybox/index.js +3 -0
  203. package/src/plugins/skybox/nodes/index.js +1 -0
  204. package/src/plugins/skybox/nodes/skybox.js +143 -0
  205. package/src/plugins/skybox/resources/index.js +2 -0
  206. package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
  207. package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
  208. package/src/plugins/skybox/skybox.js +137 -0
  209. package/src/renderer/core/index.js +179 -0
  210. package/src/renderer/graph/index.js +3 -0
  211. package/src/renderer/graph/nodes.js +34 -0
  212. package/src/renderer/graph/rendergraph.js +182 -0
  213. package/src/renderer/index.js +5 -0
  214. package/src/renderer/plugin.js +36 -0
  215. package/src/renderer/renderer.js +179 -0
  216. package/src/renderer/views.js +28 -0
  217. package/src/rendertarget/canvastarget.js +30 -0
  218. package/src/rendertarget/image.js +132 -0
  219. package/src/rendertarget/index.js +3 -0
  220. package/src/rendertarget/rendertarget.js +89 -0
  221. package/src/shader/basicFragment.glsl +30 -0
  222. package/src/shader/basicVertex.glsl +87 -0
  223. package/src/shader/common/color.glsl +7 -0
  224. package/src/shader/common/common.glsl +25 -0
  225. package/src/shader/common/index.js +4 -0
  226. package/src/shader/common/light.glsl +437 -0
  227. package/src/shader/common/math.glsl +12 -0
  228. package/src/shader/debug/index.js +2 -0
  229. package/src/shader/debug/skeletonFragment.glsl +8 -0
  230. package/src/shader/debug/skeletonVertex.glsl +27 -0
  231. package/src/shader/depthFragment.glsl +37 -0
  232. package/src/shader/index.js +11 -0
  233. package/src/shader/lambertFragment.glsl +126 -0
  234. package/src/shader/normalFragment.glsl +25 -0
  235. package/src/shader/phongFragment.glsl +140 -0
  236. package/src/shader/skyboxFragment.glsl +16 -0
  237. package/src/shader/skyboxVertex.glsl +20 -0
  238. package/src/shader/standardFragment.glsl +274 -0
  239. package/src/texture/index.js +2 -0
  240. package/src/texture/sampler.js +111 -0
  241. package/src/texture/texture.js +234 -0
  242. package/src/utils/index.js +115 -0
  243. package/tsconfig.json +11 -0
  244. package/website/config/index.ts +1 -0
  245. package/website/config/navigation.ts +53 -0
  246. package/website/content.config.ts +92 -0
  247. package/website/layouts/DocLayout.astro +501 -0
  248. package/website/layouts/Example.astro +91 -0
  249. package/website/pages/examples/[...slug].astro +77 -0
  250. package/website/pages/examples/index.astro +98 -0
  251. package/website/pages/examples/samples/[...slug].astro +17 -0
  252. package/website/pages/guide/[slug].astro +30 -0
  253. package/website/pages/guide/index.astro +21 -0
  254. package/website/pages/index.astro +9 -0
  255. package/website/plugins/remark-link-base.js +23 -0
  256. package/website/utils/url.ts +30 -0
@@ -0,0 +1,87 @@
1
+ precision mediump float;
2
+
3
+ #include <common>
4
+
5
+ uniform CameraBlock {
6
+ Camera camera;
7
+ };
8
+
9
+ uniform mat4 model;
10
+ #ifdef SKINNED
11
+ uniform sampler2D bone_transforms;
12
+ #endif
13
+
14
+ in vec3 position;
15
+ in vec2 uv;
16
+ in vec3 normal;
17
+ #ifdef VERTEX_TANGENTS
18
+ in vec3 tangent;
19
+ #endif
20
+ #ifdef SKINNED
21
+ in uvec4 joint_index;
22
+ in vec4 joint_weight;
23
+ #endif
24
+
25
+ out vec3 v_position;
26
+ #ifdef VERTEX_UVS
27
+ out vec2 v_uv;
28
+ #endif
29
+ #ifdef VERTEX_NORMALS
30
+ out vec3 v_normal;
31
+ #endif
32
+ #ifdef VERTEX_TANGENTS
33
+ out vec3 v_tangent;
34
+ #endif
35
+ out vec3 cam_direction;
36
+
37
+ void main(){
38
+ #ifdef SKINNED
39
+ mat4 boneMat0 = get_value_from_texture(joint_index.x, bone_transforms);
40
+ mat4 boneMat1 = get_value_from_texture(joint_index.y, bone_transforms);
41
+ mat4 boneMat2 = get_value_from_texture(joint_index.z, bone_transforms);
42
+ mat4 boneMat3 = get_value_from_texture(joint_index.w, bone_transforms);
43
+
44
+ vec4 skeleton_space_position = vec4(position, 1.0);
45
+ vec4 skinned_position =
46
+ (boneMat0 * skeleton_space_position) * joint_weight.x +
47
+ (boneMat1 * skeleton_space_position) * joint_weight.y +
48
+ (boneMat2 * skeleton_space_position) * joint_weight.z +
49
+ (boneMat3 * skeleton_space_position) * joint_weight.w;
50
+ mat3 normal_matrix = mat3(model);
51
+ vec3 world_space_position = (model * skinned_position).xyz;
52
+ #else
53
+ vec3 world_space_position = (model * vec4(position,1.0)).xyz;
54
+ mat3 normal_matrix = mat3(model);
55
+ #endif
56
+
57
+ v_position = world_space_position;
58
+ #ifdef VERTEX_UVS
59
+ v_uv = uv;
60
+ #endif
61
+ #ifdef VERTEX_NORMALS
62
+ #ifdef SKINNED
63
+ vec3 skeleton_space_normal =
64
+ (mat3(boneMat0) * normal) * joint_weight.x +
65
+ (mat3(boneMat1) * normal) * joint_weight.y +
66
+ (mat3(boneMat2) * normal) * joint_weight.z +
67
+ (mat3(boneMat3) * normal) * joint_weight.w;
68
+ v_normal = normal_matrix * skeleton_space_normal;
69
+ #else
70
+ v_normal = normal_matrix * normal;
71
+ #endif
72
+ #endif
73
+ #ifdef VERTEX_TANGENTS
74
+ #ifdef SKINNED
75
+ vec3 skeleton_space_tangent =
76
+ (mat3(boneMat0) * tangent) * joint_weight.x +
77
+ (mat3(boneMat1) * tangent) * joint_weight.y +
78
+ (mat3(boneMat2) * tangent) * joint_weight.z +
79
+ (mat3(boneMat3) * tangent) * joint_weight.w;
80
+ v_tangent = normal_matrix * skeleton_space_tangent;
81
+ #else
82
+ v_tangent = normal_matrix * tangent;
83
+ #endif
84
+ #endif
85
+ cam_direction = camera.cam_position - world_space_position;
86
+ gl_Position = camera.projection * camera.view * vec4(world_space_position, 1.0);
87
+ }
@@ -0,0 +1,7 @@
1
+ vec3 quick_sRGB_to_linear(vec3 color) {
2
+ return pow(color, vec3(2.2));
3
+ }
4
+
5
+ vec3 quick_linear_to_sRGB(vec3 color) {
6
+ return pow(color, 1.0 / vec3(2.2));
7
+ }
@@ -0,0 +1,25 @@
1
+ struct Camera {
2
+ mat4 view;
3
+ mat4 projection;
4
+ vec3 cam_position;
5
+ float near;
6
+ float far;
7
+ };
8
+
9
+ // functions
10
+ vec3 tint(vec3 tex_color, vec3 tint_color){
11
+ return tex_color * tint_color;
12
+ }
13
+
14
+ mat4 get_value_from_texture(uint index, sampler2D transforms) {
15
+ uint size = uint(textureSize( transforms, 0 ).x);
16
+ uint stride = index * uint(4);
17
+ uint x = stride % size;
18
+ uint y = stride / size;
19
+ vec4 column1 = texelFetch( transforms, ivec2( x, y ), 0 );
20
+ vec4 column2 = texelFetch( transforms, ivec2( x + uint(1), y ), 0 );
21
+ vec4 column3 = texelFetch( transforms, ivec2( x + uint(2), y ), 0 );
22
+ vec4 column4 = texelFetch( transforms, ivec2( x + uint(3), y ), 0 );
23
+
24
+ return mat4( column1, column2, column3, column4 );
25
+ }
@@ -0,0 +1,4 @@
1
+ export { default as colorShaderLib } from './color.glsl'
2
+ export { default as commonShaderLib } from './common.glsl'
3
+ export { default as lightShaderLib } from './light.glsl'
4
+ export { default as mathShaderLib } from './math.glsl'
@@ -0,0 +1,437 @@
1
+ struct DirectionalLight {
2
+ vec4 color;
3
+ vec3 direction;
4
+ float intensity;
5
+ int shadow_index;
6
+ };
7
+
8
+ struct AmbientLight {
9
+ float intensity;
10
+ vec4 color;
11
+ };
12
+
13
+ struct PointLight {
14
+ vec4 color;
15
+ vec3 position;
16
+ float intensity;
17
+ float radius;
18
+ float decay;
19
+ int shadow_index;
20
+ };
21
+
22
+ struct SpotLight {
23
+ vec4 color;
24
+ vec3 position;
25
+ int shadow_index;
26
+ vec3 direction;
27
+ float intensity;
28
+ float distance;
29
+ float decay;
30
+ float innerAngle;
31
+ float outerAngle;
32
+ };
33
+
34
+ struct Shadow {
35
+ mat4 space;
36
+ float bias;
37
+ float normal_bias;
38
+ float layer;
39
+ uint mode;
40
+ float pcf_radius;
41
+ float pcss_search_radius;
42
+ float pcss_penumbra;
43
+ float _padding2;
44
+ };
45
+
46
+ struct DirectionalLights {
47
+ int count;
48
+ DirectionalLight lights[MAX_DIRECTIONAL_LIGHTS];
49
+ };
50
+
51
+ struct PointLights {
52
+ int count;
53
+ PointLight lights[MAX_POINT_LIGHTS];
54
+ };
55
+
56
+ struct SpotLights {
57
+ int count;
58
+ SpotLight lights[MAX_SPOT_LIGHTS];
59
+ };
60
+
61
+ float calculate_brightness(vec3 normal, vec3 dir) {
62
+ return max(dot(normal, dir), 0.0);
63
+ }
64
+
65
+ // https://lisyarus.github.io/blog/posts/point-light-attenuation.html
66
+ float attenuate_light_distance(float distance, float max_distance, float falloff){
67
+ float s = distance / max_distance;
68
+
69
+ if (s >= 1.0){
70
+ return 0.0;
71
+ }
72
+
73
+ float s2 = sq(s);
74
+ return sq(1.0 - s2) / (1.0 + falloff * s2);
75
+ }
76
+
77
+ float attenuate_point_light(float distance, float radius, float max_intensity, float falloff){
78
+ float s = distance / radius;
79
+
80
+ if (s >= 1.0){
81
+ return 0.0;
82
+ }
83
+
84
+ float s2 = sq(s);
85
+ return max_intensity * sq(1.0 - s2) / (1.0 + falloff * s2);
86
+ }
87
+
88
+ float attenuate_spot_light(SpotLight light, vec3 direction, float distance){
89
+ float factor = max(dot(light.direction, -direction), 0.0);
90
+
91
+ if(factor > light.outerAngle){
92
+ float cone_attenuation = smoothstep(light.outerAngle, light.innerAngle, factor);
93
+ float distance_attenuation = attenuate_light_distance(distance, light.distance, light.decay);
94
+ return cone_attenuation * distance_attenuation * light.intensity;
95
+ }
96
+ return 0.0;
97
+ }
98
+
99
+ vec3 map_cube_from_array_texture_ndc(vec3 direction) {
100
+ vec3 absolute_direction = abs(direction);
101
+
102
+ if (absolute_direction.x >= absolute_direction.y && absolute_direction.x >= absolute_direction.z) {
103
+ float face = direction.x > 0.0 ? 0.0 : 1.0;
104
+ float inv = 1.0 / absolute_direction.x;
105
+ vec2 uv = vec2(
106
+ direction.x > 0.0 ? -direction.z : direction.z,
107
+ -direction.y
108
+ );
109
+
110
+ return vec3(uv * inv, face);
111
+ } else if (absolute_direction.y >= absolute_direction.x && absolute_direction.y >= absolute_direction.z) {
112
+ float face = direction.y > 0.0 ? 2.0 : 3.0;
113
+ float inv = 1.0 / absolute_direction.y;
114
+ vec2 uv = vec2(
115
+ direction.x,
116
+ direction.y > 0.0 ? direction.z : -direction.z
117
+ );
118
+
119
+ return vec3(uv * inv, face);
120
+ }
121
+
122
+ float face = direction.z > 0.0 ? 4.0 : 5.0;
123
+ float inv = 1.0 / absolute_direction.z;
124
+ vec2 uv = vec2(
125
+ direction.z > 0.0 ? direction.x : -direction.x,
126
+ -direction.y
127
+ );
128
+
129
+ return vec3(uv * inv, face);
130
+ }
131
+
132
+ vec3 map_cube_to_array_texture_direction(float face, vec2 uv) {
133
+ if (face == 0.0) {
134
+ return normalize(vec3(1.0, -uv.y, -uv.x));
135
+ }
136
+
137
+ if (face == 1.0) {
138
+ return normalize(vec3(-1.0, -uv.y, uv.x));
139
+ }
140
+
141
+ if (face == 2.0) {
142
+ return normalize(vec3(uv.x, 1.0, uv.y));
143
+ }
144
+
145
+ if (face == 3.0) {
146
+ return normalize(vec3(uv.x, -1.0, -uv.y));
147
+ }
148
+
149
+ if (face == 4.0) {
150
+ return normalize(vec3(uv.x, -uv.y, 1.0));
151
+ }
152
+
153
+ return normalize(vec3(-uv.x, -uv.y, -1.0));
154
+ }
155
+
156
+ float shadow_compare_2d(
157
+ Shadow shadow,
158
+ sampler2DArray shadow_atlas,
159
+ vec3 shadow_map_postion,
160
+ float current_depth,
161
+ float bias
162
+ ){
163
+ float shadow_map_depth = texture(
164
+ shadow_atlas,
165
+ vec3(shadow_map_postion.xy, shadow.layer)
166
+ ).r;
167
+
168
+ return current_depth - bias > shadow_map_depth ? 0.0 : 1.0;
169
+ }
170
+
171
+ float shadow_compare_cube(
172
+ Shadow shadow,
173
+ sampler2DArray shadow_atlas,
174
+ vec3 direction,
175
+ float current_depth,
176
+ float bias
177
+ ){
178
+ vec3 ndc_uv = map_cube_from_array_texture_ndc(direction);
179
+ vec2 shadow_uv = ndc_uv.xy * 0.5 + 0.5;
180
+ float shadow_map_depth = texture(
181
+ shadow_atlas,
182
+ vec3(shadow_uv.xy, shadow.layer + ndc_uv.z)
183
+ ).r;
184
+ vec2 clip_planes = shadow.space[0].xy;
185
+ float near = clip_planes.x;
186
+ float far = clip_planes.y;
187
+ vec3 norm_direction = normalize(direction);
188
+ float scale = max(abs(norm_direction.x), max(abs(norm_direction.y), abs(norm_direction.z)));
189
+ float view_space_map_depth = linearize_depth(shadow_map_depth, near, far);
190
+ float map_depth = view_space_map_depth / (scale * far);
191
+
192
+ return current_depth - bias > map_depth ? 0.0 : 1.0;
193
+ }
194
+
195
+ float shadow_pcf_2d_radius(
196
+ Shadow shadow,
197
+ sampler2DArray shadow_atlas,
198
+ vec3 shadow_map_postion,
199
+ float current_depth,
200
+ float radius,
201
+ float bias
202
+ ){
203
+ vec2 texel_size = 1.0 / vec2(textureSize(shadow_atlas, 0).xy);
204
+ vec2 pcf_step = texel_size * radius;
205
+ float shadow_sum = 0.0;
206
+
207
+ for (int y = -1; y <= 1; y++) {
208
+ for (int x = -1; x <= 1; x++) {
209
+ vec2 sample_offset = vec2(float(x), float(y)) * pcf_step;
210
+ vec3 sample_position = vec3(shadow_map_postion.xy + sample_offset, shadow_map_postion.z);
211
+ shadow_sum += shadow_compare_2d(shadow, shadow_atlas, sample_position, current_depth, bias);
212
+ }
213
+ }
214
+
215
+ return shadow_sum / 9.0;
216
+ }
217
+
218
+ float shadow_pcf_2d(
219
+ Shadow shadow,
220
+ sampler2DArray shadow_atlas,
221
+ vec3 shadow_map_postion,
222
+ float current_depth,
223
+ float bias
224
+ ){
225
+ return shadow_pcf_2d_radius(
226
+ shadow,
227
+ shadow_atlas,
228
+ shadow_map_postion,
229
+ current_depth,
230
+ shadow.pcf_radius,
231
+ bias
232
+ );
233
+ }
234
+
235
+ float shadow_pcf_cube_radius(
236
+ Shadow shadow,
237
+ sampler2DArray shadow_atlas,
238
+ vec3 direction,
239
+ float current_depth,
240
+ float radius,
241
+ float bias
242
+ ){
243
+ vec3 ndc_uv = map_cube_from_array_texture_ndc(direction);
244
+ vec2 texel_size = 1.0 / vec2(textureSize(shadow_atlas, 0).xy);
245
+ vec2 pcf_step = texel_size * radius;
246
+ float shadow_sum = 0.0;
247
+
248
+ for (int y = -1; y <= 1; y++) {
249
+ for (int x = -1; x <= 1; x++) {
250
+ vec2 sample_offset = vec2(float(x), float(y)) * pcf_step;
251
+ vec2 sample_uv = ndc_uv.xy + sample_offset;
252
+ vec3 sample_direction = map_cube_to_array_texture_direction(ndc_uv.z, sample_uv);
253
+ shadow_sum += shadow_compare_cube(shadow, shadow_atlas, sample_direction, current_depth, bias);
254
+ }
255
+ }
256
+
257
+ return shadow_sum / 9.0;
258
+ }
259
+
260
+ float shadow_pcf_cube(
261
+ Shadow shadow,
262
+ sampler2DArray shadow_atlas,
263
+ vec3 direction,
264
+ float current_depth,
265
+ float bias
266
+ ){
267
+ return shadow_pcf_cube_radius(
268
+ shadow,
269
+ shadow_atlas,
270
+ direction,
271
+ current_depth,
272
+ shadow.pcf_radius,
273
+ bias
274
+ );
275
+ }
276
+
277
+ float shadow_pcss_2d(
278
+ Shadow shadow,
279
+ sampler2DArray shadow_atlas,
280
+ vec3 shadow_map_postion,
281
+ float current_depth,
282
+ float bias
283
+ ){
284
+ vec2 texel_size = 1.0 / vec2(textureSize(shadow_atlas, 0).xy);
285
+ vec2 search_step = texel_size * shadow.pcss_search_radius;
286
+ float blocker_sum = 0.0;
287
+ float blocker_count = 0.0;
288
+
289
+ for (int y = -1; y <= 1; y++) {
290
+ for (int x = -1; x <= 1; x++) {
291
+ vec2 sample_offset = vec2(float(x), float(y)) * search_step;
292
+ float sample_depth = texture(
293
+ shadow_atlas,
294
+ vec3(shadow_map_postion.xy + sample_offset, shadow.layer)
295
+ ).r;
296
+ if (sample_depth < current_depth - bias) {
297
+ blocker_sum += sample_depth;
298
+ blocker_count += 1.0;
299
+ }
300
+ }
301
+ }
302
+
303
+ if (blocker_count == 0.0) {
304
+ return 1.0;
305
+ }
306
+
307
+ float blocker_depth = blocker_sum / blocker_count;
308
+ float penumbra = (current_depth - blocker_depth) / max(blocker_depth, 0.0001);
309
+ float filter_radius = clamp(
310
+ shadow.pcf_radius + penumbra * shadow.pcss_penumbra,
311
+ shadow.pcf_radius,
312
+ shadow.pcf_radius + 12.0
313
+ );
314
+ return shadow_pcf_2d_radius(
315
+ shadow,
316
+ shadow_atlas,
317
+ shadow_map_postion,
318
+ current_depth,
319
+ filter_radius,
320
+ bias
321
+ );
322
+ }
323
+
324
+ float shadow_pcss_cube(
325
+ Shadow shadow,
326
+ sampler2DArray shadow_atlas,
327
+ vec3 direction,
328
+ float current_depth,
329
+ float bias
330
+ ){
331
+ vec3 ndc_uv = map_cube_from_array_texture_ndc(direction);
332
+ vec2 texel_size = 1.0 / vec2(textureSize(shadow_atlas, 0).xy);
333
+ vec2 search_step = texel_size * shadow.pcss_search_radius;
334
+ vec2 clip_planes = shadow.space[0].xy;
335
+ float near = clip_planes.x;
336
+ float far = clip_planes.y;
337
+ float blocker_sum = 0.0;
338
+ float blocker_count = 0.0;
339
+
340
+ for (int y = -1; y <= 1; y++) {
341
+ for (int x = -1; x <= 1; x++) {
342
+ vec2 sample_offset = vec2(float(x), float(y)) * search_step;
343
+ vec2 sample_uv = ndc_uv.xy + sample_offset;
344
+ vec3 sample_direction = map_cube_to_array_texture_direction(ndc_uv.z, sample_uv);
345
+ vec3 sample_ndc = map_cube_from_array_texture_ndc(sample_direction);
346
+ vec2 sample_shadow_uv = sample_ndc.xy * 0.5 + 0.5;
347
+ float shadow_map_depth = texture(
348
+ shadow_atlas,
349
+ vec3(sample_shadow_uv.xy, shadow.layer + sample_ndc.z)
350
+ ).r;
351
+ vec3 norm_direction = normalize(sample_direction);
352
+ float scale = max(abs(norm_direction.x), max(abs(norm_direction.y), abs(norm_direction.z)));
353
+ float view_space_map_depth = linearize_depth(shadow_map_depth, near, far);
354
+ float map_depth = view_space_map_depth / (scale * far);
355
+ if (map_depth < current_depth - bias) {
356
+ blocker_sum += map_depth;
357
+ blocker_count += 1.0;
358
+ }
359
+ }
360
+ }
361
+
362
+ if (blocker_count == 0.0) {
363
+ return 1.0;
364
+ }
365
+
366
+ float blocker_depth = blocker_sum / blocker_count;
367
+ float penumbra = (current_depth - blocker_depth) / max(blocker_depth, 0.0001);
368
+ float filter_radius = clamp(
369
+ shadow.pcf_radius + penumbra * shadow.pcss_penumbra,
370
+ shadow.pcf_radius,
371
+ shadow.pcf_radius + 12.0
372
+ );
373
+ return shadow_pcf_cube_radius(
374
+ shadow,
375
+ shadow_atlas,
376
+ direction,
377
+ current_depth,
378
+ filter_radius,
379
+ bias
380
+ );
381
+ }
382
+
383
+ float shadow_contribution_2d(Shadow shadow, sampler2DArray shadow_atlas, vec3 position, float NdotL){
384
+ vec4 clipped_position = shadow.space * vec4(position, 1.0);
385
+ vec3 ndc_position = clipped_position.xyz / clipped_position.w;
386
+ vec3 shadow_map_postion = ndc_position * 0.5 + 0.5;
387
+
388
+ if(
389
+ shadow_map_postion.x < 0.0 || shadow_map_postion.x > 1.0 ||
390
+ shadow_map_postion.y < 0.0 || shadow_map_postion.y > 1.0
391
+ ){
392
+ return 1.0;
393
+ }
394
+ float current_depth = shadow_map_postion.z;
395
+ float normal_bias = shadow.normal_bias * (1.0 - NdotL);
396
+ float bias = shadow.bias + normal_bias;
397
+
398
+ if (shadow.mode == 0u) {
399
+ return shadow_compare_2d(shadow, shadow_atlas, shadow_map_postion, current_depth, bias);
400
+ }
401
+ if (shadow.mode == 1u) {
402
+ return shadow_pcf_2d(shadow, shadow_atlas, shadow_map_postion, current_depth, bias);
403
+ }
404
+ if (shadow.mode == 2u) {
405
+ return shadow_pcss_2d(shadow, shadow_atlas, shadow_map_postion, current_depth, bias);
406
+ }
407
+ return shadow_pcf_2d(shadow, shadow_atlas, shadow_map_postion, current_depth, bias);
408
+ }
409
+
410
+ float shadow_contribution_cube(Shadow shadow, sampler2DArray shadow_atlas, vec3 position, float NdotL){
411
+ // the clipping planes are encoded in the first column of the space matrix
412
+ vec2 clip_planes = shadow.space[0].xy;
413
+ vec3 light_position = shadow.space[3].xyz;
414
+ vec3 direction = position - light_position;
415
+ float distance = length(direction);
416
+ vec3 norm_distance = direction / distance;
417
+ float near = clip_planes.x;
418
+ float far = clip_planes.y;
419
+ float current_depth = distance / far;
420
+
421
+ vec3 ndc_uv = map_cube_from_array_texture_ndc(direction);
422
+ vec2 shadow_uv = ndc_uv.xy * 0.5 + 0.5;
423
+
424
+ float normal_bias = shadow.normal_bias * (1.0 - NdotL);
425
+ float bias = shadow.bias + normal_bias;
426
+
427
+ if (shadow.mode == 0u) {
428
+ return shadow_compare_cube(shadow, shadow_atlas, direction, current_depth, bias);
429
+ }
430
+ if (shadow.mode == 1u) {
431
+ return shadow_pcf_cube(shadow, shadow_atlas, direction, current_depth, bias);
432
+ }
433
+ if (shadow.mode == 2u) {
434
+ return shadow_pcss_cube(shadow, shadow_atlas, direction, current_depth, bias);
435
+ }
436
+ return shadow_pcf_cube(shadow, shadow_atlas, direction, current_depth, bias);
437
+ }
@@ -0,0 +1,12 @@
1
+ const float PI = 3.14159265359;
2
+
3
+ // functions
4
+ float sq(float x) {
5
+ return x * x;
6
+ }
7
+
8
+ // https://learnopengl.com/Advanced-OpenGL/Depth-testing
9
+ float linearize_depth(float depth, float near, float far){
10
+ float ndc = depth * 2.0 - 1.0;
11
+ return (2.0 * near * far) / (far + near - ndc * (far - near));
12
+ }
@@ -0,0 +1,2 @@
1
+ export { default as skeletonVertex } from './skeletonVertex.glsl'
2
+ export { default as skeletonFragment } from './skeletonFragment.glsl'
@@ -0,0 +1,8 @@
1
+ precision mediump float;
2
+
3
+ in vec3 color;
4
+ out vec4 fragment_color;
5
+
6
+ void main() {
7
+ fragment_color = vec4(color, 1.0);
8
+ }
@@ -0,0 +1,27 @@
1
+ precision mediump float;
2
+
3
+ #include <common>
4
+
5
+ uniform CameraBlock {
6
+ Camera camera;
7
+ };
8
+ uniform sampler2D transforms;
9
+ uniform mat4 model;
10
+ uniform uint parent_index;
11
+ uniform uint child_index;
12
+
13
+ out vec3 color;
14
+
15
+ void main() {
16
+ mat4 parent_matrix = get_value_from_texture(parent_index, transforms);
17
+ mat4 child_matrix = get_value_from_texture(child_index, transforms);
18
+
19
+ vec3 parent_position = parent_matrix[3].xyz;
20
+ vec3 child_position = child_matrix[3].xyz;
21
+
22
+ // Each bone line is made of two vertices.
23
+ vec3 world_position = (gl_VertexID % 2 == 0) ? parent_position : child_position;
24
+
25
+ color = (gl_VertexID % 2 == 0) ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
26
+ gl_Position = camera.projection * camera.view * model * vec4(world_position, 1.0);
27
+ }
@@ -0,0 +1,37 @@
1
+ precision mediump float;
2
+ precision mediump sampler2DArray;
3
+
4
+ #include <math>
5
+ #include <common>
6
+
7
+ struct CameraParams {
8
+ float near;
9
+ float far;
10
+ };
11
+
12
+ #ifdef VERTEX_UVS
13
+ in vec2 v_uv;
14
+ #endif
15
+
16
+ uniform MaterialBlock {
17
+ CameraParams params;
18
+ };
19
+ uniform sampler2D depth_texture;
20
+
21
+ out vec4 fragment_color;
22
+
23
+ void main(){
24
+ #ifdef VERTEX_UVS
25
+ float sample_depth = texture(depth_texture, v_uv).r / 1.0;
26
+ float linear_depth = linearize_depth(sample_depth, params.near, params.far) / params.far;
27
+ float visual_depth = (sample_depth - params.near) / (params.far - params.near);
28
+ fragment_color = vec4(
29
+ linear_depth,
30
+ linear_depth,
31
+ linear_depth,
32
+ 1.0
33
+ );
34
+ #else
35
+ fragment_color = vec4(1.0, 0.0, 0.0, 1.0);
36
+ #endif
37
+ }
@@ -0,0 +1,11 @@
1
+ export * from './common/index.js'
2
+ export * from './debug/index.js'
3
+ export { default as basicVertex } from './basicVertex.glsl'
4
+ export { default as basicFragment } from './basicFragment.glsl'
5
+ export { default as normalFragment } from './normalFragment.glsl'
6
+ export { default as lambertFragment } from './lambertFragment.glsl'
7
+ export { default as phongFragment } from './phongFragment.glsl'
8
+ export { default as standardFragment } from './standardFragment.glsl'
9
+ export { default as skyboxVertex } from './skyboxVertex.glsl'
10
+ export { default as skyboxFragment } from './skyboxFragment.glsl'
11
+ export { default as depthFragment } from './depthFragment.glsl'