Model loading · function
readRadianceHdr
Read a Radiance RGBE file into linear radiance.
Explained in Importing models.
function readRadianceHdr(bytes: Uint8Array): RadianceImageimport { readRadianceHdr } from '@driftengine/assets';Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array |
In depth
Pure, and it takes bytes rather than a URL. It knows nothing about a device, a fetch or a texture, which is what lets it be tested exactly and what keeps the fetching decision — cache headers, retries, where the file lives — with the consumer who has to make it.
Both scanline encodings, because only one of them is optional in practice. A file narrower than 8 or wider than 0x7fff stores flat RGBE quadruples; everything else is new-style run-length, and that is every environment map anybody actually has. A decoder that handles only the flat path passes a hand-built test and fails on every real file.
Every refusal names what it found. AGENTS.md requires failing loudly at load with an
actionable message: a decoder that quietly answers black for a header it does not recognise
hands a scene an environment of nothing, which is indistinguishable from a probe that has not
baked yet and is diagnosed as the renderer's fault.
What it costs is width * height * 12 bytes for the result, which at 2048x1024 is 25 MB
held while the faces are built. What would make it wrong is a consumer streaming an
environment larger than memory; this reads whole files, and a tiled format is what that consumer
wants — which is one of the reasons KTX2 is named and deliberately not taken.