Repository navigation
feat: cap the size of model textures at load (setMaxTextureSize) #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ declare function bloom_set_sharpen_strength(strength: number): number; | |
| declare function bloom_set_ssgi_probe_spacing(pixels: number): number; | ||
| declare function bloom_set_shadow_distance(metres: number): number; | ||
| declare function bloom_set_shadow_cascade_stagger(on: number): number; | ||
| declare function bloom_set_max_texture_size(px: number): number; | ||
| declare function bloom_set_texture_streaming(budgetMb: number): number; | ||
| declare function bloom_set_shadow_filter_4tap(on: number): number; | ||
| declare function bloom_set_shadow_map_size(texels: number): number; | ||
|
|
@@ -862,6 +863,19 @@ export function setShadowCascadeStagger(on: boolean): boolean { | |
| return bloom_set_shadow_cascade_stagger(on ? 1 : 0) !== 0; | ||
| } | ||
|
|
||
| /** | ||
| * The largest edge, in pixels, a model texture keeps (0 = no cap, the | ||
| * default). A PNG / JPEG / DDS texture in a glTF model that is larger is | ||
| * downscaled by a power of two when it is decoded, which is the same as | ||
| * dropping its top mip levels: 4096 px RGBA with mips is 85 MB, 2048 is 21 MB, | ||
| * 1024 is 5 MB. Call it BEFORE loading models; it applies to models loaded | ||
| * afterwards. KTX2 block-compressed textures are left alone. For machines | ||
|
Comment on lines
+871
to
+872
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply the texture cap when a cached model is reloaded. While the first handle is loaded, a second Suggested fix
|
||
| * with little video memory, or integrated GPUs sharing system memory. | ||
| */ | ||
| export function setMaxTextureSize(px: number): boolean { | ||
| return bloom_set_max_texture_size(px) !== 0; | ||
| } | ||
|
|
||
| /** | ||
| * Texture streaming: keep only the mip levels each texture needs at its | ||
| * present distance, inside a budget of `budgetMb` megabytes (0 = off, the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Premultiply color RGB before filtering transparent textures.
For opaque red beside transparent black, reducing 2x1 to 1x1 produces approximately
(128,0,0,128). Transparent black therefore darkens the visible red. glTF supplies unassociated base-color RGB, butimage::imageops::resizeexpects premultiplied alpha for varying-alpha images. (raw.githubusercontent.com)For color textures with transparency, premultiply RGB before resizing. Unpremultiply the result afterward and handle zero alpha explicitly. Keep opaque textures and non-color data unchanged.
Filter capped color textures in linear light.
cap_rgbadownscales base-color bytes withFilterType::Trianglein encoded sRGB space. For a 2x1 opaque black/white texture capped to 1x1, this gives about 128. Averaging in linear light and encoding back gives about 188. The cap therefore darkens capped color textures. Existing mip generation for color images already filters in linear light, so this darkening comes from the cap alone.Pass the color role into
decode_texture_bytesandcap_rgba. For sRGB color images, convert RGB to linear light before resizing, then encode it back to sRGB. Keep normal, metallic, roughness, and other data images linear. The loader already computesis_srgbfor each image (models_gltf.rs:527), and that value is available at the decode calls atmodels_gltf.rs:549andmodels_gltf.rs:610.