Rework texture formats so shaders read every data type in the same units

Open
#852 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start with createBandTexture in packages/deck.gl-geotiff/src/multi-cog-layer.ts, inferRenderPipeline and FORMAT_TABLE in the GeoTIFF package, then follow the sampling and nodata modules. Compare the three options in the issue and trace how each data type reaches shader code. Done means one documented unit convention works for every data type, including signed integers and floats, across the affected pipelines.

Written by the indexing model from the issue text.

Description

[!NOTE]
This issue was written by Claude (Claude Code), not by @kylebarron.

The units a shader reads a sample in depend on the raster's data type, and COGLayer's default pipeline renders only unsigned integers. This tracks reworking texture formats so that every data type reaches the shaders in the same units, and COGLayer can render signed integers and floats.

Today

MultiCOGLayer (createBandTexture):

  • uint8 and uint16 upload as r8unorm and r16unorm, so shaders read 0-1. Without EXT_texture_norm16, as in Firefox, uint16 goes to r32float divided by 65535, and stays 0-1 (#773).
  • Every other type uploads as r32float with raw values (#777). The renderPipeline docs mark these types as experimental, with units "likely to change".

COGLayer's default pipeline (inferRenderPipeline) handles only unsigned integers, and throws for signed integers and floats. The format table it uses (inferScalarKind, FORMAT_TABLE):

  • maps every unsigned type to a unorm format, so shaders read 0-1. There's no 32-bit unorm format, so uint32 throws.
  • maps signed integers to integer formats such as r16sint. CreateTexture samples with a sampler2D, which can't read integer textures.
  • maps floats to r32float, with raw values.
  • has uint entries, such as r8uint, that no input reaches.

The shader modules inherit the mix:

  • COGLayer scales nodata into 0-1 before FilterNoDataVal. For raw data, the same module takes the raw value.
  • LinearRescale's docs tell Sentinel-2 users to rescale 0-0.15 for reflectance 0-10000, because of r16unorm.
  • So a pipeline written for one data type gives wrong results for another, without an error.

The Zarr examples upload their own textures, as r32float with raw values.

Options

  1. Raw values for every data type (my pick). Shaders always read the data's own values, so nodata values, rescale ranges and filters are given in the data's units.
    • Storage can stay compact. uint8 and uint16 can stay in r8unorm and r16unorm, with the sampling module multiplying by 255 or 65535 to get the values back. Those formats can also be linearly filtered everywhere, which r32float needs float32-filterable for.
    • Signed integers and uint32 go to r32float, as MultiCOGLayer does today. #773's fallback would upload raw floats.
    • Breaking: the ranges in every uint8 and uint16 pipeline change, so this should land before 1.0.
  2. Normalized integers, raw floats, as today, but complete: signed integers as snorm (-1 to 1), or shifted into 0-1, as #180 did with a snorm-to-unorm module. Unsigned pipelines don't change, but floats and integers still differ, and the units of integer data depend on its bit width.
  3. Keep today's rules and document them, and add signed integers and floats to COGLayer's default pipeline only.

Related: #160 (nodata precision for floats), #772 (per-band uploads in COGLayer).

🤖 Written by Claude Code

Dominant language
TypeScript
Stars
240
Forks
34
Avg merge
17h 24m
Merged PRs (30d)
62

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from developmentseed/deck.gl-raster

All issues in developmentseed/deck.gl-raster

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.