Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

R3F24: the white picture a ShaderMaterial gets for a texture with no picture (shader.ts WHITE) decodes: it was a broken PNG (its data cut short, its CRC wrong), so the engine refused every material given it and drew it in its colour. test/shader.test.ts: both stand-in pictures decode (white, opaque black)

shinyobjectz3f37f7c2a2cf
diff --git a/sdk/r3f/src/input/shader.ts b/sdk/r3f/src/input/shader.ts
index 6169acb0..f73d8748 100644
--- a/sdk/r3f/src/input/shader.ts
+++ b/sdk/r3f/src/input/shader.ts
@@ -142,9 +142,9 @@ function valueOf(v: unknown): number | boolean | number[] | undefined {
}
/** a picture three has no file for (a render target's): one white pixel, so the shader still runs */
-const WHITE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=";
+export const WHITE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/Wj6HMwAAAAASUVORK5CYII=";
// a 1x1 opaque black PNG: what WebGL reads from a sampler with no texture bound
-const BLACK = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQI12NgYGD4DwABBAEApOCsMQAAAABJRU5ErkJggg==";
+export const BLACK = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQI12NgYGD4DwABBAEApOCsMQAAAABJRU5ErkJggg==";
const warned = new Set<string>();
function warnOnce(k: string, why: string) {
diff --git a/sdk/r3f/test/shader.test.ts b/sdk/r3f/test/shader.test.ts
index 608160fd..9ca5e394 100644
--- a/sdk/r3f/test/shader.test.ts
+++ b/sdk/r3f/test/shader.test.ts
@@ -54,3 +54,20 @@ describe("ShaderMaterial → raea's ThreeShaderMaterial", () => {
expect(ownAttributes(g)).toEqual({ aRandom: { size: 1, values: [0.25, 0.75] } });
});
});
+
+describe("the pictures a ShaderMaterial is given where three has none", () => {
+ test("are PNGs that decode: one white pixel, one opaque black", async () => {
+ const { inflateSync, crc32 } = await import("node:zlib");
+ const { WHITE, BLACK } = await import("../src/input/shader");
+ const pixel = (url: string) => {
+ const png = Buffer.from(url.split(",")[1], "base64");
+ const at = png.indexOf("IDAT");
+ const len = png.readUInt32BE(at - 4);
+ // the chunk's CRC covers its type and its data
+ expect(crc32(png.subarray(at, at + 4 + len))).toBe(png.readUInt32BE(at + 4 + len));
+ return [...inflateSync(png.subarray(at + 4, at + 4 + len))];
+ };
+ expect(pixel(WHITE)).toEqual([0, 255, 255, 255, 255]);
+ expect(pixel(BLACK)).toEqual([0, 0, 0, 0, 255]);
+ });
+});