reze-engine 0.61.7 → 0.62.1
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/dist/engine.d.ts +24 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +96 -7
- package/dist/shaders/directives.d.ts +10 -0
- package/dist/shaders/directives.d.ts.map +1 -1
- package/dist/shaders/directives.js +11 -0
- package/dist/shaders/lights.d.ts.map +1 -1
- package/dist/shaders/lights.js +2 -1
- package/dist/shaders/passes/composite.d.ts.map +1 -1
- package/dist/shaders/passes/composite.js +2 -0
- package/dist/shaders/passes/grid.d.ts.map +1 -1
- package/dist/shaders/passes/grid.js +2 -0
- package/dist/shaders/passes/particles.d.ts +7 -0
- package/dist/shaders/passes/particles.d.ts.map +1 -1
- package/dist/shaders/passes/particles.js +10 -0
- package/dist/shaders/passes/scene-contract.d.ts.map +1 -1
- package/dist/shaders/passes/scene-contract.js +6 -2
- package/dist/shaders/passes/trails.d.ts.map +1 -1
- package/dist/shaders/passes/trails.js +2 -1
- package/dist/shaders/texture-api.d.ts +9 -0
- package/dist/shaders/texture-api.d.ts.map +1 -0
- package/dist/shaders/texture-api.js +54 -0
- package/package.json +1 -1
- package/src/engine.ts +110 -3
- package/src/shaders/directives.ts +21 -0
- package/src/shaders/lights.ts +2 -1
- package/src/shaders/passes/composite.ts +2 -0
- package/src/shaders/passes/grid.ts +2 -0
- package/src/shaders/passes/particles.ts +13 -0
- package/src/shaders/passes/scene-contract.ts +6 -2
- package/src/shaders/passes/trails.ts +2 -1
- package/src/shaders/texture-api.ts +56 -0
|
@@ -12,6 +12,7 @@ import { sceneIdFieldWgsl, sceneIdPadWgsl } from "./scene-contract"
|
|
|
12
12
|
import { idApi } from "../id-api"
|
|
13
13
|
import { sceneLightApi } from "../scene-light-api"
|
|
14
14
|
import { pointsApi } from "../points-api"
|
|
15
|
+
import { textureApi } from "../texture-api"
|
|
15
16
|
// Ribbons along a bone's recorded path, drawn as geometry.
|
|
16
17
|
//
|
|
17
18
|
// This is the effect the whole geometry path was built for. As a fullscreen
|
|
@@ -303,7 +304,7 @@ fn rzTurnRadius(a: vec3f, b: vec3f, c: vec3f) -> f32 {
|
|
|
303
304
|
gridReadApi(0, 8, 9, src.gridSize) +
|
|
304
305
|
// Stubbed: this module cannot read an attachment the scene pass writes — see
|
|
305
306
|
// id-api.ts. The author's whole file compiles here, so the names must exist.
|
|
306
|
-
idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) + pointsApi(false) +
|
|
307
|
+
idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) + pointsApi(false) + textureApi(0) +
|
|
307
308
|
"\n// ── user effect ──\n" +
|
|
308
309
|
src.wgsl +
|
|
309
310
|
/* wgsl */ `
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Pictures an effect is handed by its host — `#textures N`.
|
|
2
|
+
//
|
|
3
|
+
// #textures 2
|
|
4
|
+
//
|
|
5
|
+
// gives the PARTICLE SHADING rzTexture(i, uv) and rzTextureLod(i, uv, lod) over
|
|
6
|
+
// N images the host passes with the install (setEffects' `textures`, slot i =
|
|
7
|
+
// picture i). uv (0,0) is the image's top-left row, the style graph's
|
|
8
|
+
// tex_image convention, and it repeats. A slot the host left empty reads white.
|
|
9
|
+
//
|
|
10
|
+
// WHY: a game's splash is a picture on a card, and an effect that may only draw
|
|
11
|
+
// procedurally can only ever guess at it — shape, coverage, veins, each a guess
|
|
12
|
+
// to be corrected. A converted stage carries the game's own textures, and this
|
|
13
|
+
// is how its particles draw them.
|
|
14
|
+
//
|
|
15
|
+
// Fragment-only, because textureSample is: the compute stage and every other
|
|
16
|
+
// module the author's file is spliced into get STUBS returning zero, so one
|
|
17
|
+
// effect file compiles in every mount it has.
|
|
18
|
+
|
|
19
|
+
/** How many pictures one effect can read. */
|
|
20
|
+
export const MAX_EFFECT_TEXTURES = 4
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* rzTexture / rzTextureLod. `count` is the effect's `#textures` (0 = stubs);
|
|
24
|
+
* the textures take bindings first..first+count-1 in `group` and the one
|
|
25
|
+
* sampler `sampler`.
|
|
26
|
+
*/
|
|
27
|
+
export function textureApi(count: number, group = 0, first = 0, sampler = 0): string {
|
|
28
|
+
if (count <= 0) {
|
|
29
|
+
return /* wgsl */ `
|
|
30
|
+
fn rzTexture(i: u32, uv: vec2f) -> vec4f { return vec4f(0.0); }
|
|
31
|
+
fn rzTextureLod(i: u32, uv: vec2f, lod: f32) -> vec4f { return vec4f(0.0); }
|
|
32
|
+
`
|
|
33
|
+
}
|
|
34
|
+
const n = Math.min(count, MAX_EFFECT_TEXTURES)
|
|
35
|
+
let decl = `@group(${group}) @binding(${sampler}) var _rzTexSampler: sampler;\n`
|
|
36
|
+
for (let k = 0; k < n; k++) decl += `@group(${group}) @binding(${first + k}) var _rzTex${k}: texture_2d<f32>;\n`
|
|
37
|
+
// Every slot is sampled unconditionally and the one asked for is selected:
|
|
38
|
+
// textureSample must be reached in uniform control flow, and a switch on a
|
|
39
|
+
// per-fragment index is not.
|
|
40
|
+
const pick = (call: (k: number) => string) => {
|
|
41
|
+
let body = " var c = vec4f(0.0);\n"
|
|
42
|
+
for (let k = 0; k < n; k++) body += ` let s${k} = ${call(k)};\n if (i == ${k}u) { c = s${k}; }\n`
|
|
43
|
+
return body + " return c;\n"
|
|
44
|
+
}
|
|
45
|
+
return (
|
|
46
|
+
decl +
|
|
47
|
+
/* wgsl */ `
|
|
48
|
+
/** Picture i of the effect's #textures, at uv ((0,0) top-left, repeating). */
|
|
49
|
+
fn rzTexture(i: u32, uv: vec2f) -> vec4f {
|
|
50
|
+
${pick((k) => `textureSample(_rzTex${k}, _rzTexSampler, uv)`)}}
|
|
51
|
+
/** The same at an explicit mip level — usable where derivatives are not. */
|
|
52
|
+
fn rzTextureLod(i: u32, uv: vec2f, lod: f32) -> vec4f {
|
|
53
|
+
${pick((k) => `textureSampleLevel(_rzTex${k}, _rzTexSampler, uv, lod)`)}}
|
|
54
|
+
`
|
|
55
|
+
)
|
|
56
|
+
}
|