rift-ds 1.28.0 → 1.29.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.
@@ -1,4 +1,4 @@
1
- import { assemble, uniformNames, VERTEX } from "./assemble.js";
1
+ import { assemble, VERTEX } from "./assemble.js";
2
2
  import { MAX_COLOURS } from "./types.js";
3
3
  const NIGHT_GROUND = [15e-4, 18e-4, 3e-3];
4
4
  function readColours(host, tokens) {
@@ -55,37 +55,36 @@ function drawGlyphs(ramp, font) {
55
55
  }
56
56
  return { strip, count: glyphs.length };
57
57
  }
58
- function compile(gl, type, source) {
58
+ function compile(gl, type, source, report) {
59
59
  const shader = gl.createShader(type);
60
60
  if (!shader) return null;
61
61
  gl.shaderSource(shader, source);
62
62
  gl.compileShader(shader);
63
63
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
64
- console.warn(gl.getShaderInfoLog(shader));
64
+ report(gl.getShaderInfoLog(shader) ?? "");
65
65
  gl.deleteShader(shader);
66
66
  return null;
67
67
  }
68
68
  return shader;
69
69
  }
70
- function valueOf(values, passes, name) {
71
- for (const pass of passes) {
72
- const prefix = `u_${pass.id}_`;
73
- if (!name.startsWith(prefix)) continue;
74
- const state = values.passes[pass.id];
75
- const key = name.slice(prefix.length);
76
- if (key === "on") return state?.on ? 1 : 0;
77
- return state?.params[key] ?? 0;
78
- }
79
- return values.scene[name.slice(2)] ?? 0;
80
- }
81
- function createRenderer(gl, scene, passes) {
82
- const vs = compile(gl, gl.VERTEX_SHADER, VERTEX);
83
- const fs = compile(gl, gl.FRAGMENT_SHADER, assemble(scene, passes));
70
+ function createRenderer(gl, scene, passes, report = (log) => console.warn(log)) {
71
+ const vs = compile(gl, gl.VERTEX_SHADER, VERTEX, report);
72
+ const fs = compile(gl, gl.FRAGMENT_SHADER, assemble(scene, passes), report);
84
73
  const program = gl.createProgram();
85
- if (!vs || !fs || !program) return null;
74
+ const discard = () => {
75
+ gl.deleteProgram(program);
76
+ gl.deleteShader(vs);
77
+ gl.deleteShader(fs);
78
+ return null;
79
+ };
80
+ if (!vs || !fs || !program) return discard();
86
81
  gl.attachShader(program, vs);
87
82
  gl.attachShader(program, fs);
88
83
  gl.linkProgram(program);
84
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
85
+ report(gl.getProgramInfoLog(program) ?? "");
86
+ return discard();
87
+ }
89
88
  gl.useProgram(program);
90
89
  const vao = gl.createVertexArray();
91
90
  gl.bindVertexArray(vao);
@@ -98,7 +97,20 @@ function createRenderer(gl, scene, passes) {
98
97
  const uCols = at("u_col");
99
98
  const uRatio = at("u_ratio");
100
99
  const uGlyphCount = at("u_glyphCount");
101
- const floats = uniformNames(scene, passes).map((name) => [name, at(name)]);
100
+ const floats = [
101
+ ...scene.params.map(
102
+ (param) => [at(`u_${param.key}`), (values) => values.scene[param.key] ?? 0]
103
+ ),
104
+ ...passes.flatMap((pass) => [
105
+ [at(`u_${pass.id}_on`), (values) => values.passes[pass.id]?.on ? 1 : 0],
106
+ ...pass.params.map(
107
+ (param) => [
108
+ at(`u_${pass.id}_${param.key}`),
109
+ (values) => values.passes[pass.id]?.params[param.key] ?? 0
110
+ ]
111
+ )
112
+ ])
113
+ ];
102
114
  const glyphTexture = scene.glyphs ? gl.createTexture() : null;
103
115
  let glyphFont = "";
104
116
  return {
@@ -130,7 +142,7 @@ function createRenderer(gl, scene, passes) {
130
142
  gl.uniform2f(uSize, width, height);
131
143
  gl.uniform1f(uRatio, ratio);
132
144
  gl.uniform1f(uTime, time);
133
- for (const [name, location] of floats) gl.uniform1f(location, valueOf(values, passes, name));
145
+ for (const [location, read] of floats) gl.uniform1f(location, read(values));
134
146
  gl.drawArrays(gl.TRIANGLES, 0, 3);
135
147
  },
136
148
  dispose() {
@@ -72,5 +72,83 @@ export declare const waves: Scene;
72
72
  * gives the colour its depth. Nothing in it has an edge.
73
73
  */
74
74
  export declare const aurora: Scene;
75
+ /**
76
+ * The highway: a straight highway at night, seen from its shoulder, running to a
77
+ * low horizon. It is drawn in long-exposure light trails, every one a
78
+ * straight line to the single point where the road ends, with light
79
+ * streaming along them rather than the lines themselves moving. A cold haze
80
+ * sits on the horizon and drifts over the ground, and a hot point with a
81
+ * flare marks where the trails meet, and a city's lights lie along the
82
+ * horizon under slow clouds and drifting mist.
83
+ */
84
+ export declare const highway: Scene;
75
85
  /** Every scene, in picker order. */
86
+ /**
87
+ * The ocean: open water seen from straight above, with sea life drawn in
88
+ * type swimming through it. It is the one scene with a day of its own, told
89
+ * from the page ground: on a light page it is a shallow tropical sea, the
90
+ * ground showing through turquoise water under a net of sunlight, the
91
+ * animals dark against the sand; on a dark page it is deep water at night,
92
+ * deep blue with the net cut into it as shadow and a patch of moonlight, where the animals
93
+ * are bioluminescent: their characters pulse in their own colour and the
94
+ * water round each body glows with it. The water is drawn
95
+ * in square blocks with a few flat steps of light, as a pixel drawing is,
96
+ * and the animals are type, as are the loose characters that trace the
97
+ * crests of the net and travel with them; nothing in the scene sits still. The water answers the animals: each
98
+ * parts it at the nose and drags a rippled wake behind, the net of light
99
+ * carried along at the animal's own pace, and by night the stirred water
100
+ * glows. The animals wear the theme's accents, each its own and every
101
+ * fish of a school a different one. Each animal is a silhouette (a shark, a ray, a turtle,
102
+ * schools of small fish) read at the centre of every character cell, so it
103
+ * moves a cell at a time, and a cell prints a heavier character the deeper
104
+ * inside the body it lies. Every crossing takes a new heading and lane.
105
+ */
106
+ export declare const ocean: Scene;
107
+ /**
108
+ * The sky: cloud massed overhead and lit by a low sun, painted more than
109
+ * observed. The clouds lie on one flat layer far above, so they are large
110
+ * and slow at the top of the frame and small, close-packed and hazed where
111
+ * the layer runs off to the horizon, and the layer is bent before it is
112
+ * read, so a cloud billows and curls as paint does rather than sitting as
113
+ * a puff. The drama is the light. The sun stands low and the cloud burns
114
+ * with it: each cloud is lit by comparing its thickness with the cloud a
115
+ * step towards the light, which gives it a hot side and a shaded one
116
+ * without a ray being marched, and the colour runs from the hot side
117
+ * through an ember middle to a cold shade; where cloud is thin in front of
118
+ * the sun the light comes through it, and the strip of sky on the horizon
119
+ * under the cloud burns hardest of all. Like the ocean it has a day of its own, told from the page
120
+ * ground: on a light page a golden hour, cream and rose cloud with a deep
121
+ * blue shade over a sky that warms to the horizon; on a dark page the
122
+ * last of a sunset with the night already overhead: the sky near black
123
+ * with stars, heavy cloud standing as silhouettes darker still, burning
124
+ * like coals only where it faces the sun, over a horizon on fire. The sky is the fourth ambient role cooled with a
125
+ * little of the second, the sun the first, the fire in the cloud the fifth
126
+ * and sixth and its shade the third, so a theme recolours it. Contrails
127
+ * cross the far sky low over the horizon, well above the weather, so
128
+ * every cloud stands in front of them, and they hold the sun's colour;
129
+ * one more is still being laid, high in the frame, by a plane a few pixels
130
+ * long. Deep blue shows through overhead in slow patches.
131
+ */
132
+ export declare const sky: Scene;
133
+ /**
134
+ * The galaxy: a spiral seen at a slant, deep in a field of stars. A disc
135
+ * of light thins outwards from a hot core, wound into two arms. The arms
136
+ * are drawn on the disc unwound, where each lies straight, so the cloud
137
+ * in them, the dust lanes cut along their inner edges and the knots of
138
+ * young stars strung down them all run with the arm, in filaments, and
139
+ * the dust is heavier on the side of the disc tipped towards the eye. The
140
+ * core is a bulge rounder than the disc, standing out of it, near white
141
+ * at its heart in a wide halo of the theme's warm colours, and the disc
142
+ * cools through the theme's colours to its rim. Two companions keep it
143
+ * company, a small soft ellipse off the disc and a tight bright one
144
+ * beside the core. The stars are four depths of points, one to a cell at
145
+ * most, thick in some parts of the sky and thin in others: a dust of
146
+ * faint ones, two scatters of brighter ones and a few near ones with a
147
+ * glow of their own, all twinkling slowly. Behind it all a band of lit
148
+ * gas crosses the sky, billowed and creeping, with a rift of dust down
149
+ * its middle and the stars crowded into it. The arms turn, too slowly to
150
+ * see move. Stars are points, finer than soft light, so the scene draws
151
+ * at up to two pixels per CSS pixel and sizes everything in CSS pixels.
152
+ */
153
+ export declare const galaxy: Scene;
76
154
  export declare const SCENES: Scene[];