@woosh/meep-engine 2.40.1 → 2.42.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 (75) hide show
  1. package/core/collection/HashMap.d.ts +2 -0
  2. package/core/collection/HashMap.js +22 -0
  3. package/core/geom/3d/apply_mat4_transform_to_v3_array.js +2 -4
  4. package/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +5 -0
  5. package/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js +31 -0
  6. package/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +33 -0
  7. package/core/geom/3d/normal/octahedron/encoding.spec.js +29 -0
  8. package/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +28 -0
  9. package/core/geom/3d/topology/struct/BinaryTopology.js +112 -0
  10. package/core/geom/Quaternion.js +14 -0
  11. package/core/math/sign_not_zero.js +8 -0
  12. package/core/parser/simple/SimpleParser.js +3 -86
  13. package/core/parser/simple/readUnsignedInteger.js +66 -0
  14. package/core/parser/simple/skipWhitespace.js +21 -0
  15. package/engine/EngineHarness.js +13 -3
  16. package/engine/asset/AssetDescription.spec.js +27 -0
  17. package/engine/asset/loaders/GLTFAssetLoader.js +5 -3
  18. package/engine/ecs/foliage/ImpostorFoliage.js +4 -0
  19. package/engine/ecs/transform/Transform.js +23 -3
  20. package/engine/graphics/ecs/decal/v2/Decal.d.ts +11 -0
  21. package/engine/graphics/ecs/decal/v2/Decal.js +50 -0
  22. package/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +8 -0
  23. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +213 -0
  24. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +237 -0
  25. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +8 -1
  26. package/engine/graphics/ecs/mesh-v2/build_three_object.js +4 -0
  27. package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +22 -7
  28. package/engine/graphics/filter/ImageFilter.js +2 -1
  29. package/engine/graphics/geometry/MikkT/MikkTSpace.js +466 -305
  30. package/engine/graphics/geometry/MikkT/MikkTSpace.spec.js +7 -1
  31. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeBufferAttributeHash.js +1 -1
  32. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeGeometryEquality.js +2 -2
  33. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeGeometryHash.js +1 -1
  34. package/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +2 -2
  35. package/engine/graphics/impostors/card_cluster/FacePlaneAssignment.js +30 -0
  36. package/engine/graphics/impostors/card_cluster/README.md +13 -0
  37. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +345 -0
  38. package/engine/graphics/impostors/octahedral/ImpostorCaptureType.js +10 -0
  39. package/engine/graphics/impostors/octahedral/ImpostorDescription.js +69 -0
  40. package/engine/graphics/impostors/octahedral/README.md +30 -0
  41. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +45 -0
  42. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere_radius_only.js +37 -0
  43. package/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +117 -0
  44. package/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +20 -0
  45. package/engine/graphics/impostors/octahedral/grid/OctahedralUvEncoder.js +25 -0
  46. package/engine/graphics/impostors/octahedral/grid/UvEncoder.js +21 -0
  47. package/engine/graphics/impostors/octahedral/prototypeBaker.js +237 -0
  48. package/engine/graphics/impostors/octahedral/shader/BakeShaderStandard.js +196 -0
  49. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderStandard.js +306 -0
  50. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +349 -0
  51. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV1.js +74 -0
  52. package/engine/graphics/impostors/octahedral/shader/glsl/common.glsl +206 -0
  53. package/engine/graphics/impostors/octahedral/shader/glsl/v1/common.glsl +209 -0
  54. package/engine/graphics/impostors/octahedral/shader/glsl/v1/flagment.glsl +80 -0
  55. package/engine/graphics/impostors/octahedral/shader/glsl/v1/vertex.glsl +350 -0
  56. package/engine/graphics/micron/convert_three_object_to_micron.js +2 -2
  57. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +2 -2
  58. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  59. package/engine/graphics/particles/node-based/codegen/CodeGenerator.js +1 -1
  60. package/engine/graphics/particles/node-based/nodes/noise/CurlNoiseNode.js +1 -1
  61. package/engine/graphics/render/forward_plus/LightManager.js +1 -1
  62. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +1 -3
  63. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +2 -1
  64. package/engine/graphics/render/forward_plus/model/Decal.js +19 -2
  65. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +32 -10
  66. package/engine/graphics/shaders/ScreenSpaceQuadShader.js +4 -14
  67. package/engine/graphics/shaders/glsl_gen_swizzled_read.js +39 -0
  68. package/engine/graphics/texture/sampler/Sampler2D.js +10 -10
  69. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +117 -11
  70. package/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +66 -0
  71. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +2 -2
  72. package/engine/ui/GUIEngine.js +8 -1
  73. package/package.json +1 -1
  74. package/view/tooltip/gml/parser/readReferenceToken.js +1 -1
  75. package/engine/asset/GameAssetManager.js +0 -137
