Skip to content

Conversation

@atlv24
Copy link
Contributor

@atlv24 atlv24 commented Jul 25, 2025

Objective

Solution

  • Don't embed stbn.ktx2, just load it for now
  • Gate gen env maps by limit checks
  • Extract a plugin to do this cleanly
  • Only load stbn.ktx2 when its needed

Testing

  • reflection_probes example
  • someone please test webgl2

@atlv24 atlv24 added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen P-Regression Functionality that used to work but no longer does. Add a test for this! O-WebGL2 Specific to the WebGL2 render API S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 25, 2025
@atlv24 atlv24 added the P-Crash A sudden unexpected crash label Jul 25, 2025
@rparrett
Copy link
Contributor

This would require users to download stbn.ktx2 and place it in their own assets/textures directory, which is probably not what we want.

@mate-h
Copy link
Contributor

mate-h commented Jul 25, 2025

Thank you for the quick turnaround. I tested the reflection probe example on mac, webgpu and webgl. All works as expected. The diff also looks good to me but good point about using assets/textures folder.
Current and future use cases for the blue noise:

  • realtime environment map filtering GGX
  • solari path tracing and ReSTIR GGX
  • raymarching algorithm jittering for volumetrics, atmosphere

A couple of solutions i have in mind:

  • in the immediate term, to address the issue with the Bevy build output binary size the keep thus current PR as is
  • we maybe need to generate the bluenoise at runtime on the CPU, however could introduce a new dependency or new code to maintain.
  • just reduce the overall size of the bluenoise to 32x32 and keep it always in the binary
  • hide it behind a feature flag. This means use cases I mentioned above would need to be run with the feature flag enabled

@atlv24
Copy link
Contributor Author

atlv24 commented Jul 25, 2025

Id rather leave improving DX to another PR, given that the alternative atm is a revert. I have a few ideas but im not sure which is best. Any are better than a revert though :p

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. The plugin naming is not something I will block on but if people agree with me then it would be nice to change before merging.

One idea for a follow-up - we could add a feature to optionally compile-in the texture instead of loading it from an asset directory. That would give people the option of that convenience, though perhaps it has other downsides like ram usage for the binary, unless that part can be paged out after upload to vram.

@atlv24 atlv24 force-pushed the ad/webgl2-gen-envmaps branch from ac43819 to af6eadd Compare July 25, 2025 17:55
pub texture: Handle<Image>,
}

impl FromWorld for Bluenoise {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this a system rather than a FromWorld impl? Something like init_blue_noise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seemed to be pretty sensitive to ordering, i dont want to figure out porting this to RenderStartup in this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm okay with porting it later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this declaration for FromWorld and put the code block back into PBR plugin with a conditional feature flag.

Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if the texture was embedded but gated by a feature flag and if someone spawns a GeneratedEnvironmentMapLight component without the feature flag we log a warning saying they need to enable the feature. A bit like what the tonemapping_luts feature flag does. The current approach requires user to copy the texture which is a bit less nice but not a blocker.

With that said, the PR as is does fix the issue, we can always implement the feature flag thing later.

@mate-h
Copy link
Contributor

mate-h commented Jul 26, 2025

I created a PR against this branch to address some of @IceSentry feedback about using feature flags. I also added a fallback to a RNG based noise which still looks decent. Since this PR already has all approvals I don't consider this a blocker, can be reviewed/merged as a separate PR as well. I will get feedback on my proposed changes from @atlv24 when I get a chance.

Add blue noise texture feature and fall back to rng
@github-actions
Copy link
Contributor

You added a new feature but didn't update the readme. Please run cargo run -p build-templated-pages -- update features to update it, and commit the file change.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 27, 2025
debug = ["bevy_internal/debug"]

# Include spatio-temporal blue noise KTX2 file used by generated environment maps, Solari and atmosphere
bluenoise_texture = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be enabling this feature in other features, e.g. for solari or env maps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not needed in solari just yet, we'll let Jasmine add the feature when she starts using it. And gen env maps dont need this either thanks to the fallback, so for now its fine i believe

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 27, 2025
@atlv24
Copy link
Contributor Author

atlv24 commented Jul 27, 2025

@mate-h thanks for fixing CI! i think we're good to go

Merged via the queue into bevyengine:main with commit ae1e094 Jul 27, 2025
38 checks passed
mate-h added a commit to mate-h/bevy that referenced this pull request Jul 28, 2025
# Objective

- bevyengine#19076 (comment)
broke webgl2 and bloated binary size by a megabyte
- Fixes bevyengine#20276

## Solution

- Don't embed stbn.ktx2, just load it for now
- Gate gen env maps by limit checks
- Extract a plugin to do this cleanly
- Only load stbn.ktx2 when its needed

## Testing

- reflection_probes example
- someone please test webgl2

---------

Co-authored-by: Máté Homolya <mate.homolya@gmail.com>
tychedelia pushed a commit to tychedelia/bevy that referenced this pull request Jul 31, 2025
# Objective

- bevyengine#19076 (comment)
broke webgl2 and bloated binary size by a megabyte
- Fixes bevyengine#20276

## Solution

- Don't embed stbn.ktx2, just load it for now
- Gate gen env maps by limit checks
- Extract a plugin to do this cleanly
- Only load stbn.ktx2 when its needed

## Testing

- reflection_probes example
- someone please test webgl2

---------

Co-authored-by: Máté Homolya <mate.homolya@gmail.com>
@atlv24 atlv24 deleted the ad/webgl2-gen-envmaps branch August 1, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-WebGL2 Specific to the WebGL2 render API P-Crash A sudden unexpected crash P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

WebGL2 broken: no compute shaders

7 participants