@woosh/meep-engine 2.41.0 → 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 (39) hide show
  1. package/core/geom/3d/apply_mat4_transform_to_v3_array.js +2 -4
  2. package/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +28 -0
  3. package/core/geom/Quaternion.js +14 -0
  4. package/engine/EngineHarness.js +9 -3
  5. package/engine/ecs/transform/Transform.js +23 -3
  6. package/engine/graphics/ecs/decal/v2/Decal.d.ts +11 -0
  7. package/engine/graphics/ecs/decal/v2/Decal.js +50 -0
  8. package/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +8 -0
  9. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +213 -0
  10. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +237 -0
  11. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +8 -1
  12. package/engine/graphics/ecs/mesh-v2/build_three_object.js +4 -0
  13. package/engine/graphics/geometry/MikkT/MikkTSpace.js +466 -305
  14. package/engine/graphics/geometry/buffered/computeGeometryEquality.js +1 -1
  15. package/engine/graphics/geometry/buffered/computeGeometryHash.js +1 -1
  16. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +27 -14
  17. package/engine/graphics/impostors/octahedral/ImpostorDescription.js +6 -0
  18. package/engine/graphics/impostors/octahedral/README.md +1 -0
  19. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +25 -22
  20. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere_radius_only.js +37 -0
  21. package/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +30 -1
  22. package/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +1 -1
  23. package/engine/graphics/impostors/octahedral/prototypeBaker.js +121 -22
  24. package/engine/graphics/impostors/octahedral/shader/BakeShaderStandard.js +46 -7
  25. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +349 -0
  26. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV1.js +74 -0
  27. package/engine/graphics/impostors/octahedral/shader/glsl/v1/common.glsl +209 -0
  28. package/engine/graphics/impostors/octahedral/shader/glsl/v1/flagment.glsl +80 -0
  29. package/engine/graphics/impostors/octahedral/shader/glsl/v1/vertex.glsl +350 -0
  30. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  31. package/engine/graphics/render/forward_plus/LightManager.js +1 -1
  32. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +1 -3
  33. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +2 -1
  34. package/engine/graphics/render/forward_plus/model/Decal.js +19 -2
  35. package/engine/graphics/texture/sampler/Sampler2D.js +10 -10
  36. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +117 -11
  37. package/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +66 -0
  38. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +2 -2
  39. package/package.json +1 -1
