reze-engine 0.2.15 → 0.2.16

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.
package/README.md CHANGED
@@ -26,11 +26,7 @@ export default function Scene() {
26
26
  const initEngine = useCallback(async () => {
27
27
  if (canvasRef.current) {
28
28
  try {
29
- const engine = new Engine(canvasRef.current, {
30
- ambient: 1.0,
31
- rimLightIntensity: 0.1,
32
- bloomIntensity: 0.1,
33
- })
29
+ const engine = new Engine(canvasRef.current)
34
30
  engineRef.current = engine
35
31
  await engine.init()
36
32
  await engine.loadModel("/models/塞尔凯特/塞尔凯特.pmx")
package/dist/engine.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Quat, Vec3 } from "./math";
2
2
  export type EngineOptions = {
3
- ambient?: number;
4
3
  ambientColor?: Vec3;
5
4
  bloomIntensity?: number;
6
5
  rimLightIntensity?: number;
@@ -24,7 +23,6 @@ export declare class Engine {
24
23
  private cameraTarget;
25
24
  private lightUniformBuffer;
26
25
  private lightData;
27
- private lightCount;
28
26
  private vertexBuffer;
29
27
  private indexBuffer?;
30
28
  private resizeObserver;
@@ -52,7 +50,6 @@ export declare class Engine {
52
50
  private readonly STENCIL_EYE_VALUE;
53
51
  private readonly COMPUTE_WORKGROUP_SIZE;
54
52
  private readonly BLOOM_DOWNSCALE_FACTOR;
55
- private ambient;
56
53
  private ambientColor;
57
54
  private sceneRenderTexture;
58
55
  private sceneRenderTextureView;
@@ -115,8 +112,6 @@ export declare class Engine {
115
112
  private handleResize;
116
113
  private setupCamera;
117
114
  private setupLighting;
118
- private addLight;
119
- private setAmbient;
120
115
  private setAmbientColor;
121
116
  loadAnimation(url: string): Promise<void>;
122
117
  playAnimation(options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAMnC,MAAM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G,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC/C,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB;IAqKM,aAAa;IAQpB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,cAAc;IAuDf,QAAQ,IAAI,WAAW;IAIvB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI;IAgBnC,cAAc;IAQd,OAAO;IAYD,SAAS,CAAC,IAAI,EAAE,MAAM;IAmB5B,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM;YAK5D,iBAAiB;YA0GjB,cAAc;YA+Pd,qBAAqB;IAmC5B,MAAM;IAmIb,OAAO,CAAC,UAAU;IAmGlB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,WAAW;IAwBnB,OAAO,CAAC,kBAAkB;CAgF3B"}
package/dist/engine.js CHANGED
@@ -8,8 +8,7 @@ export class Engine {
8
8
  this.cameraMatrixData = new Float32Array(36);
9
9
  this.cameraDistance = 26.6;
10
10
  this.cameraTarget = new Vec3(0, 12.5, 0);
11
- this.lightData = new Float32Array(64);
12
- this.lightCount = 0;
11
+ this.lightData = new Float32Array(4);
13
12
  this.resizeObserver = null;
14
13
  this.sampleCount = 4;
15
14
  // Constants
@@ -17,10 +16,9 @@ export class Engine {
17
16
  this.COMPUTE_WORKGROUP_SIZE = 64;
18
17
  this.BLOOM_DOWNSCALE_FACTOR = 2;
19
18
  // Ambient light settings
20
- this.ambient = 1.0;
21
19
  this.ambientColor = new Vec3(1.0, 1.0, 1.0);
22
20
  // Bloom settings
23
- this.bloomThreshold = 0.3;
21
+ this.bloomThreshold = 0.01;
24
22
  this.bloomIntensity = 0.12;
25
23
  // Rim light settings
26
24
  this.rimLightIntensity = 0.45;
@@ -60,7 +58,6 @@ export class Engine {
60
58
  this.breathingBaseRotations = new Map();
61
59
  this.canvas = canvas;
62
60
  if (options) {
63
- this.ambient = options.ambient ?? 1.0;
64
61
  this.ambientColor = options.ambientColor ?? new Vec3(1.0, 1.0, 1.0);
65
62
  this.bloomIntensity = options.bloomIntensity ?? 0.12;
66
63
  this.rimLightIntensity = options.rimLightIntensity ?? 0.45;
@@ -111,20 +108,8 @@ export class Engine {
111
108
  _padding: f32,
112
109
  };
113
110
 
114
- struct Light {
115
- direction: vec3f,
116
- _padding1: f32,
117
- color: vec3f,
118
- intensity: f32,
119
- };
120
-
121
111
  struct LightUniforms {
122
- ambient: f32,
123
112
  ambientColor: vec3f,
124
- lightCount: f32,
125
- _padding1: f32,
126
- _padding2: f32,
127
- lights: array<Light, 4>,
128
113
  };
129
114
 
130
115
  struct MaterialUniforms {
@@ -198,16 +183,7 @@ export class Engine {
198
183
  let n = normalize(input.normal);
199
184
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
200
185
 
201
- var lightAccum = light.ambient * light.ambientColor;
202
- let numLights = u32(light.lightCount);
203
- for (var i = 0u; i < numLights; i++) {
204
- let l = -light.lights[i].direction;
205
- let nDotL = max(dot(n, l), 0.0);
206
- let toonUV = vec2f(nDotL, 0.5);
207
- let toonFactor = textureSample(toonTexture, toonSampler, toonUV).rgb;
208
- let radiance = light.lights[i].color * light.lights[i].intensity;
209
- lightAccum += toonFactor * radiance * nDotL;
210
- }
186
+ let lightAccum = light.ambientColor;
211
187
 
212
188
  // Rim light calculation
213
189
  let viewDir = normalize(camera.viewPos - input.worldPos);
@@ -1238,46 +1214,18 @@ export class Engine {
1238
1214
  setupLighting() {
1239
1215
  this.lightUniformBuffer = this.device.createBuffer({
1240
1216
  label: "light uniforms",
1241
- size: 64 * 4,
1217
+ size: 4 * 4, // 4 floats: ambientColor vec3f (3) + padding (1)
1242
1218
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
1243
1219
  });
1244
- this.lightCount = 0;
1245
- this.setAmbient(this.ambient);
1246
1220
  this.setAmbientColor(this.ambientColor);
1247
- this.addLight(new Vec3(-0.5, -0.8, 0.5).normalize(), new Vec3(1.0, 0.95, 0.9), 0.02);
1248
- this.addLight(new Vec3(0.7, -0.5, 0.3).normalize(), new Vec3(0.8, 0.85, 1.0), 0.015);
1249
- this.addLight(new Vec3(0.3, -0.5, -1.0).normalize(), new Vec3(0.9, 0.9, 1.0), 0.01);
1250
1221
  this.device.queue.writeBuffer(this.lightUniformBuffer, 0, this.lightData);
1251
1222
  }
1252
- addLight(direction, color, intensity = 1.0) {
1253
- if (this.lightCount >= 4)
1254
- return false;
1255
- const normalized = direction.normalize();
1256
- const baseIndex = 12 + this.lightCount * 8;
1257
- this.lightData[baseIndex] = normalized.x;
1258
- this.lightData[baseIndex + 1] = normalized.y;
1259
- this.lightData[baseIndex + 2] = normalized.z;
1260
- this.lightData[baseIndex + 3] = 0;
1261
- this.lightData[baseIndex + 4] = color.x;
1262
- this.lightData[baseIndex + 5] = color.y;
1263
- this.lightData[baseIndex + 6] = color.z;
1264
- this.lightData[baseIndex + 7] = intensity;
1265
- this.lightCount++;
1266
- // lightCount: f32 at offset 28 (index 7)
1267
- // Layout: ambient (0), padding (1-3), ambientColor (4-6, padding 7), lightCount (8), _padding1 (9), _padding2 (10), lights start at 12
1268
- this.lightData[8] = this.lightCount;
1269
- return true;
1270
- }
1271
- setAmbient(intensity) {
1272
- // ambient: f32 at offset 0 (index 0)
1273
- this.lightData[0] = intensity;
1274
- }
1275
1223
  setAmbientColor(color) {
1276
- this.lightData[4] = color.x;
1277
- this.lightData[5] = color.y;
1278
- this.lightData[6] = color.z;
1279
- // Index 7 is padding for vec3f alignment (must be 0)
1280
- this.lightData[7] = 0.0;
1224
+ // Layout: ambientColor (0-2), padding (3)
1225
+ this.lightData[0] = color.x;
1226
+ this.lightData[1] = color.y;
1227
+ this.lightData[2] = color.z;
1228
+ this.lightData[3] = 0.0; // Padding for vec3f alignment
1281
1229
  }
1282
1230
  async loadAnimation(url) {
1283
1231
  const frames = await VMDLoader.load(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "A WebGPU-based MMD model renderer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/engine.ts CHANGED
@@ -6,7 +6,6 @@ import { Physics } from "./physics"
6
6
  import { VMDKeyFrame, VMDLoader } from "./vmd-loader"
7
7
 
8
8
  export type EngineOptions = {
9
- ambient?: number
10
9
  ambientColor?: Vec3
11
10
  bloomIntensity?: number
12
11
  rimLightIntensity?: number
@@ -44,8 +43,7 @@ export class Engine {
44
43
  private cameraDistance: number = 26.6
45
44
  private cameraTarget: Vec3 = new Vec3(0, 12.5, 0)
46
45
  private lightUniformBuffer!: GPUBuffer
47
- private lightData = new Float32Array(64)
48
- private lightCount = 0
46
+ private lightData = new Float32Array(4)
49
47
  private vertexBuffer!: GPUBuffer
50
48
  private indexBuffer?: GPUBuffer
51
49
  private resizeObserver: ResizeObserver | null = null
@@ -77,7 +75,6 @@ export class Engine {
77
75
  private readonly COMPUTE_WORKGROUP_SIZE = 64
78
76
  private readonly BLOOM_DOWNSCALE_FACTOR = 2
79
77
  // Ambient light settings
80
- private ambient: number = 1.0
81
78
  private ambientColor: Vec3 = new Vec3(1.0, 1.0, 1.0)
82
79
  // Bloom post-processing textures
83
80
  private sceneRenderTexture!: GPUTexture
@@ -101,7 +98,7 @@ export class Engine {
101
98
  private bloomBlurVBindGroup?: GPUBindGroup
102
99
  private bloomComposeBindGroup?: GPUBindGroup
103
100
  // Bloom settings
104
- private bloomThreshold: number = 0.3
101
+ private bloomThreshold: number = 0.01
105
102
  private bloomIntensity: number = 0.12
106
103
  // Rim light settings
107
104
  private rimLightIntensity: number = 0.45
@@ -147,7 +144,6 @@ export class Engine {
147
144
  constructor(canvas: HTMLCanvasElement, options?: EngineOptions) {
148
145
  this.canvas = canvas
149
146
  if (options) {
150
- this.ambient = options.ambient ?? 1.0
151
147
  this.ambientColor = options.ambientColor ?? new Vec3(1.0, 1.0, 1.0)
152
148
  this.bloomIntensity = options.bloomIntensity ?? 0.12
153
149
  this.rimLightIntensity = options.rimLightIntensity ?? 0.45
@@ -205,20 +201,8 @@ export class Engine {
205
201
  _padding: f32,
206
202
  };
207
203
 
208
- struct Light {
209
- direction: vec3f,
210
- _padding1: f32,
211
- color: vec3f,
212
- intensity: f32,
213
- };
214
-
215
204
  struct LightUniforms {
216
- ambient: f32,
217
205
  ambientColor: vec3f,
218
- lightCount: f32,
219
- _padding1: f32,
220
- _padding2: f32,
221
- lights: array<Light, 4>,
222
206
  };
223
207
 
224
208
  struct MaterialUniforms {
@@ -292,16 +276,7 @@ export class Engine {
292
276
  let n = normalize(input.normal);
293
277
  let albedo = textureSample(diffuseTexture, diffuseSampler, input.uv).rgb;
294
278
 
295
- var lightAccum = light.ambient * light.ambientColor;
296
- let numLights = u32(light.lightCount);
297
- for (var i = 0u; i < numLights; i++) {
298
- let l = -light.lights[i].direction;
299
- let nDotL = max(dot(n, l), 0.0);
300
- let toonUV = vec2f(nDotL, 0.5);
301
- let toonFactor = textureSample(toonTexture, toonSampler, toonUV).rgb;
302
- let radiance = light.lights[i].color * light.lights[i].intensity;
303
- lightAccum += toonFactor * radiance * nDotL;
304
- }
279
+ let lightAccum = light.ambientColor;
305
280
 
306
281
  // Rim light calculation
307
282
  let viewDir = normalize(camera.viewPos - input.worldPos);
@@ -1384,53 +1359,21 @@ export class Engine {
1384
1359
  private setupLighting() {
1385
1360
  this.lightUniformBuffer = this.device.createBuffer({
1386
1361
  label: "light uniforms",
1387
- size: 64 * 4,
1362
+ size: 4 * 4, // 4 floats: ambientColor vec3f (3) + padding (1)
1388
1363
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
1389
1364
  })
1390
1365
 
1391
- this.lightCount = 0
1392
-
1393
- this.setAmbient(this.ambient)
1394
1366
  this.setAmbientColor(this.ambientColor)
1395
1367
 
1396
- this.addLight(new Vec3(-0.5, -0.8, 0.5).normalize(), new Vec3(1.0, 0.95, 0.9), 0.02)
1397
- this.addLight(new Vec3(0.7, -0.5, 0.3).normalize(), new Vec3(0.8, 0.85, 1.0), 0.015)
1398
- this.addLight(new Vec3(0.3, -0.5, -1.0).normalize(), new Vec3(0.9, 0.9, 1.0), 0.01)
1399
1368
  this.device.queue.writeBuffer(this.lightUniformBuffer, 0, this.lightData)
1400
1369
  }
1401
1370
 
1402
- private addLight(direction: Vec3, color: Vec3, intensity: number = 1.0): boolean {
1403
- if (this.lightCount >= 4) return false
1404
-
1405
- const normalized = direction.normalize()
1406
- const baseIndex = 12 + this.lightCount * 8
1407
- this.lightData[baseIndex] = normalized.x
1408
- this.lightData[baseIndex + 1] = normalized.y
1409
- this.lightData[baseIndex + 2] = normalized.z
1410
- this.lightData[baseIndex + 3] = 0
1411
- this.lightData[baseIndex + 4] = color.x
1412
- this.lightData[baseIndex + 5] = color.y
1413
- this.lightData[baseIndex + 6] = color.z
1414
- this.lightData[baseIndex + 7] = intensity
1415
-
1416
- this.lightCount++
1417
- // lightCount: f32 at offset 28 (index 7)
1418
- // Layout: ambient (0), padding (1-3), ambientColor (4-6, padding 7), lightCount (8), _padding1 (9), _padding2 (10), lights start at 12
1419
- this.lightData[8] = this.lightCount
1420
- return true
1421
- }
1422
-
1423
- private setAmbient(intensity: number) {
1424
- // ambient: f32 at offset 0 (index 0)
1425
- this.lightData[0] = intensity
1426
- }
1427
-
1428
1371
  private setAmbientColor(color: Vec3) {
1429
- this.lightData[4] = color.x
1430
- this.lightData[5] = color.y
1431
- this.lightData[6] = color.z
1432
- // Index 7 is padding for vec3f alignment (must be 0)
1433
- this.lightData[7] = 0.0
1372
+ // Layout: ambientColor (0-2), padding (3)
1373
+ this.lightData[0] = color.x
1374
+ this.lightData[1] = color.y
1375
+ this.lightData[2] = color.z
1376
+ this.lightData[3] = 0.0 // Padding for vec3f alignment
1434
1377
  }
1435
1378
 
1436
1379
  public async loadAnimation(url: string) {