@@ -0,0 +1,350 @@
1
+ const float aabb_max = 1.0;
2
+
3
+ uniform float uFrames;
4
+ uniform bool uIsFullSphere;
5
+ uniform float uRadius;
6
+ uniform vec3 uOffset;
7
+
8
+ // = object.matrixWorld
9
+ uniform mat4 modelMatrix;
10
+
11
+ // = camera.matrixWorldInverse * object.matrixWorld
12
+ uniform mat4 modelViewMatrix;
13
+
14
+ // = camera.projectionMatrix
15
+ uniform mat4 projectionMatrix;
16
+
17
+ // = camera.matrixWorldInverse
18
+ uniform mat4 viewMatrix;
19
+
20
+ // = inverse transpose of modelViewMatrix
21
+ uniform mat3 normalMatrix;
22
+
23
+ // = camera position in world space
24
+ uniform vec3 cameraPosition;
25
+
26
+ in vec2 uv;
27
+
28
+ out vec2 uv_frame1;
29
+ out vec2 xy_frame1;
30
+ flat out vec2 frame1;
31
+ flat out vec3 frame1_normal;
32
+ out vec2 uv_frame2;
33
+ out vec2 xy_frame2;
34
+ flat out vec2 frame2;
35
+ flat out vec3 frame2_normal;
36
+ out vec2 uv_frame3;
37
+ out vec2 xy_frame3;
38
+ flat out vec2 frame3;
39
+ flat out vec3 frame3_normal;
40
+ out vec4 quad_blend_weights;
41
+
42
+ vec2 VecToSphereOct(vec3 pivotToCamera)
43
+ {
44
+ vec3 octant = sign(pivotToCamera);
45
+
46
+ // |x| + |y| + |z| = 1
47
+ float sum = dot(pivotToCamera, octant);
48
+ vec3 octahedron = pivotToCamera / sum;
49
+
50
+ if (octahedron.y < 0.0){
51
+ vec3 absolute = abs(octahedron);
52
+ octahedron.xz = octant.xz * vec2(1.0 - absolute.z, 1.0 - absolute.x);
53
+ }
54
+ return octahedron.xz;
55
+ }
56
+
57
+ //for hemisphere
58
+ vec2 VecToHemiSphereOct(vec3 vec)
59
+ {
60
+ vec.y = max(vec.y, 0.001);
61
+ vec = normalize(vec);
62
+ vec3 octant = sign(vec);
63
+
64
+ // |x| + |y| + |z| = 1
65
+ float sum = dot(vec, octant);
66
+ vec3 octahedron = vec / sum;
67
+
68
+ return vec2(
69
+ octahedron.x + octahedron.z,
70
+ octahedron.z - octahedron.x
71
+ );
72
+ }
73
+
74
+ vec2 VectorToGrid(vec3 vec)
75
+ {
76
+ if (uIsFullSphere)
77
+ {
78
+ return VecToSphereOct(vec);
79
+ }
80
+ else
81
+ {
82
+ return VecToHemiSphereOct(vec);
83
+ }
84
+ }
85
+ //for sphere
86
+ vec3 OctaSphereEnc(vec2 coord)
87
+ {
88
+ coord = (coord - 0.5) * 2.0;
89
+ vec3 position = vec3(coord.x, 0.0, coord.y);
90
+ vec2 absolute = abs(position.xz);
91
+ position.y = 1.0 - absolute.x - absolute.y;
92
+
93
+ if (position.y < 0.0)
94
+ {
95
+ position.xz = sign(position.xz) * vec2(1.0 - absolute.y, 1.0 - absolute.x);
96
+ }
97
+
98
+ return position;
99
+ }
100
+
101
+ //for hemisphere
102
+ vec3 OctaHemiSphereEnc(vec2 coord)
103
+ {
104
+ //coord = (0, 0.27)
105
+ //pos = -0.27, 0, -0.63
106
+
107
+ vec3 position = vec3(coord.x - coord.y, 0.0, -1.0 + coord.x + coord.y);
108
+ vec2 absolute = abs(position.xz);
109
+ position.y = 1.0 - absolute.x - absolute.y;
110
+ return position;
111
+ }
112
+
113
+ vec3 GridToVector(vec2 coord)
114
+ {
115
+ if (uIsFullSphere)
116
+ {
117
+ return OctaSphereEnc(coord);
118
+ }
119
+ else
120
+ {
121
+ return OctaHemiSphereEnc(coord);
122
+ }
123
+ }
124
+
125
+ vec3 FrameXYToRay(vec2 frame, vec2 frameCountMinusOne)
126
+ {
127
+ //divide frame x y by framecount minus one to get 0-1
128
+ vec2 f = (frame.xy/ frameCountMinusOne);
129
+ //bias and scale to -1 to 1
130
+
131
+ vec3 vec = GridToVector(f);
132
+ vec = normalize(vec);
133
+ return vec;
134
+ }
135
+
136
+ vec3 SpriteProjection(vec3 pivotToCameraRayLocal, vec2 size, vec2 loc_uv)
137
+ {
138
+ vec3 z = normalize(pivotToCameraRayLocal);
139
+ vec3 x, y;
140
+ vec3 up = vec3(0, 1, 0);
141
+ //cross product doesnt work if we look directly from bottom
142
+ if (abs(z.y) > 0.999f)
143
+ {
144
+ up = vec3(0, 0, -1);
145
+ }
146
+ x = normalize(cross(up, z));
147
+ y = normalize(cross(x, z));
148
+
149
+ loc_uv -= vec2(0.5, 0.5);
150
+ vec2 uv = (loc_uv) * 2.0;//-1 to 1
151
+
152
+ vec3 newX = x * uv.x;
153
+ vec3 newY = y * uv.y;
154
+
155
+ vec2 vecSize = size * 0.5;
156
+
157
+ newX *= vecSize.x;
158
+ newY *= vecSize.y;
159
+
160
+ return newX + newY;
161
+ }
162
+
163
+ vec4 quadBlendWieghts(vec2 coords)
164
+ {
165
+ vec4 res;
166
+ /* 0 0 0
167
+ 0 0 0
168
+ 1 0 0 */
169
+ res.x = min(1.0 - coords.x, 1.0 - coords.y);
170
+ /* 1 0 0
171
+ 0 0 0
172
+ 0 0 1 */
173
+ res.y = abs(coords.x - coords.y);
174
+ /* 0 0 1
175
+ 0 0 0
176
+ 0 0 0 */
177
+ res.z = min(coords.x, coords.y);
178
+ /* 0 0 0
179
+ 0 0 1
180
+ 0 1 1 */
181
+ res.w = ceil(coords.x - coords.y);
182
+ //res.xyz /= (res.x + res.y + res.z);
183
+ return res;
184
+ }
185
+
186
+ //this function works well in orthogonal projection. It works okeyish with further distances of perspective projection
187
+ vec2 virtualPlaneUV(vec3 plane_normal, vec3 plane_x, vec3 plane_y, vec3 pivotToCameraRay, vec3 vertexToCameraRay, float size)
188
+ {
189
+ plane_normal = normalize(plane_normal);
190
+ plane_x = normalize(plane_x);
191
+ plane_y = normalize(plane_y);
192
+
193
+ // plane_normal is normalized but pivotToCameraRay & vertexToCameraRay are NOT
194
+ // so what are we doing here ?
195
+ // We are calculating length of pivotToCameraRay projected onto plane_normal
196
+ // so pivotToCameraRay is vector to camera from CENTER OF object
197
+ // we are recalculting this distance taking into account new plane normal
198
+ float projectedNormalRayLength = dot(plane_normal, pivotToCameraRay);
199
+ // tihs is direction is almost the same as origin, but its to individual vertex
200
+ // not sure this is correct for perspective projection
201
+ float projectedVertexRayLength = dot(plane_normal, vertexToCameraRay);
202
+ // basically its length difference betwen center and vertex - "not precise"
203
+ // projectedVertexRayLength is bigger than projectedNormalRayLength when vertex is
204
+ // further than "main front facing billboard"
205
+ // so offsetLength is getting smaller, otherwise is getting bigger
206
+ float offsetLength = projectedNormalRayLength/projectedVertexRayLength;
207
+
208
+ // ok so offsetLength is just a length
209
+ // we want a vector so we multiply it by vertexToCameraRay to get this offset
210
+ // now what are we REALY doing is calculuating distance difference
211
+ // se are SUBSTRACTING pivotToCameraRay vector
212
+ // we would get difference between center of plane and vertex rotated
213
+ vec3 offsetVector = vertexToCameraRay * offsetLength - pivotToCameraRay;
214
+
215
+ // we got the offset of rotated vertex, but we need to offset it from correct plane axis
216
+ // so again we projecting length of intersection (offset of rotated vertex) onto plane_x
217
+ // and plane_y
218
+ vec2 duv = vec2(
219
+ dot(plane_x, offsetVector),
220
+ dot(plane_y, offsetVector)
221
+ );
222
+
223
+ //we are in space -1 to 1
224
+ duv /= 2.0 * size;
225
+ duv += 0.5;
226
+ return duv;
227
+ }
228
+ void calcuateXYbasis(vec3 plane_normal, out vec3 plane_x, out vec3 plane_y)
229
+ {
230
+ vec3 up = vec3(0, 1, 0);
231
+ //cross product doesnt work if we look directly from bottom
232
+ if (abs(plane_normal.y) > 0.999f)
233
+ {
234
+ up = vec3(0, 0, 1);
235
+ }
236
+ plane_x = normalize(cross(plane_normal, up));
237
+ plane_y = normalize(cross(plane_x, plane_normal));
238
+ }
239
+ vec3 projectOnPlaneBasis(vec3 ray, vec3 plane_normal, vec3 plane_x, vec3 plane_y)
240
+ {
241
+ //reproject plane normal onto planeXY basos
242
+ return normalize(vec3(
243
+ dot(plane_x, ray),
244
+ dot(plane_y, ray),
245
+ dot(plane_normal, ray)
246
+ ));
247
+ }
248
+
249
+ void main()
250
+ {
251
+ vec2 framesMinusOne = vec2(uFrames-1.0);
252
+ vec3 cameraPos_WS = cameraPosition;
253
+ vec3 cameraPos_OS = (viewMatrix* vec4(cameraPos_WS, 1.0)).xyz;
254
+
255
+ //radius * 2
256
+ vec2 size = vec2(2.0) * uRadius;
257
+
258
+ mat4 m4 = modelViewMatrix;
259
+
260
+ m4[0][0] = 1.0;
261
+ m4[0][1] = 0.0;
262
+ m4[0][2] = 0.0;
263
+
264
+ m4[1][0] = 0.0;
265
+ m4[1][1] = 1.0;
266
+ m4[1][2] = 0.0;
267
+
268
+ m4[2][0] = 0.0;
269
+ m4[2][1] = 0.0;
270
+ m4[2][2] = 1.0;
271
+
272
+ vec3 object_scale = vec3(
273
+ length(modelViewMatrix[0].xyz),
274
+ length(modelViewMatrix[1].xyz),
275
+ length(modelViewMatrix[2].xyz)
276
+ );
277
+
278
+ vec4 mvPosition = m4 * vec4(object_scale*(vec3(uv.x -0.5, uv.y - 0.5, 0.0) + uOffset/ (uRadius*2.0)), 1.0);
279
+ gl_Position = projectionMatrix * mvPosition;
280
+ vec2 pos = gl_Position.xy/gl_Position.w;
281
+
282
+
283
+ mat4 inverse_matrix = inverse(projectionMatrix * modelViewMatrix);
284
+ //compute ray's start and end as inversion of this coordinates
285
+ //in near and far clip planes
286
+ vec4 near_4 = inverse_matrix * (vec4(pos, -1.0, 1.0));
287
+ vec4 far_4 = inverse_matrix * (vec4(pos, 1.0, 1.0));
288
+
289
+ vec3 local_ray_near = near_4.xyz / near_4.w;
290
+ vec3 local_ray_far = far_4.xyz/ far_4.w;
291
+
292
+ //TODO: check if this is correct. We are using orho projected images, so
293
+ // camera far away
294
+ //vec3 pivotToCameraRay = (cameraPos_OS) * 10.0;
295
+ //vec3 pivotToCameraDir = normalize(cameraPos_OS);
296
+
297
+ vec3 ray_direction = local_ray_far-local_ray_near;
298
+ ray_direction *= -1.0;
299
+
300
+ vec2 grid = VectorToGrid(ray_direction);
301
+ //bias and scale to 0 to 1
302
+ grid = clamp((grid + 1.0) * 0.5, 0.0, 1.0);
303
+ grid *= framesMinusOne;
304
+ grid = clamp(grid, vec2(0.0), framesMinusOne);
305
+ vec2 gridFloor = min(floor(grid), framesMinusOne);
306
+ vec2 gridFract = fract(grid);
307
+
308
+ //vec3 projected = SpriteProjection(pivotToCameraDir, size, uv);
309
+ //vec3 vertexToCameraRay = (pivotToCameraRay - (projected));
310
+ //vec3 vertexToCameraDir = normalize(vertexToCameraRay);
311
+
312
+ frame1 = gridFloor;
313
+ quad_blend_weights = quadBlendWieghts(gridFract);
314
+ //convert frame coordinate to octahedron direction
315
+ vec3 projectedQuadADir = FrameXYToRay(frame1, framesMinusOne);
316
+
317
+ frame2 = clamp(frame1 + mix(vec2(0, 1), vec2(1, 0), quad_blend_weights.w), vec2(0, 0), framesMinusOne);
318
+ vec3 projectedQuadBDir = FrameXYToRay(frame2, framesMinusOne);
319
+
320
+ frame3 = clamp(frame1 + vec2(1.0), vec2(0, 0), framesMinusOne);
321
+ vec3 projectedQuadCDir = FrameXYToRay(frame3, framesMinusOne);
322
+
323
+ frame1_normal = (modelViewMatrix *vec4(projectedQuadADir, 0)).xyz;
324
+ frame2_normal = (modelViewMatrix *vec4(projectedQuadBDir, 0)).xyz;
325
+ frame3_normal = (modelViewMatrix *vec4(projectedQuadCDir, 0)).xyz;
326
+
327
+ //calcute virtual planes projections
328
+ vec3 plane_x1, plane_y1, plane_x2, plane_y2, plane_x3, plane_y3;
329
+ calcuateXYbasis(projectedQuadADir, plane_x1, plane_y1);
330
+ uv_frame1 = virtualPlaneUV(projectedQuadADir, plane_x1, plane_y1, local_ray_near, local_ray_far, uRadius);
331
+ xy_frame1 = projectOnPlaneBasis(-ray_direction, projectedQuadADir, plane_x1, plane_y1).xy;
332
+
333
+ calcuateXYbasis(projectedQuadBDir, plane_x2, plane_y2);
334
+ uv_frame2 = virtualPlaneUV(projectedQuadBDir, plane_x2, plane_y2, local_ray_near, local_ray_far, uRadius);
335
+ xy_frame2 = projectOnPlaneBasis(-ray_direction, projectedQuadBDir, plane_x2, plane_y2).xy;
336
+
337
+ calcuateXYbasis(projectedQuadCDir, plane_x3, plane_y3);
338
+ uv_frame3 = virtualPlaneUV(projectedQuadCDir, plane_x3, plane_y3, local_ray_near, local_ray_far, uRadius);
339
+ xy_frame3 = projectOnPlaneBasis(-ray_direction, projectedQuadCDir, plane_x3, plane_y3).xy;
340
+
341
+ //to fragment shader
342
+ //to fragment shader
343
+ // vec3 p = (projected+uOffset)+pivotToCameraDir*aabb_max;
344
+
345
+ // gl_Position = projectionMatrix * vec4(p,1.0);
346
+
347
+ // NORMAL = normalize(pivotToCameraDir);
348
+ // TANGENT= normalize(cross(NORMAL, vec3(0.0, 1.0, 0.0)));
349
+ // BINORMAL = normalize(cross(TANGENT, NORMAL));
350
+ }
@@ -1,6 +1,6 @@
1
1
  import { HashMap } from "../../../core/collection/HashMap.js";
