Compare commits

...

6 Commits

Author SHA1 Message Date
Carter Anderson
b995b4662a bump all other crates to 0.8.1 2022-08-23 12:30:12 -07:00
Carter Anderson
2fa7b3b6d0 Release 0.8.1 2022-08-18 17:02:20 -07:00
Robert Swain
a7ece4ce85 bevy_pbr: Fix tangent and normal normalization (#5666)
# Objective

- Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly.
- Fixes #5514 by ensuring the tangent basis matrix (TBN) is orthonormal

## Solution

- Normalize the world normal in the vertex stage and not the fragment stage
- Normalize the world tangent xyz in the vertex stage
- Take into account the sign of the determinant of the local to world matrix when calculating the bitangent

---

## Changelog

- Fixed - scaling a model that uses normal mapping now has correct lighting again
2022-08-18 16:54:01 -07:00
Robert Swain
b3ab4fc2b3 Sync up bevy_sprite and bevy_ui shader View struct (#5531)
# Objective

- Similar to #5512 , the `View` struct definition in the shaders in `bevy_sprite` and `bevy_ui` were out of sync with the rust-side `ViewUniform`. Only `view_proj` was being used and is the first member and as those shaders are not customisable it makes little difference in practice, unlike for `Mesh2d`.

## Solution

- Sync shader `View` struct definition in `bevy_sprite` and `bevy_ui` with the correct definition that matches `ViewUniform`
2022-08-18 16:53:46 -07:00
François
12daeebf83 fix order of exit/close window systems (#5558)
# Objective

Fixes #5384 and maybe other issues around window closing/app not exiting

## Solution

There are three systems involved in exiting when closing a window:
- `close_when_requested` asking Winit to close the window in stage `Update`
- `exit_on_all_closed` exiting when no window remains opened in stage `Update`
- `change_window` removing windows that are closed in stage `PostUpdate`

This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default)

This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
2022-08-18 16:53:34 -07:00
Azervu
52ccd768c5 Fix View by adding missing fields present in ViewUniform (#5512)
# Objective

View mesh2d_view_types.wgsl was missing a couple of fields present in bevy::render::ViewUniform, causing rendering issues for shaders using later fields.

## Solution
Solved by adding the fields in question
2022-08-18 16:52:58 -07:00
47 changed files with 125 additions and 62 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "bevy"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
categories = ["game-engines", "graphics", "gui", "rendering"]
description = "A refreshingly simple data-driven game engine and app framework"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_animation"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides animation functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_app"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides core App functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_asset"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides asset functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_audio"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides audio functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_core"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides core functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_core_pipeline"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = [
"Bevy Contributors <bevyengine@gmail.com>",

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_derive"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides derive implementations for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_diagnostic"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides diagnostic functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_dylib"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Force the Bevy Engine to be dynamically linked for faster linking"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_dynamic_plugin"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides dynamic plugin loading capabilities for non-wasm platforms"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_ecs"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Bevy Engine's entity component system"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_ecs_macros"
version = "0.8.0"
version = "0.8.1"
description = "Bevy ECS Macros"
edition = "2021"
license = "MIT OR Apache-2.0"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_encase_derive"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Bevy derive macro for encase"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_gilrs"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Gamepad system made using Gilrs for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_gltf"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Bevy Engine GLTF loading"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_hierarchy"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides hierarchy functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_input"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides input functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_internal"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "An internal Bevy crate used to facilitate optional dynamic linking via the 'dynamic' feature"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_log"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides logging for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_macro_utils"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "A collection of utils for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_math"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides math functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_mikktspace"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Benjamin Wasty <benny.wasty@gmail.com>", "David Harvey-Macaulay <alteous@outlook.com>", "Layl Bongers <LaylConway@users.noreply.github.com>"]
description = "Mikkelsen tangent space algorithm"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_pbr"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Adds PBR rendering to Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -9,7 +9,7 @@ use bevy_ecs::{
prelude::*,
system::{lifetimeless::*, SystemParamItem, SystemState},
};
use bevy_math::{Mat4, Vec2};
use bevy_math::{Mat3A, Mat4, Vec2};
use bevy_reflect::TypeUuid;
use bevy_render::{
extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin},
@ -117,6 +117,9 @@ bitflags::bitflags! {
#[repr(transparent)]
struct MeshFlags: u32 {
const SHADOW_RECEIVER = (1 << 0);
// Indicates the sign of the determinant of the 3x3 model matrix. If the sign is positive,
// then the flag should be set, else it should not be set.
const SIGN_DETERMINANT_MODEL_3X3 = (1 << 31);
const NONE = 0;
const UNINITIALIZED = 0xFFFF;
}
@ -143,13 +146,16 @@ pub fn extract_meshes(
for (entity, _, transform, handle, not_receiver, not_caster) in visible_meshes {
let transform = transform.compute_matrix();
let shadow_receiver_flags = if not_receiver.is_some() {
MeshFlags::empty().bits
let mut flags = if not_receiver.is_some() {
MeshFlags::empty()
} else {
MeshFlags::SHADOW_RECEIVER.bits
MeshFlags::SHADOW_RECEIVER
};
if Mat3A::from_mat4(transform).determinant().is_sign_positive() {
flags |= MeshFlags::SIGN_DETERMINANT_MODEL_3X3;
}
let uniform = MeshUniform {
flags: shadow_receiver_flags,
flags: flags.bits,
transform,
inverse_transpose_model: transform.inverse().transpose(),
};

View File

@ -17,20 +17,47 @@ fn mesh_position_local_to_clip(model: mat4x4<f32>, vertex_position: vec4<f32>) -
}
fn mesh_normal_local_to_world(vertex_normal: vec3<f32>) -> vec3<f32> {
return mat3x3<f32>(
mesh.inverse_transpose_model[0].xyz,
mesh.inverse_transpose_model[1].xyz,
mesh.inverse_transpose_model[2].xyz
) * vertex_normal;
// NOTE: The mikktspace method of normal mapping requires that the world normal is
// re-normalized in the vertex shader to match the way mikktspace bakes vertex tangents
// and normal maps so that the exact inverse process is applied when shading. Blender, Unity,
// Unreal Engine, Godot, and more all use the mikktspace method. Do not change this code
// unless you really know what you are doing.
// http://www.mikktspace.com/
return normalize(
mat3x3<f32>(
mesh.inverse_transpose_model[0].xyz,
mesh.inverse_transpose_model[1].xyz,
mesh.inverse_transpose_model[2].xyz
) * vertex_normal
);
}
// Calculates the sign of the determinant of the 3x3 model matrix based on a
// mesh flag
fn sign_determinant_model_3x3() -> f32 {
// bool(u32) is false if 0u else true
// f32(bool) is 1.0 if true else 0.0
// * 2.0 - 1.0 remaps 0.0 or 1.0 to -1.0 or 1.0 respectively
return f32(bool(mesh.flags & MESH_FLAGS_SIGN_DETERMINANT_MODEL_3X3_BIT)) * 2.0 - 1.0;
}
fn mesh_tangent_local_to_world(model: mat4x4<f32>, vertex_tangent: vec4<f32>) -> vec4<f32> {
// NOTE: The mikktspace method of normal mapping requires that the world tangent is
// re-normalized in the vertex shader to match the way mikktspace bakes vertex tangents
// and normal maps so that the exact inverse process is applied when shading. Blender, Unity,
// Unreal Engine, Godot, and more all use the mikktspace method. Do not change this code
// unless you really know what you are doing.
// http://www.mikktspace.com/
return vec4<f32>(
mat3x3<f32>(
model[0].xyz,
model[1].xyz,
model[2].xyz
) * vertex_tangent.xyz,
vertex_tangent.w
normalize(
mat3x3<f32>(
model[0].xyz,
model[1].xyz,
model[2].xyz
) * vertex_tangent.xyz
),
// NOTE: Multiplying by the sign of the determinant of the 3x3 model matrix accounts for
// situations such as negative scaling.
vertex_tangent.w * sign_determinant_model_3x3()
);
}

View File

@ -14,3 +14,5 @@ struct SkinnedMesh {
#endif
let MESH_FLAGS_SHADOW_RECEIVER_BIT: u32 = 1u;
// 2^31 - if the flag is set, the sign is positive, else it is negative
let MESH_FLAGS_SIGN_DETERMINANT_MODEL_3X3_BIT: u32 = 2147483648u;

View File

@ -15,7 +15,13 @@ fn prepare_normal(
#endif
is_front: bool,
) -> vec3<f32> {
var N: vec3<f32> = normalize(world_normal);
// NOTE: The mikktspace method of normal mapping explicitly requires that the world normal NOT
// be re-normalized in the fragment shader. This is primarily to match the way mikktspace
// bakes vertex tangents and normal maps so that this is the exact inverse. Blender, Unity,
// Unreal Engine, Godot, and more all use the mikktspace method. Do not change this code
// unless you really know what you are doing.
// http://www.mikktspace.com/
var N: vec3<f32> = world_normal;
#ifdef VERTEX_TANGENTS
#ifdef STANDARDMATERIAL_NORMAL_MAP
@ -236,7 +242,7 @@ fn pbr(
fn tone_mapping(in: vec4<f32>) -> vec4<f32> {
// tone_mapping
return vec4<f32>(reinhard_luminance(in.rgb), in.a);
// Gamma correction.
// Not needed with sRGB buffer
// output_color.rgb = pow(output_color.rgb, vec3(1.0 / 2.2));

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_ptr"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Utilities for working with untyped pointers in a more safe way"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_reflect"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Dynamically interact with rust types"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_reflect_derive"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Derive implementations for bevy_reflect"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_render"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides rendering functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_render_macros"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Derive implementations for bevy_render"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_scene"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides scene functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_sprite"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides sprite functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -2,9 +2,11 @@
struct View {
view_proj: mat4x4<f32>,
inverse_view_proj: mat4x4<f32>,
view: mat4x4<f32>,
inverse_view: mat4x4<f32>,
projection: mat4x4<f32>,
inverse_projection: mat4x4<f32>,
world_position: vec3<f32>,
width: f32,
height: f32,

View File

@ -1,6 +1,13 @@
struct View {
view_proj: mat4x4<f32>,
inverse_view_proj: mat4x4<f32>,
view: mat4x4<f32>,
inverse_view: mat4x4<f32>,
projection: mat4x4<f32>,
inverse_projection: mat4x4<f32>,
world_position: vec3<f32>,
width: f32,
height: f32,
};
@group(0) @binding(0)
var<uniform> view: View;

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_tasks"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "A task executor for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_text"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides text functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_time"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides time functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_transform"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides transform functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_ui"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "A custom ECS-driven UI framework built specifically for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,13 @@
struct View {
view_proj: mat4x4<f32>,
inverse_view_proj: mat4x4<f32>,
view: mat4x4<f32>,
inverse_view: mat4x4<f32>,
projection: mat4x4<f32>,
inverse_projection: mat4x4<f32>,
world_position: vec3<f32>,
width: f32,
height: f32,
};
@group(0) @binding(0)
var<uniform> view: View;
@ -22,7 +29,7 @@ fn vertex(
out.position = view.view_proj * vec4<f32>(vertex_position, 1.0);
out.color = vertex_color;
return out;
}
}
@group(1) @binding(0)
var sprite_texture: texture_2d<f32>;
@ -31,7 +38,7 @@ var sprite_sampler: sampler;
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
var color = textureSample(sprite_texture, sprite_sampler, in.uv);
var color = textureSample(sprite_texture, sprite_sampler, in.uv);
color = in.color * color;
return color;
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_utils"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "A collection of utils for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_window"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Provides windowing functionality for Bevy Engine"
homepage = "https://bevyengine.org"

View File

@ -22,7 +22,10 @@ pub mod prelude {
}
use bevy_app::prelude::*;
use bevy_ecs::{event::Events, schedule::SystemLabel};
use bevy_ecs::{
event::Events,
schedule::{ParallelSystemDescriptorCoercion, SystemLabel},
};
/// The configuration information for the [`WindowPlugin`].
///
@ -106,7 +109,10 @@ impl Plugin for WindowPlugin {
}
if settings.exit_on_all_closed {
app.add_system(exit_on_all_closed);
app.add_system_to_stage(
CoreStage::PostUpdate,
exit_on_all_closed.after(ModifiesWindows),
);
}
if settings.close_when_requested {
app.add_system(close_when_requested);

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_winit"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "A winit window and input backend for Bevy Engine"
homepage = "https://bevyengine.org"