Skip to content
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

wasm: Page shows behind skybox when skybox brightness is low #12740

Closed
rparrett opened this issue Mar 26, 2024 · 1 comment · Fixed by #12888
Closed

wasm: Page shows behind skybox when skybox brightness is low #12740

rparrett opened this issue Mar 26, 2024 · 1 comment · Fixed by #12888
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Milestone

Comments

@rparrett
Copy link
Contributor

Bevy version

0.13.1, main

Relevant system information

AdapterInfo { name: "ANGLE (Apple, ANGLE Metal Renderer: Apple M1 Max, Unspecified Version)", vendor: 4203, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Gl }

What you did

  • With wasm-server-runner
  • Change brightness in examples/3d/skybox.rs to 100..
  • cargo run --example skybox --target=wasm32-unknown-unknown
  • Using browser dev tools, add the following style to body:
    background: repeating-linear-gradient(-45deg, rgb(255, 200, 200), rgb(255, 200, 200) 10px, white 10px, white 20px);

What went wrong

Page background can be seen through the skybox.

image

Additional information

The following patch seems to fix the problem, but I'm not sure if it's proper.

diff --git a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
index 593b440ee..37a66cfba 100644
--- a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
+++ b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
@@ -72,5 +72,5 @@ fn skybox_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
     let ray_direction = coords_to_ray_direction(in.position.xy, view.viewport);
 
     // Cube maps are left-handed so we negate the z coordinate.
-    return textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0)) * uniforms.brightness;
+    return vec4<f32>(textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0)).rgb * uniforms.brightness, 1.0);
 }
@rparrett rparrett added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 26, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 26, 2024
@SolarLiner
Copy link
Contributor

SolarLiner commented Mar 27, 2024

The bug is in how the brightness is wrongly applied to the alpha channel, so the fix is the correct one; however your fix also makes it impossible to do transparent backgrouns when that is desired, because the alpha channel is now hardcoded to 1.

The following patch resolves that issue (not tested):

diff --git a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
index 593b440ee..37a66cfba 100644
--- a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
+++ b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl
@@ -72,5 +72,5 @@ fn skybox_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
     let ray_direction = coords_to_ray_direction(in.position.xy, view.viewport);
 
     // Cube maps are left-handed so we negate the z coordinate.
-    return textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0)) * uniforms.brightness;
+    let out = textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0));
+    out.rgb *= uniforms.brightness;
+    return out;
 }

@JMS55 JMS55 added this to the 0.13.2 milestone Mar 27, 2024
@mockersf mockersf modified the milestones: 0.13.2, 0.13.3 Apr 4, 2024
github-merge-queue bot pushed a commit that referenced this issue Apr 6, 2024
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants