onejs-sl 0.1.12 → 0.1.13
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/CHANGELOG.md +7 -0
- package/README.md +25 -20
- package/goldens/goldens.json +1 -1
- package/lib/noise2d.hlsl +10 -4
- package/package.json +1 -1
- package/src/lib/glsl.ts +9 -5
- package/src/lib/hlsl.ts +9 -5
- package/src/lib/wgsl.ts +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.13
|
|
4
|
+
|
|
5
|
+
Unity's Metal compile of OneJS's effects no longer warns of an uninitialized variable. Nothing draws differently.
|
|
6
|
+
|
|
7
|
+
- `onejsFbmKind` returns once, so FxSources compiles on Metal with no warning
|
|
8
|
+
- A WGSL noise kind no longer evaluates both fBm kinds to pick one
|
|
9
|
+
|
|
3
10
|
## 0.1.12
|
|
4
11
|
|
|
5
12
|
The noise hashes are integer arithmetic, so every GPU draws the same bits. Value noise and voronoi look different, seed 0 included; program hashes do not change.
|
package/README.md
CHANGED
|
@@ -115,8 +115,8 @@ know the project's colour space when it prints.
|
|
|
115
115
|
difference, the `.cginc` copies included in the container, and OneJS's
|
|
116
116
|
`SLSharedLibraryTests` checks them from the other side. What proves the
|
|
117
117
|
translations draw the same picture: the goldens compile the whole library on
|
|
118
|
-
WebGPU and WebGL2 and draw every fixture; OneJS's parity harness
|
|
119
|
-
|
|
118
|
+
WebGPU and WebGL2 and draw every fixture; OneJS's parity harness draws every
|
|
119
|
+
fixture through a real WebGL player and holds it to the goldens; `SLSharedLibraryTests` draws every corpus program in Unity
|
|
120
120
|
through `SLCommon.cginc` and through the translated shared subset and requires
|
|
121
121
|
them to agree; and the Metal check above compiles the shared subset.
|
|
122
122
|
|
|
@@ -125,9 +125,11 @@ them to agree; and the Metal check above compiles the shared subset.
|
|
|
125
125
|
`goldens/goldens.json` is every corpus fixture drawn as a Linear OneJS game
|
|
126
126
|
stores it: the package's WGSL and GLSL ES in OneJS's web frame, into an
|
|
127
127
|
`rgba8unorm-srgb` target (the format the element's render texture has), read
|
|
128
|
-
back raw, with no Unity, no UI Toolkit and no browser colour management.
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
back raw, with no Unity, no UI Toolkit and no browser colour management. The
|
|
129
|
+
goldens stand on their own: the two backends must agree, and the anchors and
|
|
130
|
+
the hash probes must match arithmetic. A host's own backend is checked against
|
|
131
|
+
them, as OneJS's parity harness (`Tools/sl-web-parity` in the container) checks
|
|
132
|
+
what a WebGL player draws.
|
|
131
133
|
|
|
132
134
|
`npm run goldens` draws it on WebGPU and WebGL2 in a Chrome with its own
|
|
133
135
|
profile (set `CHROME` to choose one). The two backends must agree within 1/255
|
|
@@ -202,17 +204,17 @@ container this package is checked out at `JSModules/onejs-sl`, and
|
|
|
202
204
|
|
|
203
205
|
## The one idea
|
|
204
206
|
|
|
205
|
-
**One authoring surface, one IR,
|
|
206
|
-
at runtime in a player build, on any graphics API, so
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
editor compiles shaders at build time.
|
|
207
|
+
**One authoring surface, one IR, several backends.** Unity cannot compile a
|
|
208
|
+
shader at runtime in a player build, on any graphics API, so the first backend
|
|
209
|
+
made a program data that a fixed shader evaluates: a VM. An editor does compile
|
|
210
|
+
shaders, at build time, so the second prints HLSL for it.
|
|
210
211
|
|
|
211
|
-
So the same source
|
|
212
|
-
|
|
212
|
+
So the same source draws compiled from generated HLSL in the editor and in a
|
|
213
|
+
native player, with no edit in between, and the VM stays behind a switch: OneJS
|
|
214
|
+
leaves it out unless a project defines `ONEJS_SL_VM`. Both backends exist:
|
|
213
215
|
`encode.ts` feeds OneJS's `Runtime/SL/SLProgramBridge.cs` and `FxProgram.shader`,
|
|
214
216
|
and `hlsl.ts` feeds its `Editor/SLShaderGenerator.cs`. Nobody writes a manifest for the
|
|
215
|
-
second: an editor that
|
|
217
|
+
second: an editor that draws a program asks the encoded program for its
|
|
216
218
|
`hlsl` (a lazy getter, never read in Play), records it into
|
|
217
219
|
`Assets/OneJS/Recorded.sl.json`, generates the shader and
|
|
218
220
|
moves the live material onto it. `manifest()` is still there for an app that
|
|
@@ -223,10 +225,11 @@ shader, but the page it runs in can. `web.ts` prints every program as WGSL and
|
|
|
223
225
|
as GLSL ES 3.00 (carrying the library functions it calls, translated from
|
|
224
226
|
`lib/*.hlsl`), and OneJS's
|
|
225
227
|
`Plugins/WebGL/OneJSSLWeb.jslib` compiles whichever one Unity's device speaks
|
|
226
|
-
and draws it into the element's target
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
and draws it into the element's target. A `.sl` import carries both strings,
|
|
229
|
+
printed at build time; an `encode()` result has them as lazy getters, like
|
|
230
|
+
`hlsl`. A WebGL player has no VM: the element draws nothing until the compiled
|
|
231
|
+
program is ready, and nothing after a compile error, which the page reports.
|
|
232
|
+
The host contract (the frame block, the
|
|
230
233
|
16 uniform slots, one binding pair per sampled texture) is written out at the
|
|
231
234
|
top of `web.ts`.
|
|
232
235
|
|
|
@@ -234,7 +237,7 @@ The emitters match the HLSL emitter's semantics rather than each language's
|
|
|
234
237
|
own: `%` truncates like `fmod`, `pow` takes `abs` of its base, `asin` and
|
|
235
238
|
`acos` clamp, `log` and `sqrt` guard their argument, a select is the VM's
|
|
236
239
|
branchless `lerp`. `web.test.ts` checks the structure (every shape, every
|
|
237
|
-
opcode, the library order); whether the output matches the
|
|
240
|
+
opcode, the library order); whether the output matches the goldens is
|
|
238
241
|
measured in a browser, through the real element, by `Tools/sl-web-parity` in
|
|
239
242
|
the container.
|
|
240
243
|
|
|
@@ -294,8 +297,10 @@ baseline, which is the one resource neither backend can widen.
|
|
|
294
297
|
|
|
295
298
|
`Program.hash` is what will link a program to its compiled shader. If it differs
|
|
296
299
|
between the machine that generated the shader and the machine that runs it, the
|
|
297
|
-
|
|
298
|
-
|
|
300
|
+
player finds no shader for the program: it draws nothing and logs one error
|
|
301
|
+
naming the hash. Before OneJS 3.6.0 it fell back to the VM and **nobody was
|
|
302
|
+
told**: correct output, quietly slow, no error, the worst failure this design
|
|
303
|
+
could have, and the reason the hash is built the way it is.
|
|
299
304
|
|
|
300
305
|
So it is a Merkle hash over the graph reachable from the result, not a walk of
|
|
301
306
|
the node array. An earlier version hashed storage order, which meant hoisting a
|
package/goldens/goldens.json
CHANGED
package/lib/noise2d.hlsl
CHANGED
|
@@ -213,10 +213,16 @@ float onejsRidged(float2 p, float seed, int octaves, float lacunarity, float gai
|
|
|
213
213
|
|
|
214
214
|
/// Dispatches on the noise kind: 0 value fBm, 1 simplex fBm, 2 turbulence,
|
|
215
215
|
/// 3 ridged. The numbers are the contract with onejs-unity/src/fx/image.ts.
|
|
216
|
+
///
|
|
217
|
+
/// One return, at the end. Written with early returns, every path still
|
|
218
|
+
/// returns, but Unity's Metal compile warns of a potentially uninitialized
|
|
219
|
+
/// variable named after this function in every project that imports OneJS.
|
|
216
220
|
float onejsFbmKind(int kind, float2 p, float seed, int octaves, float lacunarity, float gain)
|
|
217
221
|
{
|
|
218
|
-
|
|
219
|
-
if (kind ==
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
float n;
|
|
223
|
+
if (kind == 2) n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
|
|
224
|
+
else if (kind == 3) n = onejsRidged(p, seed, octaves, lacunarity, gain);
|
|
225
|
+
else if (kind == 1) n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
|
|
226
|
+
else n = onejsFbm(p, seed, octaves, lacunarity, gain);
|
|
227
|
+
return n;
|
|
222
228
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onejs-sl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "The OneJS shader language: a small typed language for per pixel programs, compiled to a portable IR and emitted as HLSL, WGSL, GLSL ES or a VM buffer",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/src/lib/glsl.ts
CHANGED
|
@@ -710,13 +710,17 @@ float onejsRidged(vec2 p, float seed, int octaves, float lacunarity, float gain)
|
|
|
710
710
|
`,
|
|
711
711
|
`
|
|
712
712
|
float onejsFbmKind(int kind, vec2 p, float seed, int octaves, float lacunarity, float gain) {
|
|
713
|
+
float n;
|
|
713
714
|
if (kind == 2) {
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
715
|
+
n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
|
|
716
|
+
} else if (kind == 3) {
|
|
717
|
+
n = onejsRidged(p, seed, octaves, lacunarity, gain);
|
|
718
|
+
} else if (kind == 1) {
|
|
719
|
+
n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
|
|
720
|
+
} else {
|
|
721
|
+
n = onejsFbm(p, seed, octaves, lacunarity, gain);
|
|
718
722
|
}
|
|
719
|
-
return
|
|
723
|
+
return n;
|
|
720
724
|
}
|
|
721
725
|
`,
|
|
722
726
|
`
|
package/src/lib/hlsl.ts
CHANGED
|
@@ -710,13 +710,17 @@ float onejsRidged(float2 p, float seed, int octaves, float lacunarity, float gai
|
|
|
710
710
|
`,
|
|
711
711
|
`
|
|
712
712
|
float onejsFbmKind(int kind, float2 p, float seed, int octaves, float lacunarity, float gain) {
|
|
713
|
+
float n;
|
|
713
714
|
if (kind == 2) {
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
715
|
+
n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
|
|
716
|
+
} else if (kind == 3) {
|
|
717
|
+
n = onejsRidged(p, seed, octaves, lacunarity, gain);
|
|
718
|
+
} else if (kind == 1) {
|
|
719
|
+
n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
|
|
720
|
+
} else {
|
|
721
|
+
n = onejsFbm(p, seed, octaves, lacunarity, gain);
|
|
718
722
|
}
|
|
719
|
-
return
|
|
723
|
+
return n;
|
|
720
724
|
}
|
|
721
725
|
`,
|
|
722
726
|
`
|
package/src/lib/wgsl.ts
CHANGED
|
@@ -761,13 +761,17 @@ fn onejsRidged(pIn: vec2f, seed: f32, octaves: i32, lacunarity: f32, gain: f32)
|
|
|
761
761
|
`,
|
|
762
762
|
`
|
|
763
763
|
fn onejsFbmKind(kind: i32, p: vec2f, seed: f32, octaves: i32, lacunarity: f32, gain: f32) -> f32 {
|
|
764
|
+
var n: f32;
|
|
764
765
|
if (kind == 2) {
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
766
|
+
n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
|
|
767
|
+
} else if (kind == 3) {
|
|
768
|
+
n = onejsRidged(p, seed, octaves, lacunarity, gain);
|
|
769
|
+
} else if (kind == 1) {
|
|
770
|
+
n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
|
|
771
|
+
} else {
|
|
772
|
+
n = onejsFbm_f2_f_i_f_f(p, seed, octaves, lacunarity, gain);
|
|
769
773
|
}
|
|
770
|
-
return
|
|
774
|
+
return n;
|
|
771
775
|
}
|
|
772
776
|
`,
|
|
773
777
|
`
|