2
- import { computeGeometryHash } from "../../asset/loaders/geometry/geometry/computeGeometryHash.js";
3
- import { computeGeometryEquality } from "../../asset/loaders/geometry/geometry/computeGeometryEquality.js";
2
+ import { computeGeometryHash } from "../geometry/buffered/computeGeometryHash.js";
3
+ import { computeGeometryEquality } from "../geometry/buffered/computeGeometryEquality.js";
4
4
  import { buildMicronGeometryFromBufferGeometry } from "./build/buildMicronGeometryFromBufferGeometry.js";
5
5
  import { ThreeMicronMesh } from "./format/ThreeMicronMesh.js";
6
6
  import { AsyncMapWrapper } from "../../../core/collection/map/AsyncMapWrapper.js";
@@ -3,8 +3,8 @@ import { VGThreeRenderer } from "../render/v1/VGThreeRenderer.js";
3
3
  import { RenderLayer } from "../../render/layers/RenderLayer.js";
4
4
  import { RenderPassType } from "../../render/RenderPassType.js";
5
5
  import { Cache } from "../../../../core/cache/Cache.js";
6
- import { computeGeometryHash } from "../../../asset/loaders/geometry/geometry/computeGeometryHash.js";
7
- import { computeGeometryEquality } from "../../../asset/loaders/geometry/geometry/computeGeometryEquality.js";
6
+ import { computeGeometryHash } from "../../geometry/buffered/computeGeometryHash.js";
7
+ import { computeGeometryEquality } from "../../geometry/buffered/computeGeometryEquality.js";
8
8
  import { CachedAsyncMap } from "../../../../core/collection/map/CachedAsyncMap.js";
