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

shadow_biases: Support moving the light position and resetting biases #10185

Merged
merged 3 commits into from Oct 19, 2023

Conversation

superdump
Copy link
Contributor

Objective

  • Make it possible to move the light position around in the shadow_biases example
  • Also support resetting the depth/normal biases to the engine defaults, or zero.

Solution

  • The light position is displayed in the text overlay.
  • The light position can be adjusted with left/right/up/down/pgup/pgdown.
  • The depth/normal biases can be reset to defaults by pressing R, or to zero by pressing Z.

@robtfm
Copy link
Contributor

robtfm commented Oct 19, 2023

just for sanity's sake could we

  • set the text once
  • change the color to something readable against white
  • change the wording for the filter method so it specifies it's for directional
diff --git a/examples/3d/shadow_biases.rs b/examples/3d/shadow_biases.rs
index 4553bf791..b62ece509 100644
--- a/examples/3d/shadow_biases.rs
+++ b/examples/3d/shadow_biases.rs
@@ -111,6 +111,7 @@ fn setup(
 
     let style = TextStyle {
         font_size: 20.,
+        color: Color::rgb(1.0, 0.0, 0.5),
         ..default()
     };
     commands.spawn(
@@ -125,7 +126,7 @@ fn setup(
             ),
             TextSection::new("DirectionalLight", style.clone()),
             TextSection::new("]\n", style.clone()),
-            TextSection::new("F     - switch between filter methods [", style.clone()),
+            TextSection::new("F     - switch directional light filter methods [", style.clone()),
             TextSection::new("Hardware2x2", style.clone()),
             TextSection::new("]\n", style.clone()),
             TextSection::new("1/2   - change point light depth bias [", style.clone()),
@@ -269,41 +270,30 @@ fn adjust_point_light_biases(
     for mut light in &mut query {
         if input.just_pressed(KeyCode::Key1) {
             light.shadow_depth_bias -= depth_bias_step_size;
-            example_text.single_mut().sections[11].value =
-                format!("{:.2}", light.shadow_depth_bias);
         }
         if input.just_pressed(KeyCode::Key2) {
             light.shadow_depth_bias += depth_bias_step_size;
-            example_text.single_mut().sections[11].value =
-                format!("{:.2}", light.shadow_depth_bias);
         }
         if input.just_pressed(KeyCode::Key3) {
             light.shadow_normal_bias -= normal_bias_step_size;
-            example_text.single_mut().sections[14].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::Key4) {
             light.shadow_normal_bias += normal_bias_step_size;
-            example_text.single_mut().sections[14].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::R) {
             light.shadow_depth_bias = PointLight::DEFAULT_SHADOW_DEPTH_BIAS;
-            example_text.single_mut().sections[11].value =
-                format!("{:.2}", light.shadow_depth_bias);
             light.shadow_normal_bias = PointLight::DEFAULT_SHADOW_NORMAL_BIAS;
-            example_text.single_mut().sections[14].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::Z) {
             light.shadow_depth_bias = 0.0;
-            example_text.single_mut().sections[11].value =
-                format!("{:.2}", light.shadow_depth_bias);
             light.shadow_normal_bias = 0.0;
-            example_text.single_mut().sections[14].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
-    }
+
+        example_text.single_mut().sections[11].value =
+            format!("{:.2}", light.shadow_depth_bias);
+        example_text.single_mut().sections[14].value =
+            format!("{:.1}", light.shadow_normal_bias);
+}
 }
 
 fn adjust_directional_light_biases(
@@ -316,40 +306,29 @@ fn adjust_directional_light_biases(
     for mut light in &mut query {
         if input.just_pressed(KeyCode::Key5) {
             light.shadow_depth_bias -= depth_bias_step_size;
-            example_text.single_mut().sections[17].value =
-                format!("{:.2}", light.shadow_depth_bias);
         }
         if input.just_pressed(KeyCode::Key6) {
             light.shadow_depth_bias += depth_bias_step_size;
-            example_text.single_mut().sections[17].value =
-                format!("{:.2}", light.shadow_depth_bias);
         }
         if input.just_pressed(KeyCode::Key7) {
             light.shadow_normal_bias -= normal_bias_step_size;
-            example_text.single_mut().sections[20].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::Key8) {
             light.shadow_normal_bias += normal_bias_step_size;
-            example_text.single_mut().sections[20].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::R) {
             light.shadow_depth_bias = DirectionalLight::DEFAULT_SHADOW_DEPTH_BIAS;
-            example_text.single_mut().sections[17].value =
-                format!("{:.2}", light.shadow_depth_bias);
             light.shadow_normal_bias = DirectionalLight::DEFAULT_SHADOW_NORMAL_BIAS;
-            example_text.single_mut().sections[20].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
         if input.just_pressed(KeyCode::Z) {
             light.shadow_depth_bias = 0.0;
-            example_text.single_mut().sections[17].value =
-                format!("{:.2}", light.shadow_depth_bias);
             light.shadow_normal_bias = 0.0;
-            example_text.single_mut().sections[20].value =
-                format!("{:.1}", light.shadow_normal_bias);
         }
+
+        example_text.single_mut().sections[17].value =
+            format!("{:.2}", light.shadow_depth_bias);
+        example_text.single_mut().sections[20].value =
+            format!("{:.1}", light.shadow_normal_bias);
     }
 }

@robtfm
Copy link
Contributor

robtfm commented Oct 19, 2023

and maybe the spheres could descend in y so that peter panning shows up?

@superdump superdump added this pull request to the merge queue Oct 19, 2023
Merged via the queue into bevyengine:main with commit 15c54b5 Oct 19, 2023
21 checks passed
ameknite pushed a commit to ameknite/bevy that referenced this pull request Nov 6, 2023
…bevyengine#10185)

# Objective

- Make it possible to move the light position around in the
`shadow_biases` example
- Also support resetting the depth/normal biases to the engine defaults,
or zero.

## Solution

- The light position is displayed in the text overlay.
- The light position can be adjusted with
left/right/up/down/pgup/pgdown.
- The depth/normal biases can be reset to defaults by pressing R, or to
zero by pressing Z.

---------

Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
…bevyengine#10185)

# Objective

- Make it possible to move the light position around in the
`shadow_biases` example
- Also support resetting the depth/normal biases to the engine defaults,
or zero.

## Solution

- The light position is displayed in the text overlay.
- The light position can be adjusted with
left/right/up/down/pgup/pgdown.
- The depth/normal biases can be reset to defaults by pressing R, or to
zero by pressing Z.

---------

Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants