Repository navigation
fix(examples): correct NDVI range filter in naip-mosaic - #522
Merged
Merged
Conversation
The `ndvi` shader module pre-normalized raw NDVI from [-1, 1] to [0, 1]
(`color.r = (ndvi + 1.0) / 2.0`) so the `Colormap` module — which samples
`color.r` as a [0, 1] index — read it correctly. But `ndviFilter` runs after
`ndvi` and compared the already-normalized `color.r` against `ndviMin`/`ndviMax`
that come straight from the slider, which is in raw NDVI units [-1, 1]. A slider
value of 0.5 therefore filtered at raw NDVI 0.0, not 0.5.
Fix: have the `ndvi` module write the raw value (`color.r = (nir - red) /
(nir + red)`, range [-1, 1]) so `ndviFilter` compares like-for-like, then insert
`{ module: LinearRescale, props: { rescaleMin: -1, rescaleMax: 1 } }` into the
`renderNDVI` pipeline right before `Colormap` to remap to [0, 1] for the lookup.
Also switches `ndviFilter.getUniforms` from `||` to `??` so a slider min/max of
exactly `0` isn't replaced by the `-1`/`1` defaults.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before:
See how the filter and colormap isn't lining up with what's displayed? The colormap implies that no blue pixels should be rendered, but a bunch of blue pixels are still being rendered...

This is because we were accidentally rescaling the NDVI output with range
[-1, 1]to range[0, 1]before applying the filtering.After:
Now, we ensure that we apply the filter before doing any filtering:
Bug
In the
naip-mosaicexample, the NDVI render pipeline was:The
ndvishader module pre-normalized raw NDVI from[-1, 1]to[0, 1](color.r = (ndvi + 1.0) / 2.0) so theColormapmodule — which samplescolor.ras a[0, 1]index — read it correctly. ButndviFilterruns afterndviand compared the already-normalizedcolor.r ∈ [0, 1]againstndviMin/ndviMaxthat come straight from the NDVI-range slider, which is in raw NDVI units[-1, 1]. So a slider value of0.5actually filtered at raw NDVI0.0, not0.5— the filter was effectively(ndviMin + 1) / 2…(ndviMax + 1) / 2.Fix
ndvimodule now writes the raw value (color.r = (nir - red) / (nir + red), range[-1, 1]) sondviFiltercompares like-for-like.{ module: LinearRescale, props: { rescaleMin: -1, rescaleMax: 1 } }into therenderNDVIpipeline right beforeColormap, remapping[-1, 1] → [0, 1]for the colormap-texture lookup. Pipeline is nowCreateTexture → ndvi → ndviFilter → LinearRescale → Colormap → SetAlpha1.ndviFilter.getUniformsfrom||to??so a slider min/max of exactly0isn't silently replaced by the-1/1defaults.The slider stays
[-1, 1]— that's the correct user-facing range.Verification
pnpm --filter naip-mosaic-example typecheck✓pnpm --filter naip-mosaic-example build✓pnpm check✓🤖 Generated with Claude Code