9
9
  import { AsyncRemoteHashMap } from "../../../../core/collection/map/AsyncRemoteHashMap.js";
10
10
  import { BufferGeometrySerializationAdapter } from "./serialization/BufferGeometrySerializationAdapter.js";
@@ -45,7 +45,7 @@ export function getTransformedPositionsCached(occurrence, attribute_index) {
45
45
 
46
46
  const destination = new Float32Array(source_array.length);
47
47
 
48
- apply_mat4_transform_to_v3_array(source_array, 0, destination, 0, patch.vertex_count, occurrence.transform);
48
+ apply_mat4_transform_to_v3_array(source_array, 0, destination, 0, patch.vertex_count, occurrence.transform.elements);
49
49
 
50
50
  // store in cache
51
51
  transformed_position_cache.put(key, destination);
@@ -14,6 +14,6 @@ export class CodeGenerator {
14
14
  uniforms
15
15
  }) {
16
16
 
17
-
17
+ throw new Error('Not Implemented');
18
18
  }
19
19
  }
@@ -24,7 +24,7 @@ export class CurlNoiseNode extends ShaderNode {
24
24
  ],
25
25
  ParticleDataTypes.Vector3
26
26
  )
27
- ))
27
+ ));
28
28
  }
29
29
 
30
30
  generate_code(instance, output, context, port_variables) {
@@ -200,7 +200,7 @@ export class LightManager {
200
200
  this.__decal_atlas_texture.minFilter = LinearMipMapLinearFilter;
201
201
  this.__decal_atlas_texture.magFilter = LinearFilter;
202
202
  this.__decal_atlas_texture.generateMipmaps = true;
203
- this.__decal_atlas_texture.anisotropy = 4;
203
+ this.__decal_atlas_texture.anisotropy = 8;
204
204
 
205
205
  /**
206
206
  *
@@ -66,14 +66,12 @@ export const FP_SHADER_CHUNK_ACCUMULATION = `
66
66
  float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);
67
67
 
68
68
  vec2 decal_uv = (local_position.xy + 0.5)*light_data_4.zw + light_data_4.xy;
69
-
70
-
69
+
71
70
  vec4 decal_color = texture(fp_t_decal_atlas, decal_uv);
72
71
 
73
72
  float decal_alpha = decal_color.a * decal_surface_angle_fade;
74
73
 
75
74
  material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
76
-
77
75
  }
78
76
 
79
77
  }
@@ -23,4 +23,5 @@ export const FP_SHADER_CHUNK_PREAMBLE = `precision mediump usampler3D;
23
23
  #define texture2DProjGradEXT textureProjGrad
24
24
  #define textureCubeGradEXT textureGrad
25
25
 
26
- uniform vec2 fp_resolution;`;
26
+ uniform vec2 fp_resolution;
27
+ `;
@@ -2,6 +2,8 @@ import { AbstractLight } from "./AbstractLight.js";
2
2
  import { aabb3_matrix4_project_by_corners } from "../../../../../core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js";
3
3
  import { aabb3_build_corners } from "../../../../../core/geom/3d/aabb/aabb3_build_corners.js";
4
4
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
5
+ import { mat4 } from "gl-matrix";
6
+ import Signal from "../../../../../core/events/signal/Signal.js";
5
7
 
6
8
  const corners = [];
7
9
  const aabb_array = new Float32Array(6);
@@ -30,6 +32,19 @@ export class Decal extends AbstractLight {
30
32
  * @type {number}
31
33
  */
32
34
  this.draw_priority = 0;
35
+
36
+ this.__signal_transfom_changed = new Signal();
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param {number[]} m
42
+ */
43
+ setTransform(m) {
44
+ mat4.copy(this.transform, m);
45
+ mat4.invert(this.transform_inverse, this.transform);
46
+
47
+ this.__signal_transfom_changed.send0();
33
48
  }
34
49
 
35
50
  handleUvPositionChange(x, y) {
@@ -55,11 +70,13 @@ export class Decal extends AbstractLight {
55
70
  }
56
71
 
57
72
  onDimensionChanged(f, thisArg) {
58
- // TODO implement
73
+
74
+ this.__signal_transfom_changed.add(f, thisArg);
59
75
  }
60
76
 
61
77
  offDimensionChanged(f, thisArg) {
62
- // TODO implement
78
+
79
+ this.__signal_transfom_changed.remove(f, thisArg);
63
80
  }
64
81
 
65
82
  getCenter(result) {
@@ -11,6 +11,9 @@ import {
11
11
  } from "three";
12
12
  import CheckersTexture from "../../../texture/CheckersTexture.js";
13
13
  import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../../../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
14
+ import { formatToChannelCount } from "../../../texture/formatToChannelCount.js";
15
+ import { glsl_gen_swizzled_read } from "../../../shaders/glsl_gen_swizzled_read.js";
16
+ import { assert } from "../../../../../core/assert.js";
14
17
 
15
18
 
16
19
  /**
@@ -44,8 +47,19 @@ function sampleTexel(texture, name, uv) {
44
47
  /**
45
48
  *
46
49
  * @param {THREE.Texture} texture
50
+ * @param {number} [alpha_override] will force specified alpha value in output, useful for cases where alpha would be 0 otherwise
51
+ * @param {(string|number)[]} swizzle allows us to re-arrange pixels as they are being written out
47
52
  */
48
- function makeShader(texture) {
53
+ function makeShader({ texture, alpha_override, swizzle }) {
54
+ let _swizzle = swizzle.slice();
55
+
56
+ const texture_channel_count = formatToChannelCount(texture.format);
57
+
58
+ if (texture_channel_count < 4) {
59
+ // no override specified, and alpha would be 0, force it to one to make image visible
60
+ _swizzle[4] = 1;
61
+ }
62
+
49
63
  return new ShaderMaterial({
50
64
 
51
65
  vertexShader: /* glsl */`
@@ -68,11 +82,7 @@ function makeShader(texture) {
68
82
  void main() {
69
83
 
70
84
  vec4 texel = ${sampleTexel(texture, 'tDiffuse', 'vUv')};
71
- gl_FragColor = texel;
72
-
73
- gl_FragColor.a = 1.0;
74
- // gl_FragColor.r *= 255.0;
75
-
85
+ gl_FragColor = ${glsl_gen_swizzled_read('texel', swizzle)};
76
86
  }`,
77
87
  uniforms: {
78
88
 
@@ -88,7 +98,8 @@ function makeShader(texture) {
88
98
  * @param {number} width
89
99
  * @param {THREE.Texture} texture
90
100
  * @param {THREE.WebGLRenderer} renderer
91
- * @param flipY
101
+ * @param {boolean} [flipY]
102
+ * @param {(string|number)[]} [swizzle]
92
103
  * @return {{view: View, render: function}}
93
104
  */
94
105
  export function buildCanvasViewFromTexture({
@@ -96,9 +107,18 @@ export function buildCanvasViewFromTexture({
96
107
  width = texture.image.width,
97
108
  height = texture.image.height,
98
109
  renderer,
99
- flipY = true
110
+ flipY = true,
111
+ swizzle = ['r', 'g', 'b', 'a']
100
112
  }) {
113
+
114
+ assert.isArray(swizzle, 'swizzle');
115
+
101
116
  const canvasView = new CanvasView();
117
+ canvasView.css({
118
+ position: 'absolute',
119
+ left: 0,
120
+ top: 0
121
+ });
102
122
  canvasView.size.set(width, height);
103
123
 
104
124
  const ctx = canvasView.context2d;
@@ -137,7 +157,7 @@ export function buildCanvasViewFromTexture({
137
157
  */
138
158
  function getShader() {
139
159
  if (__texture_cached !== texture || copyShader === null) {
140
- copyShader = makeShader(texture);
160
+ copyShader = makeShader({ texture: texture, swizzle });
141
161
 
142
162
  copyShader.side = DoubleSide;
143
163
  copyShader.uniforms.tDiffuse.value = texture;
@@ -154,6 +174,8 @@ export function buildCanvasViewFromTexture({
154
174
 
155
175
  getShader().uniforms.tDiffuse.value = texture;
156
176
 
177
+ const _rt = renderer.getRenderTarget();
178
+
157
179
  renderer.setRenderTarget(renderTarget);
158
180
 
159
181
  renderer.render(scene, camera);
@@ -163,7 +185,7 @@ export function buildCanvasViewFromTexture({
163
185
 
164
186
  ctx.putImageData(imageData, 0, 0)
165
187
 
166
- renderer.setRenderTarget(null);
188
+ renderer.setRenderTarget(_rt);
167
189
  };
168
190
 
169
191
  return {
@@ -1,3 +1,5 @@
1
+ import { glsl_gen_swizzled_read } from "./glsl_gen_swizzled_read.js";
2
+
1
3
  function vertexShader() {
2
4
  return `
3
5
  varying vec2 vUv;
@@ -11,25 +13,13 @@ function vertexShader() {
11
13
  `;
12
14
  }
13
15
 
16
+
14
17
  /**
15
18
  *
16
19
  * @param {string[]} [swizzle] what to read from the texture
17
20
  * @returns {string}
18
21
  */
19
22
  function fragmentShader(swizzle = ['r', 'g', 'b', 'a']) {
20
- const swizzle_read = [];
21
- const n = swizzle.length;
22
- for (let i = 0; i < n; i++) {
23
- const token = swizzle[i];
24
-
25
- if (typeof token === "string") {
26
- swizzle_read[i] = `texel.${token}`;
27
- } else if (typeof token === "number") {
28
- swizzle_read[i] = Number(token).toFixed(4);
29
- } else {
30
- throw new Error(`Unsupported swizzle token '${token}'`);
31
- }
32
- }
33
23
 
34
24
  return `
35
25
  uniform sampler2D tTexture;
@@ -37,7 +27,7 @@ function fragmentShader(swizzle = ['r', 'g', 'b', 'a']) {
37
27
 
38
28
  void main(){
39
29
  vec4 texel = texture2D( tTexture, vUv );
40
- gl_FragColor = vec4(${swizzle_read.join(',')});
30
+ gl_FragColor = ${glsl_gen_swizzled_read('texel', swizzle)};
41
31
  }
42
32
  `;
43
33
  }
@@ -0,0 +1,39 @@
1
+ /**
2
+ *
3
+ * @param {string} input name of the variable on which components are being accessed
4
+ * @param {(string|number)[]} swizzle
5
+ * @returns {string} swizzled vector
6
+ */
7
+ export function glsl_gen_swizzled_read(input, swizzle) {
8
+ const swizzle_read = [];
9
+ const n = swizzle.length;
10
+ for (let i = 0; i < n; i++) {
11
+ const token = swizzle[i];
12
+
13
+ if (typeof token === "string") {
14
+ swizzle_read[i] = `${input}.${token}`;
15
+ } else if (typeof token === "number") {
16
+ swizzle_read[i] = Number(token).toFixed(4);
17
+ } else {
18
+ throw new Error(`Unsupported swizzle token '${token}'`);
19
+ }
20
+ }
21
+
22
+ const arg_string = swizzle_read.join(', ');
23
+
24
+ const ctors = [
25
+ undefined,
26
+ 'float',
27
+ 'vec2',
28
+ 'vec3',
29
+ 'vec4'
30
+ ];
31
+
32
+ const ctor = ctors[swizzle.length];
33
+
34
+ if (ctor === undefined) {
35
+ throw new Error(`No constructor for input length ${swizzle.length}`);
36
+ }
37
+
38
+ return `${ctor}(${arg_string})`;
39
+ }