@@ -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
+ }
@@ -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);
@@ -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) {
@@ -271,10 +271,10 @@ export class Sampler2D {
271
271
  * @returns {number}
272
272
  */
273
273
  sampleChannelCatmullRomUV(u, v, channel) {
274
- const x = u * (this.width);
275
- const y = v * (this.height);
274
+ const x = u * (this.width - 1);
275
+ const y = v * (this.height - 1);
276
276
 
277
- return this.sampleChannelCatmullRom(x - 0.5, y - 0.5, channel);
277
+ return this.sampleChannelCatmullRom(x, y, channel);
278
278
  }
279
279
 
280
280
  /**
@@ -366,8 +366,8 @@ export class Sampler2D {
366
366
  * @returns {number}
367
367
  */
368
368
  sampleChannelBicubicUV(u, v, channel) {
369
- const x = u * (this.width);
370
- const y = v * (this.height);
369
+ const x = u * (this.width - 1);
370
+ const y = v * (this.height - 1);
371
371
 
372
372
  return this.sampleChannelBicubic(x - 0.5, y - 0.5, channel);
373
373
  }
@@ -511,10 +511,10 @@ export class Sampler2D {
511
511
  * @return {number}
512
512
  */
513
513
  sampleChannelBilinearUV(u, v, channel) {
514
- const x = u * (this.width);
515
- const y = v * (this.height);
514
+ const x = u * (this.width - 1);
515
+ const y = v * (this.height - 1);
516
516
 
517
- return this.sampleChannelBilinear(x - 0.5, y - 0.5, channel);
517
+ return this.sampleChannelBilinear(x, y, channel);
518
518
  }
519
519
 
520
520
  /**
@@ -599,8 +599,8 @@ export class Sampler2D {
599
599
  }
600
600
 
601
601
  sampleNearestUV(u, v, result) {
602
- const x = Math.round(u * (this.width) - 0.5);
603
- const y = Math.round(v * (this.height) - 0.5);
602
+ const x = Math.round(u * (this.width - 1));
603
+ const y = Math.round(v * (this.height - 1));
604
604
 
605
605
  this.read(min2(x, this.width - 1), min2(y, this.height - 1), result);
606
606
  }
@@ -6,17 +6,56 @@ import { sampler2D_scale_down_lanczos } from "./sampler2_d_scale_down_lanczos.js
6
6
  import { Sampler2D } from "./Sampler2D.js";
7
7
  import { genericResampleSampler2D } from "./genericResampleSampler2D.js";
8
8
  import Vector2 from "../../../../core/geom/Vector2.js";
9
+ import LabelView from "../../../../view/common/LabelView.js";
10
+ import EmptyView from "../../../../view/elements/EmptyView.js";
11
+ import { sampler2d_downsample_mipmap } from "./resize/sampler2d_downsample_mipmap.js";
9
12
 
10
13
  function grid(engine, input, transforms, size = new Vector2(input.width, input.height)) {
11
14
 
15
+ let draw_index = 0;
16
+
12
17
  for (let i = 0; i < transforms.length; i++) {
13
18
  const out = input.clone();
14
19
 
15
20
  out.resize(size.x, size.y);
16
21
 
17
- transforms[i](out, input);
22
+ const params = {
23
+ label: '',
24
+ skip: false
25
+ };
26
+
27
+ try {
28
+ transforms[i](out, input, params);
29
+ } catch (e) {
30
+ // error, skip
31
+ }
32
+
33
+ if (params.skip) {
34
+ continue;
35
+ }
36
+
37
+
38
+ const view = display(engine, out, draw_index * (size.x + 4), 0);
39
+
40
+ if (params.label.length > 0) {
41
+ view.addChild(new LabelView(params.label, {
42
+ css: {
43
+ position: 'absolute',
44
+ fontFamily: 'sans-serif',
45
+ fontWeight: 'bold',
46
+ top: 0,
47
+ left: 0,
48
+ zIndex: 1,
49
+ color: '#000000',
50
+ textShadow: '1px 1px 1px white',
51
+ background: 'rgba(255,255,255,0.7)',
52
+ padding: '2px'
53
+ }
54
+ }));
55
+ }
56
+
57
+ draw_index++;
18
58
 
19
- display(engine, out, i * (size.x + 4), 0);
20
59
  }
21
60
 
22
61
  }
@@ -30,11 +69,23 @@ function display(engine, sampler, x = 0, y = 0) {
30
69
 
31
70
  view.css({
32
71
  position: 'absolute',
33
- top: `${y}px`,
34
- left: `${x}px`
72
+ top: "0",
73
+ left: "0"
35
74
  });
36
75
 
37
- engine.gameView.addChild(view);
76
+ const container = new EmptyView({
77
+ css: {
78
+ position: 'absolute',
79
+ top: `${y}px`,
80
+ left: `${x}px`
81
+ }
82
+ });
83
+ container.size.set(sampler.width, sampler.height);
84
+ container.addChild(view);
85
+
86
+ engine.gameView.addChild(container);
87
+
88
+ return container;
38
89
  }
39
90
 
40
91
 
@@ -44,7 +95,13 @@ new EngineHarness().initialize({
44
95
  }
45
96
  }).then(async engine => {
46
97
 
47
- const asset = await engine.assetManager.promise("data/textures/utility/Lenna.png", 'image');
98
+ // const asset = await engine.assetManager.promise("data/textures/utility/Lenna.png", 'image');
99
+ // const asset = await engine.assetManager.promise("data/textures/utility/uv_map_reference.jpg", 'image');
100
+ const asset = await engine.assetManager.promise("data/textures/utility/image018.jpg", 'image');
101
+ // const asset = await engine.assetManager.promise("data/textures/utility/TESTIMAGES/SAMPLING/8BIT/RGB/2448x2448/SRC/img_2448x2448_3x8bit_SRC_RGB_clips.png", 'image');
102
+ // const asset = await engine.assetManager.promise("data/textures/utility/TESTIMAGES/SAMPLING/8BIT/RGB/2448x2448/SRC/img_2448x2448_3x8bit_SRC_RGB_coins.png", 'image');
103
+ // const asset = await engine.assetManager.promise("data/models/LowPolyTownshipSet/Small_house/diffuse_512.png", 'image');
104
+ // const asset = await engine.assetManager.promise("data/models/LowPolyTownshipSet/Barrel/diffuse_256.png", 'image');
48
105
  // const asset = await engine.assetManager.promise("data/textures/utility/resolver.jpeg", 'image');
49
106
  // const asset = await engine.assetManager.promise("data/textures/icons/500_skill_icons_02/Skill_nobg/skill_492_noBG.png", 'image');
50
107
  // const asset = await engine.assetManager.promise("data/textures/utility/sampling-test.png", 'image');
@@ -88,7 +145,9 @@ new EngineHarness().initialize({
88
145
 
89
146
  function test_sampling(source, engine) {
90
147
  grid(engine, source, [
91
- (out, input) => {
148
+ (out, input, params) => {
149
+ params.label = 'Nearest';
150
+
92
151
  const sample = [];
93
152
  for (let y = 0; y < out.height; y++) {
94
153
 
@@ -100,7 +159,11 @@ function test_sampling(source, engine) {
100
159
  }
101
160
  }
102
161
  },
103
- (out, input) => {
162
+ (out, input, params) => {
163
+
164
+ params.label = 'Bilinear';
165
+ params.skip = true;
166
+
104
167
  const sample = new Uint8ClampedArray(4);
105
168
  for (let y = 0; y < out.height; y++) {
106
169
 
@@ -112,7 +175,10 @@ function test_sampling(source, engine) {
112
175
  }
113
176
  }
114
177
  },
115
- (out, input) => {
178
+ (out, input, params) => {
179
+ params.label = 'Bicubic';
180
+ params.skip = true;
181
+
116
182
  const sample = new Uint8ClampedArray(4);
117
183
  for (let y = 0; y < out.height; y++) {
118
184
 
@@ -124,7 +190,10 @@ function test_sampling(source, engine) {
124
190
  }
125
191
  }
126
192
  },
127
- (out, input) => {
193
+ (out, input, params) => {
194
+ params.label = 'catmull-rom';
195
+ params.skip = true;
196
+
128
197
  const sample = new Uint8ClampedArray(4);
129
198
  for (let y = 0; y < out.height; y++) {
130
199
 
@@ -135,9 +204,46 @@ function test_sampling(source, engine) {
135
204
  out.set(x, y, sample);
136
205
  }
137
206
  }
207
+ },
208
+ (out, input, params) => {
209
+ params.label = 'mip';
210
+
211
+
212
+ sampler2d_downsample_mipmap(input, out);
213
+
214
+ },
215
+ (out, input, params) => {
216
+ const lobes = 2;
217
+ params.label = `lanczos_${lobes}`;
218
+ params.skip = true;
219
+
220
+ return;
221
+
222
+ sampler2D_scale_down_lanczos(input, out, lobes);
223
+
224
+ },
225
+ (out, input, params) => {
226
+ const lobes = 3;
227
+ params.label = `lanczos_${lobes}`;
228
+
229
+
230
+ sampler2D_scale_down_lanczos(input, out, lobes);
231
+
232
+ },
233
+ (out, input, params) => {
234
+ const lobes = 5;
235
+ params.skip = true;
236
+ params.label = `lanczos_${lobes}`;
237
+
238
+ return;
239
+
240
+ sampler2D_scale_down_lanczos(input, out, lobes);
241
+
138
242
  }
139
243
  ], new Vector2(
140
- 200, 200
244
+ // 100, 100
245
+ 1024, 1024
246
+ // 136, 136
141
247
  ));
142
248
  }
143
249