reze-engine 0.70.3 → 0.70.4

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.
@@ -109,6 +109,12 @@ export const SCENE_LIGHT_API_BINDINGS = 4;
109
109
  * `rzWorldAmbient(n)`: the world's light arriving at a surface facing `n` —
110
110
  * the materials' own ambient, so an effect's shade can match hers.
111
111
  *
112
+ * `rzSunDir()` points toward the sun; `rzSunColor()` is the light it brings,
113
+ * the materials' colour × intensity. `rzWorldSpecular(dir, roughness)` is the
114
+ * sky seen along `dir` — the HDRI at the materials' own blur for that
115
+ * roughness, or the ambient by direction where the world has no picture or
116
+ * the module has no sky bound. All scene-linear.
117
+ *
112
118
  * With `on`, declares four bindings from `binding`:
113
119
  * +0 the light uniform (ambient, the sun — direction, and in .w the shadow
114
120
  * switch — and the HDRI's irradiance)
@@ -121,23 +127,56 @@ export const SCENE_LIGHT_API_BINDINGS = 4;
121
127
  * own N·L. The point is nudged toward the sun instead, which lifts a blade's
122
128
  * root off a stage floor that casts into the same map.
123
129
  */
124
- export function sceneLightApi(on, group, binding) {
130
+ export function sceneLightApi(on, group, binding, opts = {}) {
125
131
  if (!on) {
126
132
  return /* wgsl */ `
127
133
  fn rzShadow(p: vec3f) -> f32 { return 1.0; }
128
134
  fn rzWorldAmbient(n: vec3f) -> vec3f { return vec3f(0.0); }
129
135
  fn rzWorldAmbientAvg() -> vec3f { return vec3f(0.0); }
136
+ fn rzSunDir() -> vec3f { return vec3f(0.0, 1.0, 0.0); }
137
+ fn rzSunColor() -> vec3f { return vec3f(0.0); }
138
+ fn rzWorldSpecular(dir: vec3f, roughness: f32) -> vec3f { return vec3f(0.0); }
130
139
  `;
131
140
  }
132
- const n = SHADOW_CASCADES.length;
133
- return /* wgsl */ `
141
+ const shadow = opts.shadow ?? true;
142
+ const sky = opts.sky
143
+ ? /* wgsl */ `
144
+ @group(${group}) @binding(${opts.sky.texture}) var _rzSkyTex: texture_2d<f32>;
145
+ @group(${group}) @binding(${opts.sky.sampler}) var _rzSkySamp: sampler;
146
+ fn rzWorldSpecular(dir: vec3f, roughness: f32) -> vec3f {
147
+ // The materials' lookup (nodes.ts), restated against this module's names:
148
+ // 2 in sh[0].w means an HDRI is installed; otherwise the ambient by
149
+ // direction is the honest blurred sky, and the bound 1x1 is never read.
150
+ if (_rzLight.sh[0].w < 1.5) { return rzWorldAmbient(normalize(dir)); }
151
+ let d = normalize(dir);
152
+ let u = 0.5 + atan2(d.x, d.z) * 0.15915494309;
153
+ let v = 0.5 - asin(clamp(d.y, -1.0, 1.0)) * 0.31830988618;
154
+ let levels = f32(textureNumLevels(_rzSkyTex) - 1u);
155
+ let lod = clamp(sqrt(clamp(roughness, 0.0, 1.0)) * levels, 0.0, levels);
156
+ return textureSampleLevel(_rzSkyTex, _rzSkySamp, vec2f(u, v), lod).rgb * _rzLight.ambientColor.w;
157
+ }
158
+ `
159
+ : /* wgsl */ `
160
+ fn rzWorldSpecular(dir: vec3f, roughness: f32) -> vec3f { return rzWorldAmbient(normalize(dir)); }
161
+ `;
162
+ const sun = /* wgsl */ `
163
+ fn rzSunDir() -> vec3f { return normalize(-_rzLight.lights[0].direction.xyz); }
164
+ fn rzSunColor() -> vec3f { return _rzLight.lights[0].color.rgb * _rzLight.lights[0].color.w; }
165
+ `;
166
+ const head = /* wgsl */ `
134
167
  // The light uniform, as the materials lay it out; lights[0] is the sun.
135
168
  struct _RzSceneLight { direction: vec4f, color: vec4f, }
136
169
  struct _RzSceneLightU { ambientColor: vec4f, lights: array<_RzSceneLight, 4>, sh: array<vec4f, 9>, }
170
+ @group(${group}) @binding(${binding}) var<uniform> _rzLight: _RzSceneLightU;
171
+ `;
172
+ if (!shadow) {
173
+ return head + sun + sky + "\nfn rzShadow(p: vec3f) -> f32 { return 1.0; }\n" + worldAmbientWgsl("_rzLight");
174
+ }
175
+ const n = SHADOW_CASCADES.length;
176
+ return head + sun + sky + /* wgsl */ `
137
177
  // The cascades' matrices, inner to outer, then every caster in one sphere
138
178
  // (x, y, z, radius): radius 0 = nothing casts, negative = do not test.
139
179
  struct _RzShadowBlock { viewProj: array<mat4x4f, ${n}>, casters: vec4f, }
140
- @group(${group}) @binding(${binding}) var<uniform> _rzLight: _RzSceneLightU;
141
180
  @group(${group}) @binding(${binding + 1}) var<uniform> _rzShadowVP: _RzShadowBlock;
142
181
  @group(${group}) @binding(${binding + 2}) var _rzShadowAtlas: texture_depth_2d;
143
182
  @group(${group}) @binding(${binding + 3}) var _rzShadowCmp: sampler_comparison;
@@ -56,5 +56,5 @@ export declare function sceneTapApi(group: number, tex: number, samp: number, la
56
56
  * Black, not a guess: every one of these modules steps BEFORE the scene pass
57
57
  * resolves, so at the moment they run the frame does not exist.
58
58
  */
59
- export declare const SCENE_TAP_STUB = "\nfn rzScene(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn bgScene(uv: vec2f) -> vec3f { return rzScene(uv); }\n/** Far, which in these modules is true: no geometry has been drawn yet. */\nfn rzSceneDepth(uv: vec2f) -> f32 { return 1e9; }\nfn rzSceneFar() -> f32 { return 1e9; }\nfn rzSceneHit(uv: vec2f) -> bool { return false; }\nfn rzSceneAlpha(uv: vec2f) -> f32 { return 0.0; }\nfn rzSceneDisplay(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn rzSceneFrame(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn rzBackground() -> vec4f { return vec4f(0.0); }\n";
59
+ export declare const SCENE_TAP_STUB = "\nfn rzScene(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn bgScene(uv: vec2f) -> vec3f { return rzScene(uv); }\n/** Far, which in these modules is true: no geometry has been drawn yet. */\nfn rzSceneDepth(uv: vec2f) -> f32 { return 1e9; }\nfn rzSceneFar() -> f32 { return 1e9; }\nfn rzSceneHit(uv: vec2f) -> bool { return false; }\nfn rzSceneAlpha(uv: vec2f) -> f32 { return 0.0; }\nfn rzSceneDisplay(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn rzDisplay(c: vec3f) -> vec3f { return c; }\nfn rzSceneFrame(uv: vec2f) -> vec3f { return vec3f(0.0); }\nfn rzBackground() -> vec4f { return vec4f(0.0); }\n";
60
60
  //# sourceMappingURL=scene-tap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scene-tap.d.ts","sourceRoot":"","sources":["../../src/shaders/scene-tap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAChD,MAAM,CA6MR;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,kjBAW1B,CAAA"}
1
+ {"version":3,"file":"scene-tap.d.ts","sourceRoot":"","sources":["../../src/shaders/scene-tap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAChD,MAAM,CAuNR;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,imBAY1B,CAAA"}
@@ -195,9 +195,19 @@ fn rzSceneHit(uv: vec2f) -> bool {
195
195
  * is the identity, so writing it out is both safer and equivalent.
196
196
  */
197
197
  fn rzSceneDisplay(uv: vec2f) -> vec3f {
198
- var c = max(viewTransform(rzScene(uv) * exp2(viewU[0].x)), vec3f(0.0));
199
- if (viewU[9].w > 0.5) { c = _rzGradeScene(c); }
200
- return pow(max(c, vec3f(0.0)), vec3f(viewU[0].y));
198
+ return rzDisplay(rzScene(uv));
199
+ }
200
+
201
+ /**
202
+ * Scene-linear light to what the screen shows, the way the scene's own pixels
203
+ * get there: exposure, the view transform, the grade, the output gamma. For an
204
+ * effect that shades in light (rzWorldSpecular, rzSunColor) and returns
205
+ * display colour, so a highlight it draws rolls off exactly as hers do.
206
+ */
207
+ fn rzDisplay(c: vec3f) -> vec3f {
208
+ var o = max(viewTransform(c * exp2(viewU[0].x)), vec3f(0.0));
209
+ if (viewU[9].w > 0.5) { o = _rzGradeScene(o); }
210
+ return pow(max(o, vec3f(0.0)), vec3f(viewU[0].y));
201
211
  }
202
212
 
203
213
  /**
@@ -270,6 +280,7 @@ fn rzSceneFar() -> f32 { return 1e9; }
270
280
  fn rzSceneHit(uv: vec2f) -> bool { return false; }
271
281
  fn rzSceneAlpha(uv: vec2f) -> f32 { return 0.0; }
272
282
  fn rzSceneDisplay(uv: vec2f) -> vec3f { return vec3f(0.0); }
283
+ fn rzDisplay(c: vec3f) -> vec3f { return c; }
273
284
  fn rzSceneFrame(uv: vec2f) -> vec3f { return vec3f(0.0); }
274
285
  fn rzBackground() -> vec4f { return vec4f(0.0); }
275
286
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.70.3",
3
+ "version": "0.70.4",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",