mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Migrate from LegacyColor
to bevy_color::Color
(#12163)
# Objective - As part of the migration process we need to a) see the end effect of the migration on user ergonomics b) check for serious perf regressions c) actually migrate the code - To accomplish this, I'm going to attempt to migrate all of the remaining user-facing usages of `LegacyColor` in one PR, being careful to keep a clean commit history. - Fixes #12056. ## Solution I've chosen to use the polymorphic `Color` type as our standard user-facing API. - [x] Migrate `bevy_gizmos`. - [x] Take `impl Into<Color>` in all `bevy_gizmos` APIs - [x] Migrate sprites - [x] Migrate UI - [x] Migrate `ColorMaterial` - [x] Migrate `MaterialMesh2D` - [x] Migrate fog - [x] Migrate lights - [x] Migrate StandardMaterial - [x] Migrate wireframes - [x] Migrate clear color - [x] Migrate text - [x] Migrate gltf loader - [x] Register color types for reflection - [x] Remove `LegacyColor` - [x] Make sure CI passes Incidental improvements to ease migration: - added `Color::srgba_u8`, `Color::srgba_from_array` and friends - added `set_alpha`, `is_fully_transparent` and `is_fully_opaque` to the `Alpha` trait - add and immediately deprecate (lol) `Color::rgb` and friends in favor of more explicit and consistent `Color::srgb` - standardized on white and black for most example text colors - added vector field traits to `LinearRgba`: ~~`Add`, `Sub`, `AddAssign`, `SubAssign`,~~ `Mul<f32>` and `Div<f32>`. Multiplications and divisions do not scale alpha. `Add` and `Sub` have been cut from this PR. - added `LinearRgba` and `Srgba` `RED/GREEN/BLUE` - added `LinearRgba_to_f32_array` and `LinearRgba::to_u32` ## Migration Guide Bevy's color types have changed! Wherever you used a `bevy::render::Color`, a `bevy::color::Color` is used instead. These are quite similar! Both are enums storing a color in a specific color space (or to be more precise, using a specific color model). However, each of the different color models now has its own type. TODO... - `Color::rgba`, `Color::rgb`, `Color::rbga_u8`, `Color::rgb_u8`, `Color::rgb_from_array` are now `Color::srgba`, `Color::srgb`, `Color::srgba_u8`, `Color::srgb_u8` and `Color::srgb_from_array`. - `Color::set_a` and `Color::a` is now `Color::set_alpha` and `Color::alpha`. These are part of the `Alpha` trait in `bevy_color`. - `Color::is_fully_transparent` is now part of the `Alpha` trait in `bevy_color` - `Color::r`, `Color::set_r`, `Color::with_r` and the equivalents for `g`, `b` `h`, `s` and `l` have been removed due to causing silent relatively expensive conversions. Convert your `Color` into the desired color space, perform your operations there, and then convert it back into a polymorphic `Color` enum. - `Color::hex` is now `Srgba::hex`. Call `.into` or construct a `Color::Srgba` variant manually to convert it. - `WireframeMaterial`, `ExtractedUiNode`, `ExtractedDirectionalLight`, `ExtractedPointLight`, `ExtractedSpotLight` and `ExtractedSprite` now store a `LinearRgba`, rather than a polymorphic `Color` - `Color::rgb_linear` and `Color::rgba_linear` are now `Color::linear_rgb` and `Color::linear_rgba` - The various CSS color constants are no longer stored directly on `Color`. Instead, they're defined in the `Srgba` color space, and accessed via `bevy::color::palettes::css`. Call `.into()` on them to convert them into a `Color` for quick debugging use, and consider using the much prettier `tailwind` palette for prototyping. - The `LIME_GREEN` color has been renamed to `LIMEGREEN` to comply with the standard naming. - Vector field arithmetic operations on `Color` (add, subtract, multiply and divide by a f32) have been removed. Instead, convert your colors into `LinearRgba` space, and perform your operations explicitly there. This is particularly relevant when working with emissive or HDR colors, whose color channel values are routinely outside of the ordinary 0 to 1 range. - `Color::as_linear_rgba_f32` has been removed. Call `LinearRgba::to_f32_array` instead, converting if needed. - `Color::as_linear_rgba_u32` has been removed. Call `LinearRgba::to_u32` instead, converting if needed. - Several other color conversion methods to transform LCH or HSL colors into float arrays or `Vec` types have been removed. Please reimplement these externally or open a PR to re-add them if you found them particularly useful. - Various methods on `Color` such as `rgb` or `hsl` to convert the color into a specific color space have been removed. Convert into `LinearRgba`, then to the color space of your choice. - Various implicitly-converting color value methods on `Color` such as `r`, `g`, `b` or `h` have been removed. Please convert it into the color space of your choice, then check these properties. - `Color` no longer implements `AsBindGroup`. Store a `LinearRgba` internally instead to avoid conversion costs. --------- Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com> Co-authored-by: Afonso Lage <lage.afonso@gmail.com> Co-authored-by: Rob Parrett <robparrett@gmail.com> Co-authored-by: Zachary Harrold <zac@harrold.com.au>
This commit is contained in:
parent
b24ab2e9fb
commit
599e5e4e76
180 changed files with 1371 additions and 2807 deletions
|
@ -45,6 +45,12 @@ impl Color {
|
||||||
(*self).into()
|
(*self).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use `Color::srgba` instead"]
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color.
|
||||||
|
pub const fn rgba(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||||
|
Self::srgba(red, green, blue, alpha)
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new [`Color`] object storing a [`Srgba`] color.
|
/// Creates a new [`Color`] object storing a [`Srgba`] color.
|
||||||
pub const fn srgba(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
pub const fn srgba(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||||
Self::Srgba(Srgba {
|
Self::Srgba(Srgba {
|
||||||
|
@ -55,6 +61,12 @@ impl Color {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use `Color::srgb` instead"]
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
|
||||||
|
pub const fn rgb(red: f32, green: f32, blue: f32) -> Self {
|
||||||
|
Self::srgb(red, green, blue)
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
|
/// Creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
|
||||||
pub const fn srgb(red: f32, green: f32, blue: f32) -> Self {
|
pub const fn srgb(red: f32, green: f32, blue: f32) -> Self {
|
||||||
Self::Srgba(Srgba {
|
Self::Srgba(Srgba {
|
||||||
|
@ -65,7 +77,69 @@ impl Color {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Createsa new [`Color`] object storing a [`LinearRgba`] color.
|
#[deprecated = "Use `Color::srgb_from_array` instead"]
|
||||||
|
/// Reads an array of floats to creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
|
||||||
|
pub fn rgb_from_array([r, g, b]: [f32; 3]) -> Self {
|
||||||
|
Self::Srgba(Srgba::rgb(r, g, b))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reads an array of floats to creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
|
||||||
|
pub fn srgb_from_array(array: [f32; 3]) -> Self {
|
||||||
|
Self::Srgba(Srgba {
|
||||||
|
red: array[0],
|
||||||
|
green: array[1],
|
||||||
|
blue: array[2],
|
||||||
|
alpha: 1.0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use `Color::srgba_u8` instead"]
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values.
|
||||||
|
///
|
||||||
|
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
|
||||||
|
pub fn rgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
|
||||||
|
Self::srgba_u8(red, green, blue, alpha)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values.
|
||||||
|
///
|
||||||
|
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
|
||||||
|
pub fn srgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
|
||||||
|
Self::Srgba(Srgba {
|
||||||
|
red: red as f32 / 255.0,
|
||||||
|
green: green as f32 / 255.0,
|
||||||
|
blue: blue as f32 / 255.0,
|
||||||
|
alpha: alpha as f32 / 255.0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use `Color::srgb_u8` instead"]
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values with an alpha of 1.0.
|
||||||
|
///
|
||||||
|
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
|
||||||
|
pub fn rgb_u8(red: u8, green: u8, blue: u8) -> Self {
|
||||||
|
Self::srgb_u8(red, green, blue)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values with an alpha of 1.0.
|
||||||
|
///
|
||||||
|
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
|
||||||
|
pub fn srgb_u8(red: u8, green: u8, blue: u8) -> Self {
|
||||||
|
Self::Srgba(Srgba {
|
||||||
|
red: red as f32 / 255.0,
|
||||||
|
green: green as f32 / 255.0,
|
||||||
|
blue: blue as f32 / 255.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use Color::linear_rgba instead."]
|
||||||
|
/// Creates a new [`Color`] object storing a [`LinearRgba`] color.
|
||||||
|
pub const fn rbga_linear(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||||
|
Self::linear_rgba(red, green, blue, alpha)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`Color`] object storing a [`LinearRgba`] color.
|
||||||
pub const fn linear_rgba(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
pub const fn linear_rgba(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||||
Self::LinearRgba(LinearRgba {
|
Self::LinearRgba(LinearRgba {
|
||||||
red,
|
red,
|
||||||
|
@ -75,7 +149,13 @@ impl Color {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// a new [`Color`] object storing a [`LinearRgba`] color with an alpha of 1.0.
|
#[deprecated = "Use Color::linear_rgb instead."]
|
||||||
|
/// Creates a new [`Color`] object storing a [`LinearRgba`] color with an alpha of 1.0.
|
||||||
|
pub const fn rgb_linear(red: f32, green: f32, blue: f32) -> Self {
|
||||||
|
Self::linear_rgb(red, green, blue)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`Color`] object storing a [`LinearRgba`] color with an alpha of 1.0.
|
||||||
pub const fn linear_rgb(red: f32, green: f32, blue: f32) -> Self {
|
pub const fn linear_rgb(red: f32, green: f32, blue: f32) -> Self {
|
||||||
Self::LinearRgba(LinearRgba {
|
Self::LinearRgba(LinearRgba {
|
||||||
red,
|
red,
|
||||||
|
@ -241,8 +321,8 @@ impl Color {
|
||||||
/// A fully black [`Color::LinearRgba`] color with an alpha of 1.0.
|
/// A fully black [`Color::LinearRgba`] color with an alpha of 1.0.
|
||||||
pub const BLACK: Self = Self::linear_rgb(0., 0., 0.);
|
pub const BLACK: Self = Self::linear_rgb(0., 0., 0.);
|
||||||
|
|
||||||
/// A fully transparent [`Color::LinearRgba`] color.
|
/// A fully transparent [`Color::LinearRgba`] color with 0 red, green and blue.
|
||||||
pub const TRANSPARENT: Self = Self::linear_rgba(0., 0., 0., 0.);
|
pub const NONE: Self = Self::linear_rgba(0., 0., 0., 0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Color {
|
impl Default for Color {
|
||||||
|
@ -286,6 +366,21 @@ impl Alpha for Color {
|
||||||
Color::Xyza(x) => x.alpha(),
|
Color::Xyza(x) => x.alpha(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
match self {
|
||||||
|
Color::Srgba(x) => x.set_alpha(alpha),
|
||||||
|
Color::LinearRgba(x) => x.set_alpha(alpha),
|
||||||
|
Color::Hsla(x) => x.set_alpha(alpha),
|
||||||
|
Color::Hsva(x) => x.set_alpha(alpha),
|
||||||
|
Color::Hwba(x) => x.set_alpha(alpha),
|
||||||
|
Color::Laba(x) => x.set_alpha(alpha),
|
||||||
|
Color::Lcha(x) => x.set_alpha(alpha),
|
||||||
|
Color::Oklaba(x) => x.set_alpha(alpha),
|
||||||
|
Color::Oklcha(x) => x.set_alpha(alpha),
|
||||||
|
Color::Xyza(x) => x.set_alpha(alpha),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Srgba> for Color {
|
impl From<Srgba> for Color {
|
||||||
|
|
|
@ -47,4 +47,17 @@ pub trait Alpha: Sized {
|
||||||
|
|
||||||
/// Return a the alpha component of this color.
|
/// Return a the alpha component of this color.
|
||||||
fn alpha(&self) -> f32;
|
fn alpha(&self) -> f32;
|
||||||
|
|
||||||
|
/// Sets the alpha component of this color.
|
||||||
|
fn set_alpha(&mut self, alpha: f32);
|
||||||
|
|
||||||
|
/// Is the alpha component of this color less than or equal to 0.0?
|
||||||
|
fn is_fully_transparent(&self) -> bool {
|
||||||
|
self.alpha() <= 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Is the alpha component of this color greater than or equal to 1.0?
|
||||||
|
fn is_fully_opaque(&self) -> bool {
|
||||||
|
self.alpha() >= 1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,11 @@ impl Alpha for Hsla {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Hsla {
|
impl Luminance for Hsla {
|
||||||
|
|
|
@ -84,6 +84,11 @@ impl Alpha for Hsva {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Hsva> for Hwba {
|
impl From<Hsva> for Hwba {
|
||||||
|
|
|
@ -88,6 +88,11 @@ impl Alpha for Hwba {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Srgba> for Hwba {
|
impl From<Srgba> for Hwba {
|
||||||
|
|
|
@ -103,6 +103,11 @@ impl Alpha for Laba {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Laba {
|
impl Luminance for Laba {
|
||||||
|
|
|
@ -130,6 +130,11 @@ impl Alpha for Lcha {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Lcha {
|
impl Luminance for Lcha {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ops::{Div, Mul};
|
||||||
|
|
||||||
use crate::{color_difference::EuclideanDistance, Alpha, Luminance, Mix, StandardColor};
|
use crate::{color_difference::EuclideanDistance, Alpha, Luminance, Mix, StandardColor};
|
||||||
use bevy_math::Vec4;
|
use bevy_math::Vec4;
|
||||||
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
||||||
|
@ -50,6 +52,30 @@ impl LinearRgba {
|
||||||
alpha: 0.0,
|
alpha: 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A fully red color with full alpha.
|
||||||
|
pub const RED: Self = Self {
|
||||||
|
red: 1.0,
|
||||||
|
green: 0.0,
|
||||||
|
blue: 0.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A fully green color with full alpha.
|
||||||
|
pub const GREEN: Self = Self {
|
||||||
|
red: 0.0,
|
||||||
|
green: 1.0,
|
||||||
|
blue: 0.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A fully blue color with full alpha.
|
||||||
|
pub const BLUE: Self = Self {
|
||||||
|
red: 0.0,
|
||||||
|
green: 0.0,
|
||||||
|
blue: 1.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
/// An invalid color.
|
/// An invalid color.
|
||||||
///
|
///
|
||||||
/// This type can be used to represent an invalid color value;
|
/// This type can be used to represent an invalid color value;
|
||||||
|
@ -127,6 +153,26 @@ impl LinearRgba {
|
||||||
self.mix_assign(Self::new(1.0, 1.0, 1.0, self.alpha), adjustment);
|
self.mix_assign(Self::new(1.0, 1.0, 1.0, self.alpha), adjustment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts the color into a [f32; 4] array in RGBA order.
|
||||||
|
///
|
||||||
|
/// This is useful for passing the color to a shader.
|
||||||
|
pub fn to_f32_array(&self) -> [f32; 4] {
|
||||||
|
[self.red, self.green, self.blue, self.alpha]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts this color to a u32.
|
||||||
|
///
|
||||||
|
/// Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian).
|
||||||
|
/// `A` will be the most significant byte and `R` the least significant.
|
||||||
|
pub fn as_u32(&self) -> u32 {
|
||||||
|
u32::from_le_bytes([
|
||||||
|
(self.red * 255.0) as u8,
|
||||||
|
(self.green * 255.0) as u8,
|
||||||
|
(self.blue * 255.0) as u8,
|
||||||
|
(self.alpha * 255.0) as u8,
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LinearRgba {
|
impl Default for LinearRgba {
|
||||||
|
@ -193,6 +239,11 @@ impl Alpha for LinearRgba {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EuclideanDistance for LinearRgba {
|
impl EuclideanDistance for LinearRgba {
|
||||||
|
@ -228,6 +279,48 @@ impl From<LinearRgba> for wgpu::Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All color channels are scaled directly,
|
||||||
|
/// but alpha is unchanged.
|
||||||
|
///
|
||||||
|
/// Values are not clamped.
|
||||||
|
impl Mul<f32> for LinearRgba {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, rhs: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
red: self.red * rhs,
|
||||||
|
green: self.green * rhs,
|
||||||
|
blue: self.blue * rhs,
|
||||||
|
alpha: self.alpha,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mul<LinearRgba> for f32 {
|
||||||
|
type Output = LinearRgba;
|
||||||
|
|
||||||
|
fn mul(self, rhs: LinearRgba) -> LinearRgba {
|
||||||
|
rhs * self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// All color channels are scaled directly,
|
||||||
|
/// but alpha is unchanged.
|
||||||
|
///
|
||||||
|
/// Values are not clamped.
|
||||||
|
impl Div<f32> for LinearRgba {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn div(self, rhs: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
red: self.red / rhs,
|
||||||
|
green: self.green / rhs,
|
||||||
|
blue: self.blue / rhs,
|
||||||
|
alpha: self.alpha,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// [`LinearRgba`] is intended to be used with shaders
|
// [`LinearRgba`] is intended to be used with shaders
|
||||||
// So it's the only color type that implements [`ShaderType`] to make it easier to use inside shaders
|
// So it's the only color type that implements [`ShaderType`] to make it easier to use inside shaders
|
||||||
impl encase::ShaderType for LinearRgba {
|
impl encase::ShaderType for LinearRgba {
|
||||||
|
|
|
@ -99,6 +99,11 @@ impl Alpha for Oklaba {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Oklaba {
|
impl Luminance for Oklaba {
|
||||||
|
|
|
@ -129,6 +129,11 @@ impl Alpha for Oklcha {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Oklcha {
|
impl Luminance for Oklcha {
|
||||||
|
|
|
@ -37,6 +37,30 @@ impl Srgba {
|
||||||
/// <div style="background-color:rgb(100%, 100%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
|
/// <div style="background-color:rgb(100%, 100%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
|
||||||
pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0);
|
pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
/// A fully red color with full alpha.
|
||||||
|
pub const RED: Self = Self {
|
||||||
|
red: 1.0,
|
||||||
|
green: 0.0,
|
||||||
|
blue: 0.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A fully green color with full alpha.
|
||||||
|
pub const GREEN: Self = Self {
|
||||||
|
red: 0.0,
|
||||||
|
green: 1.0,
|
||||||
|
blue: 0.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A fully blue color with full alpha.
|
||||||
|
pub const BLUE: Self = Self {
|
||||||
|
red: 0.0,
|
||||||
|
green: 0.0,
|
||||||
|
blue: 1.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
/// Construct a new [`Srgba`] color from components.
|
/// Construct a new [`Srgba`] color from components.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -264,6 +288,11 @@ impl Alpha for Srgba {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EuclideanDistance for Srgba {
|
impl EuclideanDistance for Srgba {
|
||||||
|
|
|
@ -86,6 +86,11 @@ impl Alpha for Xyza {
|
||||||
fn alpha(&self) -> f32 {
|
fn alpha(&self) -> f32 {
|
||||||
self.alpha
|
self.alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_alpha(&mut self, alpha: f32) {
|
||||||
|
self.alpha = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Luminance for Xyza {
|
impl Luminance for Xyza {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use crate as bevy_gizmos;
|
use crate as bevy_gizmos;
|
||||||
|
|
||||||
use bevy_app::{Plugin, PostUpdate};
|
use bevy_app::{Plugin, PostUpdate};
|
||||||
use bevy_color::Oklcha;
|
use bevy_color::{Color, Oklcha};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
|
@ -13,7 +13,7 @@ use bevy_ecs::{
|
||||||
system::{Query, Res},
|
system::{Query, Res},
|
||||||
};
|
};
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_render::{color::LegacyColor, primitives::Aabb};
|
use bevy_render::primitives::Aabb;
|
||||||
use bevy_transform::{
|
use bevy_transform::{
|
||||||
components::{GlobalTransform, Transform},
|
components::{GlobalTransform, Transform},
|
||||||
TransformSystem,
|
TransformSystem,
|
||||||
|
@ -58,7 +58,7 @@ pub struct AabbGizmoConfigGroup {
|
||||||
/// A random color is chosen per box if `None`.
|
/// A random color is chosen per box if `None`.
|
||||||
///
|
///
|
||||||
/// Defaults to `None`.
|
/// Defaults to `None`.
|
||||||
pub default_color: Option<LegacyColor>,
|
pub default_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add this [`Component`] to an entity to draw its [`Aabb`] component.
|
/// Add this [`Component`] to an entity to draw its [`Aabb`] component.
|
||||||
|
@ -68,7 +68,7 @@ pub struct ShowAabbGizmo {
|
||||||
/// The color of the box.
|
/// The color of the box.
|
||||||
///
|
///
|
||||||
/// The default color from the [`AabbGizmoConfigGroup`] config is used if `None`,
|
/// The default color from the [`AabbGizmoConfigGroup`] config is used if `None`,
|
||||||
pub color: Option<LegacyColor>,
|
pub color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_aabbs(
|
fn draw_aabbs(
|
||||||
|
@ -97,7 +97,7 @@ fn draw_all_aabbs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color_from_entity(entity: Entity) -> LegacyColor {
|
fn color_from_entity(entity: Entity) -> Color {
|
||||||
Oklcha::sequential_dispersed(entity.index()).into()
|
Oklcha::sequential_dispersed(entity.index()).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
|
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::{Quat, Vec2, Vec3};
|
use bevy_math::{Quat, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
// === 2D ===
|
// === 2D ===
|
||||||
|
@ -29,13 +29,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
/// # use std::f32::consts::PI;
|
/// # use std::f32::consts::PI;
|
||||||
|
/// # use bevy_color::palettes::basic::{GREEN, RED};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., LegacyColor::GREEN);
|
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., GREEN);
|
||||||
///
|
///
|
||||||
/// // Arcs have 32 line-segments by default.
|
/// // Arcs have 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger arcs.
|
/// // You may want to increase this for larger arcs.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., LegacyColor::RED)
|
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., RED)
|
||||||
/// .segments(64);
|
/// .segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -47,7 +48,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
direction_angle: f32,
|
direction_angle: f32,
|
||||||
arc_angle: f32,
|
arc_angle: f32,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Arc2dBuilder<'_, 'w, 's, T> {
|
) -> Arc2dBuilder<'_, 'w, 's, T> {
|
||||||
Arc2dBuilder {
|
Arc2dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -55,7 +56,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
direction_angle,
|
direction_angle,
|
||||||
arc_angle,
|
arc_angle,
|
||||||
radius,
|
radius,
|
||||||
color,
|
color: color.into(),
|
||||||
segments: None,
|
segments: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +69,7 @@ pub struct Arc2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
direction_angle: f32,
|
direction_angle: f32,
|
||||||
arc_angle: f32,
|
arc_angle: f32,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
segments: Option<usize>,
|
segments: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
/// # use std::f32::consts::PI;
|
/// # use std::f32::consts::PI;
|
||||||
|
/// # use bevy_color::palettes::css::ORANGE;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// // rotation rotates normal to point in the direction of `Vec3::NEG_ONE`
|
/// // rotation rotates normal to point in the direction of `Vec3::NEG_ONE`
|
||||||
/// let rotation = Quat::from_rotation_arc(Vec3::Y, Vec3::NEG_ONE.normalize());
|
/// let rotation = Quat::from_rotation_arc(Vec3::Y, Vec3::NEG_ONE.normalize());
|
||||||
|
@ -152,7 +154,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// 0.25,
|
/// 0.25,
|
||||||
/// Vec3::ONE,
|
/// Vec3::ONE,
|
||||||
/// rotation,
|
/// rotation,
|
||||||
/// LegacyColor::ORANGE
|
/// ORANGE
|
||||||
/// )
|
/// )
|
||||||
/// .segments(100);
|
/// .segments(100);
|
||||||
/// }
|
/// }
|
||||||
|
@ -165,7 +167,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
radius: f32,
|
radius: f32,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
||||||
Arc3dBuilder {
|
Arc3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -174,7 +176,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
rotation,
|
rotation,
|
||||||
angle,
|
angle,
|
||||||
radius,
|
radius,
|
||||||
color,
|
color: color.into(),
|
||||||
segments: None,
|
segments: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,12 +199,13 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::css::ORANGE;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.short_arc_3d_between(
|
/// gizmos.short_arc_3d_between(
|
||||||
/// Vec3::ONE,
|
/// Vec3::ONE,
|
||||||
/// Vec3::ONE + Vec3::NEG_ONE,
|
/// Vec3::ONE + Vec3::NEG_ONE,
|
||||||
/// Vec3::ZERO,
|
/// Vec3::ZERO,
|
||||||
/// LegacyColor::ORANGE
|
/// ORANGE
|
||||||
/// )
|
/// )
|
||||||
/// .segments(100);
|
/// .segments(100);
|
||||||
/// }
|
/// }
|
||||||
|
@ -221,7 +224,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
center: Vec3,
|
center: Vec3,
|
||||||
from: Vec3,
|
from: Vec3,
|
||||||
to: Vec3,
|
to: Vec3,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
||||||
self.arc_from_to(center, from, to, color, |x| x)
|
self.arc_from_to(center, from, to, color, |x| x)
|
||||||
}
|
}
|
||||||
|
@ -243,12 +246,13 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::css::ORANGE;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.long_arc_3d_between(
|
/// gizmos.long_arc_3d_between(
|
||||||
/// Vec3::ONE,
|
/// Vec3::ONE,
|
||||||
/// Vec3::ONE + Vec3::NEG_ONE,
|
/// Vec3::ONE + Vec3::NEG_ONE,
|
||||||
/// Vec3::ZERO,
|
/// Vec3::ZERO,
|
||||||
/// LegacyColor::ORANGE
|
/// ORANGE
|
||||||
/// )
|
/// )
|
||||||
/// .segments(100);
|
/// .segments(100);
|
||||||
/// }
|
/// }
|
||||||
|
@ -267,7 +271,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
center: Vec3,
|
center: Vec3,
|
||||||
from: Vec3,
|
from: Vec3,
|
||||||
to: Vec3,
|
to: Vec3,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
||||||
self.arc_from_to(center, from, to, color, |angle| {
|
self.arc_from_to(center, from, to, color, |angle| {
|
||||||
if angle > 0.0 {
|
if angle > 0.0 {
|
||||||
|
@ -286,7 +290,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
center: Vec3,
|
center: Vec3,
|
||||||
from: Vec3,
|
from: Vec3,
|
||||||
to: Vec3,
|
to: Vec3,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
angle_fn: impl Fn(f32) -> f32,
|
angle_fn: impl Fn(f32) -> f32,
|
||||||
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
) -> Arc3dBuilder<'_, 'w, 's, T> {
|
||||||
// `from` and `to` can be the same here since in either case nothing gets rendered and the
|
// `from` and `to` can be the same here since in either case nothing gets rendered and the
|
||||||
|
@ -308,7 +312,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
rotation,
|
rotation,
|
||||||
angle,
|
angle,
|
||||||
radius,
|
radius,
|
||||||
color,
|
color: color.into(),
|
||||||
segments: None,
|
segments: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +335,7 @@ pub struct Arc3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
segments: Option<usize>,
|
segments: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
//! and assorted support items.
|
//! and assorted support items.
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::{Quat, Vec2, Vec3};
|
use bevy_math::{Quat, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
/// A builder returned by [`Gizmos::arrow`] and [`Gizmos::arrow_2d`]
|
/// A builder returned by [`Gizmos::arrow`] and [`Gizmos::arrow_2d`]
|
||||||
pub struct ArrowBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
pub struct ArrowBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
gizmos: &'a mut Gizmos<'w, 's, T>,
|
gizmos: &'a mut Gizmos<'w, 's, T>,
|
||||||
start: Vec3,
|
start: Vec3,
|
||||||
end: Vec3,
|
end: Vec3,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
tip_length: f32,
|
tip_length: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ impl<T: GizmoConfigGroup> ArrowBuilder<'_, '_, '_, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN)
|
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, GREEN)
|
||||||
/// .with_tip_length(3.);
|
/// .with_tip_length(3.);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -76,8 +77,9 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN);
|
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -85,14 +87,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec3,
|
start: Vec3,
|
||||||
end: Vec3,
|
end: Vec3,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> ArrowBuilder<'_, 'w, 's, T> {
|
) -> ArrowBuilder<'_, 'w, 's, T> {
|
||||||
let length = (end - start).length();
|
let length = (end - start).length();
|
||||||
ArrowBuilder {
|
ArrowBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
color,
|
color: color.into(),
|
||||||
tip_length: length / 10.,
|
tip_length: length / 10.,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,8 +108,9 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN);
|
/// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -115,7 +118,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec2,
|
start: Vec2,
|
||||||
end: Vec2,
|
end: Vec2,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> ArrowBuilder<'_, 'w, 's, T> {
|
) -> ArrowBuilder<'_, 'w, 's, T> {
|
||||||
self.arrow(start.extend(0.), end.extend(0.), color)
|
self.arrow(start.extend(0.), end.extend(0.), color)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
//! and assorted support items.
|
//! and assorted support items.
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::Mat2;
|
use bevy_math::Mat2;
|
||||||
use bevy_math::{Dir3, Quat, Vec2, Vec3};
|
use bevy_math::{Dir3, Quat, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
pub(crate) const DEFAULT_CIRCLE_SEGMENTS: usize = 32;
|
pub(crate) const DEFAULT_CIRCLE_SEGMENTS: usize = 32;
|
||||||
|
@ -29,13 +29,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), LegacyColor::GREEN);
|
/// gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), GREEN);
|
||||||
///
|
///
|
||||||
/// // Ellipses have 32 line-segments by default.
|
/// // Ellipses have 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger ellipses.
|
/// // You may want to increase this for larger ellipses.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), LegacyColor::RED)
|
/// .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), RED)
|
||||||
/// .segments(64);
|
/// .segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -46,14 +47,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
half_size: Vec2,
|
half_size: Vec2,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> EllipseBuilder<'_, 'w, 's, T> {
|
) -> EllipseBuilder<'_, 'w, 's, T> {
|
||||||
EllipseBuilder {
|
EllipseBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
half_size,
|
half_size,
|
||||||
color,
|
color: color.into(),
|
||||||
segments: DEFAULT_CIRCLE_SEGMENTS,
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,13 +68,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), LegacyColor::GREEN);
|
/// gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), GREEN);
|
||||||
///
|
///
|
||||||
/// // Ellipses have 32 line-segments by default.
|
/// // Ellipses have 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger ellipses.
|
/// // You may want to increase this for larger ellipses.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), LegacyColor::RED)
|
/// .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), RED)
|
||||||
/// .segments(64);
|
/// .segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -84,14 +86,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
half_size: Vec2,
|
half_size: Vec2,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
||||||
Ellipse2dBuilder {
|
Ellipse2dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
position,
|
position,
|
||||||
rotation: Mat2::from_angle(angle),
|
rotation: Mat2::from_angle(angle),
|
||||||
half_size,
|
half_size,
|
||||||
color,
|
color: color.into(),
|
||||||
segments: DEFAULT_CIRCLE_SEGMENTS,
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,13 +107,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.circle(Vec3::ZERO, Dir3::Z, 1., LegacyColor::GREEN);
|
/// gizmos.circle(Vec3::ZERO, Dir3::Z, 1., GREEN);
|
||||||
///
|
///
|
||||||
/// // Circles have 32 line-segments by default.
|
/// // Circles have 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger circles.
|
/// // You may want to increase this for larger circles.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .circle(Vec3::ZERO, Dir3::Z, 5., LegacyColor::RED)
|
/// .circle(Vec3::ZERO, Dir3::Z, 5., RED)
|
||||||
/// .segments(64);
|
/// .segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -122,14 +125,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
normal: Dir3,
|
normal: Dir3,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> EllipseBuilder<'_, 'w, 's, T> {
|
) -> EllipseBuilder<'_, 'w, 's, T> {
|
||||||
EllipseBuilder {
|
EllipseBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
position,
|
position,
|
||||||
rotation: Quat::from_rotation_arc(Vec3::Z, *normal),
|
rotation: Quat::from_rotation_arc(Vec3::Z, *normal),
|
||||||
half_size: Vec2::splat(radius),
|
half_size: Vec2::splat(radius),
|
||||||
color,
|
color: color.into(),
|
||||||
segments: DEFAULT_CIRCLE_SEGMENTS,
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,13 +146,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.circle_2d(Vec2::ZERO, 1., LegacyColor::GREEN);
|
/// gizmos.circle_2d(Vec2::ZERO, 1., GREEN);
|
||||||
///
|
///
|
||||||
/// // Circles have 32 line-segments by default.
|
/// // Circles have 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger circles.
|
/// // You may want to increase this for larger circles.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .circle_2d(Vec2::ZERO, 5., LegacyColor::RED)
|
/// .circle_2d(Vec2::ZERO, 5., RED)
|
||||||
/// .segments(64);
|
/// .segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -159,14 +163,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
&mut self,
|
&mut self,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
) -> Ellipse2dBuilder<'_, 'w, 's, T> {
|
||||||
Ellipse2dBuilder {
|
Ellipse2dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
position,
|
position,
|
||||||
rotation: Mat2::IDENTITY,
|
rotation: Mat2::IDENTITY,
|
||||||
half_size: Vec2::splat(radius),
|
half_size: Vec2::splat(radius),
|
||||||
color,
|
color: color.into(),
|
||||||
segments: DEFAULT_CIRCLE_SEGMENTS,
|
segments: DEFAULT_CIRCLE_SEGMENTS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +182,7 @@ pub struct EllipseBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
half_size: Vec2,
|
half_size: Vec2,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
segments: usize,
|
segments: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +213,7 @@ pub struct Ellipse2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
rotation: Mat2,
|
rotation: Mat2,
|
||||||
half_size: Vec2,
|
half_size: Vec2,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
segments: usize,
|
segments: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,13 @@
|
||||||
use std::{iter, marker::PhantomData};
|
use std::{iter, marker::PhantomData};
|
||||||
|
|
||||||
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
|
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
|
||||||
use bevy_color::LinearRgba;
|
use bevy_color::{Color, LinearRgba};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Tick,
|
component::Tick,
|
||||||
system::{Deferred, ReadOnlySystemParam, Res, Resource, SystemBuffer, SystemMeta, SystemParam},
|
system::{Deferred, ReadOnlySystemParam, Res, Resource, SystemBuffer, SystemMeta, SystemParam},
|
||||||
world::{unsafe_world_cell::UnsafeWorldCell, World},
|
world::{unsafe_world_cell::UnsafeWorldCell, World},
|
||||||
};
|
};
|
||||||
use bevy_math::{Dir3, Mat2, Quat, Vec2, Vec3};
|
use bevy_math::{Dir3, Mat2, Quat, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
use bevy_transform::TransformPoint;
|
use bevy_transform::TransformPoint;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -130,13 +129,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.line(Vec3::ZERO, Vec3::X, LegacyColor::GREEN);
|
/// gizmos.line(Vec3::ZERO, Vec3::X, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn line(&mut self, start: Vec3, end: Vec3, color: LegacyColor) {
|
pub fn line(&mut self, start: Vec3, end: Vec3, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -153,18 +153,19 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.line_gradient(Vec3::ZERO, Vec3::X, LegacyColor::GREEN, LegacyColor::RED);
|
/// gizmos.line_gradient(Vec3::ZERO, Vec3::X, GREEN, RED);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn line_gradient(
|
pub fn line_gradient<C: Into<Color>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec3,
|
start: Vec3,
|
||||||
end: Vec3,
|
end: Vec3,
|
||||||
start_color: LegacyColor,
|
start_color: C,
|
||||||
end_color: LegacyColor,
|
end_color: C,
|
||||||
) {
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -182,13 +183,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.ray(Vec3::Y, Vec3::X, LegacyColor::GREEN);
|
/// gizmos.ray(Vec3::Y, Vec3::X, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ray(&mut self, start: Vec3, vector: Vec3, color: LegacyColor) {
|
pub fn ray(&mut self, start: Vec3, vector: Vec3, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -204,18 +206,19 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.ray_gradient(Vec3::Y, Vec3::X, LegacyColor::GREEN, LegacyColor::RED);
|
/// gizmos.ray_gradient(Vec3::Y, Vec3::X, GREEN, RED);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ray_gradient(
|
pub fn ray_gradient<C: Into<Color>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec3,
|
start: Vec3,
|
||||||
vector: Vec3,
|
vector: Vec3,
|
||||||
start_color: LegacyColor,
|
start_color: C,
|
||||||
end_color: LegacyColor,
|
end_color: C,
|
||||||
) {
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -232,19 +235,25 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.linestrip([Vec3::ZERO, Vec3::X, Vec3::Y], LegacyColor::GREEN);
|
/// gizmos.linestrip([Vec3::ZERO, Vec3::X, Vec3::Y], GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn linestrip(&mut self, positions: impl IntoIterator<Item = Vec3>, color: LegacyColor) {
|
pub fn linestrip(
|
||||||
|
&mut self,
|
||||||
|
positions: impl IntoIterator<Item = Vec3>,
|
||||||
|
color: impl Into<Color>,
|
||||||
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.extend_strip_positions(positions);
|
self.extend_strip_positions(positions);
|
||||||
let len = self.buffer.strip_positions.len();
|
let len = self.buffer.strip_positions.len();
|
||||||
self.buffer.strip_colors.resize(len - 1, color.into());
|
let linear_color = LinearRgba::from(color.into());
|
||||||
|
self.buffer.strip_colors.resize(len - 1, linear_color);
|
||||||
self.buffer.strip_colors.push(LinearRgba::NAN);
|
self.buffer.strip_colors.push(LinearRgba::NAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,17 +266,21 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{BLUE, GREEN, RED};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.linestrip_gradient([
|
/// gizmos.linestrip_gradient([
|
||||||
/// (Vec3::ZERO, LegacyColor::GREEN),
|
/// (Vec3::ZERO, GREEN),
|
||||||
/// (Vec3::X, LegacyColor::RED),
|
/// (Vec3::X, RED),
|
||||||
/// (Vec3::Y, LegacyColor::BLUE)
|
/// (Vec3::Y, BLUE)
|
||||||
/// ]);
|
/// ]);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn linestrip_gradient(&mut self, points: impl IntoIterator<Item = (Vec3, LegacyColor)>) {
|
pub fn linestrip_gradient<C: Into<Color>>(
|
||||||
|
&mut self,
|
||||||
|
points: impl IntoIterator<Item = (Vec3, C)>,
|
||||||
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +298,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
|
|
||||||
for (position, color) in points {
|
for (position, color) in points {
|
||||||
strip_positions.push(position.to_array());
|
strip_positions.push(position.to_array());
|
||||||
strip_colors.push(color.into());
|
strip_colors.push(LinearRgba::from(color.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
strip_positions.push([f32::NAN; 3]);
|
strip_positions.push([f32::NAN; 3]);
|
||||||
|
@ -301,13 +314,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::Color;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.sphere(Vec3::ZERO, Quat::IDENTITY, 1., LegacyColor::BLACK);
|
/// gizmos.sphere(Vec3::ZERO, Quat::IDENTITY, 1., Color::BLACK);
|
||||||
///
|
///
|
||||||
/// // Each circle has 32 line-segments by default.
|
/// // Each circle has 32 line-segments by default.
|
||||||
/// // You may want to increase this for larger spheres.
|
/// // You may want to increase this for larger spheres.
|
||||||
/// gizmos
|
/// gizmos
|
||||||
/// .sphere(Vec3::ZERO, Quat::IDENTITY, 5., LegacyColor::BLACK)
|
/// .sphere(Vec3::ZERO, Quat::IDENTITY, 5., Color::BLACK)
|
||||||
/// .circle_segments(64);
|
/// .circle_segments(64);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
|
@ -318,14 +332,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> SphereBuilder<'_, 'w, 's, T> {
|
) -> SphereBuilder<'_, 'w, 's, T> {
|
||||||
SphereBuilder {
|
SphereBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
radius,
|
radius,
|
||||||
color,
|
color: color.into(),
|
||||||
circle_segments: DEFAULT_CIRCLE_SEGMENTS,
|
circle_segments: DEFAULT_CIRCLE_SEGMENTS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,13 +353,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.rect(Vec3::ZERO, Quat::IDENTITY, Vec2::ONE, LegacyColor::GREEN);
|
/// gizmos.rect(Vec3::ZERO, Quat::IDENTITY, Vec2::ONE, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rect(&mut self, position: Vec3, rotation: Quat, size: Vec2, color: LegacyColor) {
|
pub fn rect(&mut self, position: Vec3, rotation: Quat, size: Vec2, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -362,13 +377,15 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_transform::prelude::*;
|
/// # use bevy_transform::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.cuboid(Transform::IDENTITY, LegacyColor::GREEN);
|
/// gizmos.cuboid(Transform::IDENTITY, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cuboid(&mut self, transform: impl TransformPoint, color: LegacyColor) {
|
pub fn cuboid(&mut self, transform: impl TransformPoint, color: impl Into<Color>) {
|
||||||
|
let polymorphic_color: Color = color.into();
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -382,13 +399,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
tlf, trf, brf, blf, tlf, // Front
|
tlf, trf, brf, blf, tlf, // Front
|
||||||
tlb, trb, brb, blb, tlb, // Back
|
tlb, trb, brb, blb, tlb, // Back
|
||||||
];
|
];
|
||||||
self.linestrip(strip_positions, color);
|
self.linestrip(strip_positions, polymorphic_color);
|
||||||
|
|
||||||
let list_positions = [
|
let list_positions = [
|
||||||
trf, trb, brf, brb, blf, blb, // Front to back
|
trf, trb, brf, brb, blf, blb, // Front to back
|
||||||
];
|
];
|
||||||
self.extend_list_positions(list_positions);
|
self.extend_list_positions(list_positions);
|
||||||
self.add_list_color(color, 6);
|
|
||||||
|
self.add_list_color(polymorphic_color, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw a line in 2D from `start` to `end`.
|
/// Draw a line in 2D from `start` to `end`.
|
||||||
|
@ -400,13 +418,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.line_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN);
|
/// gizmos.line_2d(Vec2::ZERO, Vec2::X, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn line_2d(&mut self, start: Vec2, end: Vec2, color: LegacyColor) {
|
pub fn line_2d(&mut self, start: Vec2, end: Vec2, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -422,18 +441,19 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.line_gradient_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN, LegacyColor::RED);
|
/// gizmos.line_gradient_2d(Vec2::ZERO, Vec2::X, GREEN, RED);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn line_gradient_2d(
|
pub fn line_gradient_2d<C: Into<Color>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec2,
|
start: Vec2,
|
||||||
end: Vec2,
|
end: Vec2,
|
||||||
start_color: LegacyColor,
|
start_color: C,
|
||||||
end_color: LegacyColor,
|
end_color: C,
|
||||||
) {
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -450,13 +470,18 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.linestrip_2d([Vec2::ZERO, Vec2::X, Vec2::Y], LegacyColor::GREEN);
|
/// gizmos.linestrip_2d([Vec2::ZERO, Vec2::X, Vec2::Y], GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn linestrip_2d(&mut self, positions: impl IntoIterator<Item = Vec2>, color: LegacyColor) {
|
pub fn linestrip_2d(
|
||||||
|
&mut self,
|
||||||
|
positions: impl IntoIterator<Item = Vec2>,
|
||||||
|
color: impl Into<Color>,
|
||||||
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -472,19 +497,20 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN, BLUE};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.linestrip_gradient_2d([
|
/// gizmos.linestrip_gradient_2d([
|
||||||
/// (Vec2::ZERO, LegacyColor::GREEN),
|
/// (Vec2::ZERO, GREEN),
|
||||||
/// (Vec2::X, LegacyColor::RED),
|
/// (Vec2::X, RED),
|
||||||
/// (Vec2::Y, LegacyColor::BLUE)
|
/// (Vec2::Y, BLUE)
|
||||||
/// ]);
|
/// ]);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn linestrip_gradient_2d(
|
pub fn linestrip_gradient_2d<C: Into<Color>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
positions: impl IntoIterator<Item = (Vec2, LegacyColor)>,
|
positions: impl IntoIterator<Item = (Vec2, C)>,
|
||||||
) {
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -505,13 +531,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.ray_2d(Vec2::Y, Vec2::X, LegacyColor::GREEN);
|
/// gizmos.ray_2d(Vec2::Y, Vec2::X, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ray_2d(&mut self, start: Vec2, vector: Vec2, color: LegacyColor) {
|
pub fn ray_2d(&mut self, start: Vec2, vector: Vec2, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -527,18 +554,19 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, GREEN};
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.line_gradient(Vec3::Y, Vec3::X, LegacyColor::GREEN, LegacyColor::RED);
|
/// gizmos.line_gradient(Vec3::Y, Vec3::X, GREEN, RED);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ray_gradient_2d(
|
pub fn ray_gradient_2d<C: Into<Color>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Vec2,
|
start: Vec2,
|
||||||
vector: Vec2,
|
vector: Vec2,
|
||||||
start_color: LegacyColor,
|
start_color: C,
|
||||||
end_color: LegacyColor,
|
end_color: C,
|
||||||
) {
|
) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -555,13 +583,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.rect_2d(Vec2::ZERO, 0., Vec2::ONE, LegacyColor::GREEN);
|
/// gizmos.rect_2d(Vec2::ZERO, 0., Vec2::ONE, GREEN);
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # bevy_ecs::system::assert_is_system(system);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rect_2d(&mut self, position: Vec2, rotation: f32, size: Vec2, color: LegacyColor) {
|
pub fn rect_2d(&mut self, position: Vec2, rotation: f32, size: Vec2, color: impl Into<Color>) {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -578,17 +607,22 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extend_list_colors(&mut self, colors: impl IntoIterator<Item = LegacyColor>) {
|
fn extend_list_colors(&mut self, colors: impl IntoIterator<Item = impl Into<Color>>) {
|
||||||
self.buffer
|
self.buffer.list_colors.extend(
|
||||||
.list_colors
|
colors
|
||||||
.extend(colors.into_iter().map(LinearRgba::from));
|
.into_iter()
|
||||||
|
.map(|color| LinearRgba::from(color.into())),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_list_color(&mut self, color: LegacyColor, count: usize) {
|
fn add_list_color(&mut self, color: impl Into<Color>, count: usize) {
|
||||||
|
let polymorphic_color: Color = color.into();
|
||||||
|
let linear_color = LinearRgba::from(polymorphic_color);
|
||||||
|
|
||||||
self.buffer
|
self.buffer
|
||||||
.list_colors
|
.list_colors
|
||||||
.extend(iter::repeat(LinearRgba::from(color)).take(count));
|
.extend(iter::repeat(linear_color).take(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -608,7 +642,7 @@ pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
circle_segments: usize,
|
circle_segments: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
//! and assorted support items.
|
//! and assorted support items.
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
use bevy_color::LinearRgba;
|
||||||
use bevy_math::{Quat, UVec2, Vec2, Vec3};
|
use bevy_math::{Quat, UVec2, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
/// A builder returned by [`Gizmos::grid`] and [`Gizmos::grid_2d`]
|
/// A builder returned by [`Gizmos::grid`] and [`Gizmos::grid_2d`]
|
||||||
pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
|
@ -16,7 +16,7 @@ pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
cell_count: UVec2,
|
cell_count: UVec2,
|
||||||
skew: Vec2,
|
skew: Vec2,
|
||||||
outer_edges: bool,
|
outer_edges: bool,
|
||||||
color: LegacyColor,
|
color: LinearRgba,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: GizmoConfigGroup> GridBuilder<'_, '_, '_, T> {
|
impl<T: GizmoConfigGroup> GridBuilder<'_, '_, '_, T> {
|
||||||
|
@ -126,13 +126,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.grid(
|
/// gizmos.grid(
|
||||||
/// Vec3::ZERO,
|
/// Vec3::ZERO,
|
||||||
/// Quat::IDENTITY,
|
/// Quat::IDENTITY,
|
||||||
/// UVec2::new(10, 10),
|
/// UVec2::new(10, 10),
|
||||||
/// Vec2::splat(2.),
|
/// Vec2::splat(2.),
|
||||||
/// LegacyColor::GREEN
|
/// GREEN
|
||||||
/// )
|
/// )
|
||||||
/// .skew_x(0.25)
|
/// .skew_x(0.25)
|
||||||
/// .outer_edges(true);
|
/// .outer_edges(true);
|
||||||
|
@ -145,7 +146,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
cell_count: UVec2,
|
cell_count: UVec2,
|
||||||
spacing: Vec2,
|
spacing: Vec2,
|
||||||
color: LegacyColor,
|
color: impl Into<LinearRgba>,
|
||||||
) -> GridBuilder<'_, 'w, 's, T> {
|
) -> GridBuilder<'_, 'w, 's, T> {
|
||||||
GridBuilder {
|
GridBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -155,7 +156,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
cell_count,
|
cell_count,
|
||||||
skew: Vec2::ZERO,
|
skew: Vec2::ZERO,
|
||||||
outer_edges: false,
|
outer_edges: false,
|
||||||
color,
|
color: color.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,13 +182,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
/// # use bevy_gizmos::prelude::*;
|
/// # use bevy_gizmos::prelude::*;
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_math::prelude::*;
|
/// # use bevy_math::prelude::*;
|
||||||
|
/// # use bevy_color::palettes::basic::GREEN;
|
||||||
/// fn system(mut gizmos: Gizmos) {
|
/// fn system(mut gizmos: Gizmos) {
|
||||||
/// gizmos.grid_2d(
|
/// gizmos.grid_2d(
|
||||||
/// Vec2::ZERO,
|
/// Vec2::ZERO,
|
||||||
/// 0.0,
|
/// 0.0,
|
||||||
/// UVec2::new(10, 10),
|
/// UVec2::new(10, 10),
|
||||||
/// Vec2::splat(1.),
|
/// Vec2::splat(1.),
|
||||||
/// LegacyColor::GREEN
|
/// GREEN
|
||||||
/// )
|
/// )
|
||||||
/// .skew_x(0.25)
|
/// .skew_x(0.25)
|
||||||
/// .outer_edges(true);
|
/// .outer_edges(true);
|
||||||
|
@ -200,7 +202,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
rotation: f32,
|
rotation: f32,
|
||||||
cell_count: UVec2,
|
cell_count: UVec2,
|
||||||
spacing: Vec2,
|
spacing: Vec2,
|
||||||
color: LegacyColor,
|
color: impl Into<LinearRgba>,
|
||||||
) -> GridBuilder<'_, 'w, 's, T> {
|
) -> GridBuilder<'_, 'w, 's, T> {
|
||||||
GridBuilder {
|
GridBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -210,7 +212,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
|
||||||
cell_count,
|
cell_count,
|
||||||
skew: Vec2::ZERO,
|
skew: Vec2::ZERO,
|
||||||
outer_edges: false,
|
outer_edges: false,
|
||||||
color,
|
color: color.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
//! # use bevy_gizmos::prelude::*;
|
//! # use bevy_gizmos::prelude::*;
|
||||||
//! # use bevy_render::prelude::*;
|
//! # use bevy_render::prelude::*;
|
||||||
//! # use bevy_math::prelude::*;
|
//! # use bevy_math::prelude::*;
|
||||||
|
//! # use bevy_color::palettes::basic::GREEN;
|
||||||
//! fn system(mut gizmos: Gizmos) {
|
//! fn system(mut gizmos: Gizmos) {
|
||||||
//! gizmos.line(Vec3::ZERO, Vec3::X, LegacyColor::GREEN);
|
//! gizmos.line(Vec3::ZERO, Vec3::X, GREEN);
|
||||||
//! }
|
//! }
|
||||||
//! # bevy_ecs::system::assert_is_system(system);
|
//! # bevy_ecs::system::assert_is_system(system);
|
||||||
//! ```
|
//! ```
|
||||||
|
|
|
@ -4,12 +4,12 @@ use std::f32::consts::PI;
|
||||||
|
|
||||||
use super::helpers::*;
|
use super::helpers::*;
|
||||||
|
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::primitives::{
|
use bevy_math::primitives::{
|
||||||
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
|
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
|
||||||
Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
|
Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
|
||||||
};
|
};
|
||||||
use bevy_math::{Dir2, Mat2, Vec2};
|
use bevy_math::{Dir2, Mat2, Vec2};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ pub trait GizmoPrimitive2d<P: Primitive2d> {
|
||||||
primitive: P,
|
primitive: P,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_>;
|
) -> Self::Output<'_>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, T> {
|
||||||
primitive: Dir2,
|
primitive: Dir2,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -70,7 +70,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Circle> for Gizmos<'w, 's, T>
|
||||||
primitive: Circle,
|
primitive: Circle,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
_angle: f32,
|
_angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -90,7 +90,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Ellipse> for Gizmos<'w, 's, T
|
||||||
primitive: Ellipse,
|
primitive: Ellipse,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -110,8 +110,10 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's,
|
||||||
primitive: Capsule2d,
|
primitive: Capsule2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
|
let polymorphic_color: Color = color.into();
|
||||||
|
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,8 +138,8 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's,
|
||||||
.map(rotate_then_translate_2d(angle, position));
|
.map(rotate_then_translate_2d(angle, position));
|
||||||
|
|
||||||
// draw left and right side of capsule "rectangle"
|
// draw left and right side of capsule "rectangle"
|
||||||
self.line_2d(bottom_left, top_left, color);
|
self.line_2d(bottom_left, top_left, polymorphic_color);
|
||||||
self.line_2d(bottom_right, top_right, color);
|
self.line_2d(bottom_right, top_right, polymorphic_color);
|
||||||
|
|
||||||
// if the capsule is rotated we have to start the arc at a different offset angle,
|
// if the capsule is rotated we have to start the arc at a different offset angle,
|
||||||
// calculate that here
|
// calculate that here
|
||||||
|
@ -146,13 +148,19 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's,
|
||||||
let start_angle_bottom = PI + angle_offset;
|
let start_angle_bottom = PI + angle_offset;
|
||||||
|
|
||||||
// draw arcs
|
// draw arcs
|
||||||
self.arc_2d(top_center, start_angle_top, PI, primitive.radius, color);
|
self.arc_2d(
|
||||||
|
top_center,
|
||||||
|
start_angle_top,
|
||||||
|
PI,
|
||||||
|
primitive.radius,
|
||||||
|
polymorphic_color,
|
||||||
|
);
|
||||||
self.arc_2d(
|
self.arc_2d(
|
||||||
bottom_center,
|
bottom_center,
|
||||||
start_angle_bottom,
|
start_angle_bottom,
|
||||||
PI,
|
PI,
|
||||||
primitive.radius,
|
primitive.radius,
|
||||||
color,
|
polymorphic_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,9 +173,9 @@ pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
|
|
||||||
direction: Dir2, // Direction of the line
|
direction: Dir2, // Direction of the line
|
||||||
|
|
||||||
position: Vec2, // position of the center of the line
|
position: Vec2, // position of the center of the line
|
||||||
rotation: Mat2, // rotation of the line
|
rotation: Mat2, // rotation of the line
|
||||||
color: LegacyColor, // color of the line
|
color: Color, // color of the line
|
||||||
|
|
||||||
draw_arrow: bool, // decides whether to indicate the direction of the line with an arrow
|
draw_arrow: bool, // decides whether to indicate the direction of the line with an arrow
|
||||||
}
|
}
|
||||||
|
@ -188,14 +196,14 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Line2d> for Gizmos<'w, 's, T>
|
||||||
primitive: Line2d,
|
primitive: Line2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Line2dBuilder {
|
Line2dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
direction: primitive.direction,
|
direction: primitive.direction,
|
||||||
position,
|
position,
|
||||||
rotation: Mat2::from_angle(angle),
|
rotation: Mat2::from_angle(angle),
|
||||||
color,
|
color: color.into(),
|
||||||
draw_arrow: false,
|
draw_arrow: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,8 +247,10 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
|
||||||
primitive: Plane2d,
|
primitive: Plane2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
|
let polymorphic_color: Color = color.into();
|
||||||
|
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -257,13 +267,13 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
|
||||||
// offset the normal so it starts on the plane line
|
// offset the normal so it starts on the plane line
|
||||||
position + HALF_MIN_LINE_LEN * rotation * *normal,
|
position + HALF_MIN_LINE_LEN * rotation * *normal,
|
||||||
angle,
|
angle,
|
||||||
color,
|
polymorphic_color,
|
||||||
)
|
)
|
||||||
.draw_arrow(true);
|
.draw_arrow(true);
|
||||||
|
|
||||||
// draw the plane line
|
// draw the plane line
|
||||||
let direction = Dir2::new_unchecked(-normal.perp());
|
let direction = Dir2::new_unchecked(-normal.perp());
|
||||||
self.primitive_2d(Line2d { direction }, position, angle, color)
|
self.primitive_2d(Line2d { direction }, position, angle, polymorphic_color)
|
||||||
.draw_arrow(false);
|
.draw_arrow(false);
|
||||||
|
|
||||||
// draw an arrow such that the normal is always left side of the plane with respect to the
|
// draw an arrow such that the normal is always left side of the plane with respect to the
|
||||||
|
@ -271,7 +281,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
|
||||||
self.arrow_2d(
|
self.arrow_2d(
|
||||||
position,
|
position,
|
||||||
position + MIN_LINE_LEN * (rotation * *direction),
|
position + MIN_LINE_LEN * (rotation * *direction),
|
||||||
color,
|
polymorphic_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,9 +295,9 @@ pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
direction: Dir2, // Direction of the line segment
|
direction: Dir2, // Direction of the line segment
|
||||||
half_length: f32, // Half-length of the line segment
|
half_length: f32, // Half-length of the line segment
|
||||||
|
|
||||||
position: Vec2, // position of the center of the line segment
|
position: Vec2, // position of the center of the line segment
|
||||||
rotation: Mat2, // rotation of the line segment
|
rotation: Mat2, // rotation of the line segment
|
||||||
color: LegacyColor, // color of the line segment
|
color: Color, // color of the line segment
|
||||||
|
|
||||||
draw_arrow: bool, // decides whether to draw just a line or an arrow
|
draw_arrow: bool, // decides whether to draw just a line or an arrow
|
||||||
}
|
}
|
||||||
|
@ -308,7 +318,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's,
|
||||||
primitive: Segment2d,
|
primitive: Segment2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Segment2dBuilder {
|
Segment2dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -317,7 +327,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's,
|
||||||
|
|
||||||
position,
|
position,
|
||||||
rotation: Mat2::from_angle(angle),
|
rotation: Mat2::from_angle(angle),
|
||||||
color,
|
color: color.into(),
|
||||||
|
|
||||||
draw_arrow: Default::default(),
|
draw_arrow: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -354,7 +364,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polyline2d<N>
|
||||||
primitive: Polyline2d<N>,
|
primitive: Polyline2d<N>,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -381,7 +391,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolyline2d> for Gizmos<'
|
||||||
primitive: BoxedPolyline2d,
|
primitive: BoxedPolyline2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -408,7 +418,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Triangle2d> for Gizmos<'w, 's
|
||||||
primitive: Triangle2d,
|
primitive: Triangle2d,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -429,7 +439,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Rectangle> for Gizmos<'w, 's,
|
||||||
primitive: Rectangle,
|
primitive: Rectangle,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -459,7 +469,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d<Polygon<N>>
|
||||||
primitive: Polygon<N>,
|
primitive: Polygon<N>,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -496,7 +506,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<BoxedPolygon> for Gizmos<'w,
|
||||||
primitive: BoxedPolygon,
|
primitive: BoxedPolygon,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -531,7 +541,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<RegularPolygon> for Gizmos<'w
|
||||||
primitive: RegularPolygon,
|
primitive: RegularPolygon,
|
||||||
position: Vec2,
|
position: Vec2,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
color: LegacyColor,
|
color: impl Into<Color>,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
use super::helpers::*;
|
use super::helpers::*;
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::primitives::{
|
use bevy_math::primitives::{
|
||||||
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d,
|
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d,
|
||||||
Polyline3d, Primitive3d, Segment3d, Sphere, Torus,
|
Polyline3d, Primitive3d, Segment3d, Sphere, Torus,
|
||||||
};
|
};
|
||||||
use bevy_math::{Dir3, Quat, Vec3};
|
use bevy_math::{Dir3, Quat, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ pub trait GizmoPrimitive3d<P: Primitive3d> {
|
||||||
primitive: P,
|
primitive: P,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_>;
|
) -> Self::Output<'_>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Dir3> for Gizmos<'w, 's, T> {
|
||||||
primitive: Dir3,
|
primitive: Dir3,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
self.arrow(position, position + (rotation * *primitive), color);
|
self.arrow(position, position + (rotation * *primitive), color);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// Center position of the sphere in 3D space
|
// Center position of the sphere in 3D space
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
// Color of the sphere
|
// Color of the sphere
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments used to approximate the sphere geometry
|
// Number of segments used to approximate the sphere geometry
|
||||||
segments: usize,
|
segments: usize,
|
||||||
|
@ -85,7 +85,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Sphere> for Gizmos<'w, 's, T>
|
||||||
primitive: Sphere,
|
primitive: Sphere,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
SphereBuilder {
|
SphereBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -146,7 +146,7 @@ pub struct Plane3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// Center position of the sphere in 3D space
|
// Center position of the sphere in 3D space
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
// Color of the sphere
|
// Color of the sphere
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of axis to hint the plane
|
// Number of axis to hint the plane
|
||||||
axis_count: usize,
|
axis_count: usize,
|
||||||
|
@ -184,7 +184,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Plane3d> for Gizmos<'w, 's, T
|
||||||
primitive: Plane3d,
|
primitive: Plane3d,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Plane3dBuilder {
|
Plane3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -251,7 +251,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Line3d> for Gizmos<'w, 's, T>
|
||||||
primitive: Line3d,
|
primitive: Line3d,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -278,7 +278,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Segment3d> for Gizmos<'w, 's,
|
||||||
primitive: Segment3d,
|
primitive: Segment3d,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -303,7 +303,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive3d<Polyline3d<N>
|
||||||
primitive: Polyline3d<N>,
|
primitive: Polyline3d<N>,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -328,7 +328,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<BoxedPolyline3d> for Gizmos<'
|
||||||
primitive: BoxedPolyline3d,
|
primitive: BoxedPolyline3d,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -355,7 +355,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cuboid> for Gizmos<'w, 's, T>
|
||||||
primitive: Cuboid,
|
primitive: Cuboid,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return;
|
return;
|
||||||
|
@ -417,7 +417,7 @@ pub struct Cylinder3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// default orientation is: the cylinder is aligned with `Vec3::Y` axis
|
// default orientation is: the cylinder is aligned with `Vec3::Y` axis
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
// Color of the cylinder
|
// Color of the cylinder
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments used to approximate the cylinder geometry
|
// Number of segments used to approximate the cylinder geometry
|
||||||
segments: usize,
|
segments: usize,
|
||||||
|
@ -439,7 +439,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cylinder> for Gizmos<'w, 's,
|
||||||
primitive: Cylinder,
|
primitive: Cylinder,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Cylinder3dBuilder {
|
Cylinder3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -514,7 +514,7 @@ pub struct Capsule3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// default orientation is: the capsule is aligned with `Vec3::Y` axis
|
// default orientation is: the capsule is aligned with `Vec3::Y` axis
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
// Color of the capsule
|
// Color of the capsule
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments used to approximate the capsule geometry
|
// Number of segments used to approximate the capsule geometry
|
||||||
segments: usize,
|
segments: usize,
|
||||||
|
@ -536,7 +536,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Capsule3d> for Gizmos<'w, 's,
|
||||||
primitive: Capsule3d,
|
primitive: Capsule3d,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Capsule3dBuilder {
|
Capsule3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -607,7 +607,7 @@ pub struct Cone3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// default orientation is: cone base normal is aligned with the `Vec3::Y` axis
|
// default orientation is: cone base normal is aligned with the `Vec3::Y` axis
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
// Color of the cone
|
// Color of the cone
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments used to approximate the cone geometry
|
// Number of segments used to approximate the cone geometry
|
||||||
segments: usize,
|
segments: usize,
|
||||||
|
@ -629,7 +629,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Cone> for Gizmos<'w, 's, T> {
|
||||||
primitive: Cone,
|
primitive: Cone,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Cone3dBuilder {
|
Cone3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -703,7 +703,7 @@ pub struct ConicalFrustum3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// default orientation is: conical frustum base shape normals are aligned with `Vec3::Y` axis
|
// default orientation is: conical frustum base shape normals are aligned with `Vec3::Y` axis
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
// Color of the conical frustum
|
// Color of the conical frustum
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments used to approximate the curved surfaces
|
// Number of segments used to approximate the curved surfaces
|
||||||
segments: usize,
|
segments: usize,
|
||||||
|
@ -725,7 +725,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<ConicalFrustum> for Gizmos<'w
|
||||||
primitive: ConicalFrustum,
|
primitive: ConicalFrustum,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
ConicalFrustum3dBuilder {
|
ConicalFrustum3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
@ -807,7 +807,7 @@ pub struct Torus3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
|
||||||
// default orientation is: major circle normal is aligned with `Vec3::Y` axis
|
// default orientation is: major circle normal is aligned with `Vec3::Y` axis
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
// Color of the torus
|
// Color of the torus
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
|
|
||||||
// Number of segments in the minor (tube) direction
|
// Number of segments in the minor (tube) direction
|
||||||
minor_segments: usize,
|
minor_segments: usize,
|
||||||
|
@ -837,7 +837,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Torus> for Gizmos<'w, 's, T>
|
||||||
primitive: Torus,
|
primitive: Torus,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) -> Self::Output<'_> {
|
) -> Self::Output<'_> {
|
||||||
Torus3dBuilder {
|
Torus3dBuilder {
|
||||||
gizmos: self,
|
gizmos: self,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_math::{Mat2, Quat, Vec2, Vec3};
|
use bevy_math::{Mat2, Quat, Vec2, Vec3};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ pub(crate) fn draw_semi_sphere<T: GizmoConfigGroup>(
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
center: Vec3,
|
center: Vec3,
|
||||||
top: Vec3,
|
top: Vec3,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) {
|
) {
|
||||||
circle_coordinates(radius, segments)
|
circle_coordinates(radius, segments)
|
||||||
.map(|p| Vec3::new(p.x, 0.0, p.y))
|
.map(|p| Vec3::new(p.x, 0.0, p.y))
|
||||||
|
@ -81,7 +81,7 @@ pub(crate) fn draw_circle_3d<T: GizmoConfigGroup>(
|
||||||
segments: usize,
|
segments: usize,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
translation: Vec3,
|
translation: Vec3,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) {
|
) {
|
||||||
let positions = (0..=segments)
|
let positions = (0..=segments)
|
||||||
.map(|frac| frac as f32 / segments as f32)
|
.map(|frac| frac as f32 / segments as f32)
|
||||||
|
@ -100,7 +100,7 @@ pub(crate) fn draw_cylinder_vertical_lines<T: GizmoConfigGroup>(
|
||||||
half_height: f32,
|
half_height: f32,
|
||||||
rotation: Quat,
|
rotation: Quat,
|
||||||
center: Vec3,
|
center: Vec3,
|
||||||
color: LegacyColor,
|
color: Color,
|
||||||
) {
|
) {
|
||||||
circle_coordinates(radius, segments)
|
circle_coordinates(radius, segments)
|
||||||
.map(move |point_2d| {
|
.map(move |point_2d| {
|
||||||
|
|
|
@ -17,6 +17,7 @@ pbr_transmission_textures = []
|
||||||
bevy_animation = { path = "../bevy_animation", version = "0.14.0-dev", optional = true }
|
bevy_animation = { path = "../bevy_animation", version = "0.14.0-dev", optional = true }
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
|
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||||
bevy_core = { path = "../bevy_core", version = "0.14.0-dev" }
|
bevy_core = { path = "../bevy_core", version = "0.14.0-dev" }
|
||||||
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
|
|
|
@ -3,6 +3,7 @@ use bevy_animation::{AnimationTarget, AnimationTargetId};
|
||||||
use bevy_asset::{
|
use bevy_asset::{
|
||||||
io::Reader, AssetLoadError, AssetLoader, AsyncReadExt, Handle, LoadContext, ReadAssetBytesError,
|
io::Reader, AssetLoadError, AssetLoader, AsyncReadExt, Handle, LoadContext, ReadAssetBytesError,
|
||||||
};
|
};
|
||||||
|
use bevy_color::{Color, LinearRgba};
|
||||||
use bevy_core::Name;
|
use bevy_core::Name;
|
||||||
use bevy_core_pipeline::prelude::Camera3dBundle;
|
use bevy_core_pipeline::prelude::Camera3dBundle;
|
||||||
use bevy_ecs::entity::EntityHashMap;
|
use bevy_ecs::entity::EntityHashMap;
|
||||||
|
@ -17,7 +18,6 @@ use bevy_pbr::{
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
alpha::AlphaMode,
|
alpha::AlphaMode,
|
||||||
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
|
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
|
||||||
color::LegacyColor,
|
|
||||||
mesh::{
|
mesh::{
|
||||||
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
|
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
|
||||||
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
|
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
|
||||||
|
@ -913,8 +913,13 @@ fn load_material(
|
||||||
|
|
||||||
let ior = material.ior().unwrap_or(1.5);
|
let ior = material.ior().unwrap_or(1.5);
|
||||||
|
|
||||||
|
// We need to operate in the Linear color space and be willing to exceed 1.0 in our channels
|
||||||
|
let base_emissive = LinearRgba::rgb(emissive[0], emissive[1], emissive[2]);
|
||||||
|
let scaled_emissive = base_emissive * material.emissive_strength().unwrap_or(1.0);
|
||||||
|
let emissive = Color::from(scaled_emissive);
|
||||||
|
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
base_color: LegacyColor::rgba_linear(color[0], color[1], color[2], color[3]),
|
base_color: Color::linear_rgba(color[0], color[1], color[2], color[3]),
|
||||||
base_color_texture,
|
base_color_texture,
|
||||||
perceptual_roughness: pbr.roughness_factor(),
|
perceptual_roughness: pbr.roughness_factor(),
|
||||||
metallic: pbr.metallic_factor(),
|
metallic: pbr.metallic_factor(),
|
||||||
|
@ -929,8 +934,7 @@ fn load_material(
|
||||||
Some(Face::Back)
|
Some(Face::Back)
|
||||||
},
|
},
|
||||||
occlusion_texture,
|
occlusion_texture,
|
||||||
emissive: LegacyColor::rgb_linear(emissive[0], emissive[1], emissive[2])
|
emissive,
|
||||||
* material.emissive_strength().unwrap_or(1.0),
|
|
||||||
emissive_texture,
|
emissive_texture,
|
||||||
specular_transmission,
|
specular_transmission,
|
||||||
#[cfg(feature = "pbr_transmission_textures")]
|
#[cfg(feature = "pbr_transmission_textures")]
|
||||||
|
@ -940,7 +944,7 @@ fn load_material(
|
||||||
thickness_texture,
|
thickness_texture,
|
||||||
ior,
|
ior,
|
||||||
attenuation_distance,
|
attenuation_distance,
|
||||||
attenuation_color: LegacyColor::rgb_linear(
|
attenuation_color: Color::linear_rgb(
|
||||||
attenuation_color[0],
|
attenuation_color[0],
|
||||||
attenuation_color[1],
|
attenuation_color[1],
|
||||||
attenuation_color[2],
|
attenuation_color[2],
|
||||||
|
@ -1169,7 +1173,7 @@ fn load_node(
|
||||||
gltf::khr_lights_punctual::Kind::Directional => {
|
gltf::khr_lights_punctual::Kind::Directional => {
|
||||||
let mut entity = parent.spawn(DirectionalLightBundle {
|
let mut entity = parent.spawn(DirectionalLightBundle {
|
||||||
directional_light: DirectionalLight {
|
directional_light: DirectionalLight {
|
||||||
color: LegacyColor::rgb_from_array(light.color()),
|
color: Color::srgb_from_array(light.color()),
|
||||||
// NOTE: KHR_punctual_lights defines the intensity units for directional
|
// NOTE: KHR_punctual_lights defines the intensity units for directional
|
||||||
// lights in lux (lm/m^2) which is what we need.
|
// lights in lux (lm/m^2) which is what we need.
|
||||||
illuminance: light.intensity(),
|
illuminance: light.intensity(),
|
||||||
|
@ -1189,7 +1193,7 @@ fn load_node(
|
||||||
gltf::khr_lights_punctual::Kind::Point => {
|
gltf::khr_lights_punctual::Kind::Point => {
|
||||||
let mut entity = parent.spawn(PointLightBundle {
|
let mut entity = parent.spawn(PointLightBundle {
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
color: LegacyColor::rgb_from_array(light.color()),
|
color: Color::srgb_from_array(light.color()),
|
||||||
// NOTE: KHR_punctual_lights defines the intensity units for point lights in
|
// NOTE: KHR_punctual_lights defines the intensity units for point lights in
|
||||||
// candela (lm/sr) which is luminous intensity and we need luminous power.
|
// candela (lm/sr) which is luminous intensity and we need luminous power.
|
||||||
// For a point light, luminous power = 4 * pi * luminous intensity
|
// For a point light, luminous power = 4 * pi * luminous intensity
|
||||||
|
@ -1215,7 +1219,7 @@ fn load_node(
|
||||||
} => {
|
} => {
|
||||||
let mut entity = parent.spawn(SpotLightBundle {
|
let mut entity = parent.spawn(SpotLightBundle {
|
||||||
spot_light: SpotLight {
|
spot_light: SpotLight {
|
||||||
color: LegacyColor::rgb_from_array(light.color()),
|
color: Color::srgb_from_array(light.color()),
|
||||||
// NOTE: KHR_punctual_lights defines the intensity units for spot lights in
|
// NOTE: KHR_punctual_lights defines the intensity units for spot lights in
|
||||||
// candela (lm/sr) which is luminous intensity and we need luminous power.
|
// candela (lm/sr) which is luminous intensity and we need luminous power.
|
||||||
// For a spot light, we map luminous power = 4 * pi * luminous intensity
|
// For a spot light, we map luminous power = 4 * pi * luminous intensity
|
||||||
|
|
|
@ -183,8 +183,9 @@ pub mod gizmos {
|
||||||
//! # use bevy_gizmos::prelude::*;
|
//! # use bevy_gizmos::prelude::*;
|
||||||
//! # use bevy_render::prelude::*;
|
//! # use bevy_render::prelude::*;
|
||||||
//! # use bevy_math::prelude::*;
|
//! # use bevy_math::prelude::*;
|
||||||
|
//! # use bevy_color::palettes::basic::GREEN;
|
||||||
//! fn system(mut gizmos: Gizmos) {
|
//! fn system(mut gizmos: Gizmos) {
|
||||||
//! gizmos.line(Vec3::ZERO, Vec3::X, LegacyColor::GREEN);
|
//! gizmos.line(Vec3::ZERO, Vec3::X, GREEN);
|
||||||
//! }
|
//! }
|
||||||
//! # bevy_ecs::system::assert_is_system(system);
|
//! # bevy_ecs::system::assert_is_system(system);
|
||||||
//! ```
|
//! ```
|
||||||
|
|
|
@ -20,6 +20,7 @@ ios_simulator = ["bevy_render/ios_simulator"]
|
||||||
# bevy
|
# bevy
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
|
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||||
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
use bevy_color::{Color, LinearRgba};
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_math::Vec3;
|
use bevy_math::Vec3;
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_render::{color::LegacyColor, extract_component::ExtractComponent, prelude::Camera};
|
use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
|
||||||
|
|
||||||
/// Configures the “classic” computer graphics [distance fog](https://en.wikipedia.org/wiki/Distance_fog) effect,
|
/// Configures the “classic” computer graphics [distance fog](https://en.wikipedia.org/wiki/Distance_fog) effect,
|
||||||
/// in which objects appear progressively more covered in atmospheric haze the further away they are from the camera.
|
/// in which objects appear progressively more covered in atmospheric haze the further away they are from the camera.
|
||||||
|
@ -24,6 +25,7 @@ use bevy_render::{color::LegacyColor, extract_component::ExtractComponent, prelu
|
||||||
/// # use bevy_render::prelude::*;
|
/// # use bevy_render::prelude::*;
|
||||||
/// # use bevy_core_pipeline::prelude::*;
|
/// # use bevy_core_pipeline::prelude::*;
|
||||||
/// # use bevy_pbr::prelude::*;
|
/// # use bevy_pbr::prelude::*;
|
||||||
|
/// # use bevy_color::Color;
|
||||||
/// # fn system(mut commands: Commands) {
|
/// # fn system(mut commands: Commands) {
|
||||||
/// commands.spawn((
|
/// commands.spawn((
|
||||||
/// // Setup your camera as usual
|
/// // Setup your camera as usual
|
||||||
|
@ -33,7 +35,7 @@ use bevy_render::{color::LegacyColor, extract_component::ExtractComponent, prelu
|
||||||
/// },
|
/// },
|
||||||
/// // Add fog to the same entity
|
/// // Add fog to the same entity
|
||||||
/// FogSettings {
|
/// FogSettings {
|
||||||
/// color: LegacyColor::WHITE,
|
/// color: Color::WHITE,
|
||||||
/// falloff: FogFalloff::Exponential { density: 1e-3 },
|
/// falloff: FogFalloff::Exponential { density: 1e-3 },
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// },
|
/// },
|
||||||
|
@ -54,14 +56,14 @@ pub struct FogSettings {
|
||||||
///
|
///
|
||||||
/// **Tip:** The alpha channel of the color can be used to “modulate” the fog effect without
|
/// **Tip:** The alpha channel of the color can be used to “modulate” the fog effect without
|
||||||
/// changing the fog falloff mode or parameters.
|
/// changing the fog falloff mode or parameters.
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
|
|
||||||
/// Color used to modulate the influence of directional light colors on the
|
/// Color used to modulate the influence of directional light colors on the
|
||||||
/// fog, where the view direction aligns with each directional light direction,
|
/// fog, where the view direction aligns with each directional light direction,
|
||||||
/// producing a “glow” or light dispersion effect. (e.g. around the sun)
|
/// producing a “glow” or light dispersion effect. (e.g. around the sun)
|
||||||
///
|
///
|
||||||
/// Use [`LegacyColor::NONE`] to disable the effect.
|
/// Use [`Color::NONE`] to disable the effect.
|
||||||
pub directional_light_color: LegacyColor,
|
pub directional_light_color: Color,
|
||||||
|
|
||||||
/// The exponent applied to the directional light alignment calculation.
|
/// The exponent applied to the directional light alignment calculation.
|
||||||
/// A higher value means a more concentrated “glow”.
|
/// A higher value means a more concentrated “glow”.
|
||||||
|
@ -345,7 +347,7 @@ impl FogFalloff {
|
||||||
/// [`FogFalloff::REVISED_KOSCHMIEDER_CONTRAST_THRESHOLD`].
|
/// [`FogFalloff::REVISED_KOSCHMIEDER_CONTRAST_THRESHOLD`].
|
||||||
pub fn from_visibility_color(
|
pub fn from_visibility_color(
|
||||||
visibility: f32,
|
visibility: f32,
|
||||||
extinction_inscattering_color: LegacyColor,
|
extinction_inscattering_color: Color,
|
||||||
) -> FogFalloff {
|
) -> FogFalloff {
|
||||||
FogFalloff::from_visibility_contrast_colors(
|
FogFalloff::from_visibility_contrast_colors(
|
||||||
visibility,
|
visibility,
|
||||||
|
@ -361,12 +363,12 @@ impl FogFalloff {
|
||||||
///
|
///
|
||||||
/// ## Tips
|
/// ## Tips
|
||||||
/// - Alpha values of the provided colors can modulate the `extinction` and `inscattering` effects;
|
/// - Alpha values of the provided colors can modulate the `extinction` and `inscattering` effects;
|
||||||
/// - Using an `extinction_color` of [`LegacyColor::WHITE`] or [`LegacyColor::NONE`] disables the extinction effect;
|
/// - Using an `extinction_color` of [`Color::WHITE`] or [`Color::NONE`] disables the extinction effect;
|
||||||
/// - Using an `inscattering_color` of [`LegacyColor::BLACK`] or [`LegacyColor::NONE`] disables the inscattering effect.
|
/// - Using an `inscattering_color` of [`Color::BLACK`] or [`Color::NONE`] disables the inscattering effect.
|
||||||
pub fn from_visibility_colors(
|
pub fn from_visibility_colors(
|
||||||
visibility: f32,
|
visibility: f32,
|
||||||
extinction_color: LegacyColor,
|
extinction_color: Color,
|
||||||
inscattering_color: LegacyColor,
|
inscattering_color: Color,
|
||||||
) -> FogFalloff {
|
) -> FogFalloff {
|
||||||
FogFalloff::from_visibility_contrast_colors(
|
FogFalloff::from_visibility_contrast_colors(
|
||||||
visibility,
|
visibility,
|
||||||
|
@ -381,7 +383,7 @@ impl FogFalloff {
|
||||||
pub fn from_visibility_contrast_color(
|
pub fn from_visibility_contrast_color(
|
||||||
visibility: f32,
|
visibility: f32,
|
||||||
contrast_threshold: f32,
|
contrast_threshold: f32,
|
||||||
extinction_inscattering_color: LegacyColor,
|
extinction_inscattering_color: Color,
|
||||||
) -> FogFalloff {
|
) -> FogFalloff {
|
||||||
FogFalloff::from_visibility_contrast_colors(
|
FogFalloff::from_visibility_contrast_colors(
|
||||||
visibility,
|
visibility,
|
||||||
|
@ -396,18 +398,18 @@ impl FogFalloff {
|
||||||
///
|
///
|
||||||
/// ## Tips
|
/// ## Tips
|
||||||
/// - Alpha values of the provided colors can modulate the `extinction` and `inscattering` effects;
|
/// - Alpha values of the provided colors can modulate the `extinction` and `inscattering` effects;
|
||||||
/// - Using an `extinction_color` of [`LegacyColor::WHITE`] or [`LegacyColor::NONE`] disables the extinction effect;
|
/// - Using an `extinction_color` of [`Color::WHITE`] or [`Color::NONE`] disables the extinction effect;
|
||||||
/// - Using an `inscattering_color` of [`LegacyColor::BLACK`] or [`LegacyColor::NONE`] disables the inscattering effect.
|
/// - Using an `inscattering_color` of [`Color::BLACK`] or [`Color::NONE`] disables the inscattering effect.
|
||||||
pub fn from_visibility_contrast_colors(
|
pub fn from_visibility_contrast_colors(
|
||||||
visibility: f32,
|
visibility: f32,
|
||||||
contrast_threshold: f32,
|
contrast_threshold: f32,
|
||||||
extinction_color: LegacyColor,
|
extinction_color: Color,
|
||||||
inscattering_color: LegacyColor,
|
inscattering_color: Color,
|
||||||
) -> FogFalloff {
|
) -> FogFalloff {
|
||||||
use std::f32::consts::E;
|
use std::f32::consts::E;
|
||||||
|
|
||||||
let [r_e, g_e, b_e, a_e] = extinction_color.as_linear_rgba_f32();
|
let [r_e, g_e, b_e, a_e] = LinearRgba::from(extinction_color).to_f32_array();
|
||||||
let [r_i, g_i, b_i, a_i] = inscattering_color.as_linear_rgba_f32();
|
let [r_i, g_i, b_i, a_i] = LinearRgba::from(inscattering_color).to_f32_array();
|
||||||
|
|
||||||
FogFalloff::Atmospheric {
|
FogFalloff::Atmospheric {
|
||||||
extinction: Vec3::new(
|
extinction: Vec3::new(
|
||||||
|
@ -464,12 +466,12 @@ impl FogFalloff {
|
||||||
impl Default for FogSettings {
|
impl Default for FogSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba(1.0, 1.0, 1.0, 1.0),
|
color: Color::WHITE,
|
||||||
falloff: FogFalloff::Linear {
|
falloff: FogFalloff::Linear {
|
||||||
start: 0.0,
|
start: 0.0,
|
||||||
end: 100.0,
|
end: 100.0,
|
||||||
},
|
},
|
||||||
directional_light_color: LegacyColor::NONE,
|
directional_light_color: Color::NONE,
|
||||||
directional_light_exponent: 8.0,
|
directional_light_exponent: 8.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ mod prepass;
|
||||||
mod render;
|
mod render;
|
||||||
mod ssao;
|
mod ssao;
|
||||||
|
|
||||||
|
use bevy_color::{Color, LinearRgba};
|
||||||
pub use bundle::*;
|
pub use bundle::*;
|
||||||
pub use extended_material::*;
|
pub use extended_material::*;
|
||||||
pub use fog::*;
|
pub use fog::*;
|
||||||
|
@ -73,7 +74,6 @@ use bevy_render::{
|
||||||
camera::{CameraUpdateSystem, Projection},
|
camera::{CameraUpdateSystem, Projection},
|
||||||
extract_component::ExtractComponentPlugin,
|
extract_component::ExtractComponentPlugin,
|
||||||
extract_resource::ExtractResourcePlugin,
|
extract_resource::ExtractResourcePlugin,
|
||||||
prelude::LegacyColor,
|
|
||||||
render_asset::prepare_assets,
|
render_asset::prepare_assets,
|
||||||
render_graph::RenderGraph,
|
render_graph::RenderGraph,
|
||||||
render_phase::sort_phase_system,
|
render_phase::sort_phase_system,
|
||||||
|
@ -336,7 +336,7 @@ impl Plugin for PbrPlugin {
|
||||||
app.world.resource_mut::<Assets<StandardMaterial>>().insert(
|
app.world.resource_mut::<Assets<StandardMaterial>>().insert(
|
||||||
Handle::<StandardMaterial>::default(),
|
Handle::<StandardMaterial>::default(),
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(1.0, 0.0, 0.5),
|
base_color: Color::srgb(1.0, 0.0, 0.5),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -97,7 +97,7 @@ pub mod light_consts {
|
||||||
#[derive(Component, Debug, Clone, Copy, Reflect)]
|
#[derive(Component, Debug, Clone, Copy, Reflect)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
pub struct PointLight {
|
pub struct PointLight {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
|
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
|
||||||
pub intensity: f32,
|
pub intensity: f32,
|
||||||
pub range: f32,
|
pub range: f32,
|
||||||
|
@ -113,7 +113,7 @@ pub struct PointLight {
|
||||||
impl Default for PointLight {
|
impl Default for PointLight {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
PointLight {
|
PointLight {
|
||||||
color: LegacyColor::rgb(1.0, 1.0, 1.0),
|
color: Color::WHITE,
|
||||||
// 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
|
// 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
|
||||||
// default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
|
// default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
|
||||||
// this would be way too bright.
|
// this would be way too bright.
|
||||||
|
@ -151,7 +151,7 @@ impl Default for PointLightShadowMap {
|
||||||
#[derive(Component, Debug, Clone, Copy, Reflect)]
|
#[derive(Component, Debug, Clone, Copy, Reflect)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
pub struct SpotLight {
|
pub struct SpotLight {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
|
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
|
||||||
pub intensity: f32,
|
pub intensity: f32,
|
||||||
pub range: f32,
|
pub range: f32,
|
||||||
|
@ -184,7 +184,7 @@ impl Default for SpotLight {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
// a quarter arc attenuating from the center
|
// a quarter arc attenuating from the center
|
||||||
Self {
|
Self {
|
||||||
color: LegacyColor::rgb(1.0, 1.0, 1.0),
|
color: Color::WHITE,
|
||||||
// 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
|
// 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
|
||||||
// default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
|
// default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
|
||||||
// this would be way too bright.
|
// this would be way too bright.
|
||||||
|
@ -250,7 +250,7 @@ impl Default for SpotLight {
|
||||||
#[derive(Component, Debug, Clone, Reflect)]
|
#[derive(Component, Debug, Clone, Reflect)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
pub struct DirectionalLight {
|
pub struct DirectionalLight {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
/// Illuminance in lux (lumens per square meter), representing the amount of
|
/// Illuminance in lux (lumens per square meter), representing the amount of
|
||||||
/// light projected onto surfaces by this light source. Lux is used here
|
/// light projected onto surfaces by this light source. Lux is used here
|
||||||
/// instead of lumens because a directional light illuminates all surfaces
|
/// instead of lumens because a directional light illuminates all surfaces
|
||||||
|
@ -268,7 +268,7 @@ pub struct DirectionalLight {
|
||||||
impl Default for DirectionalLight {
|
impl Default for DirectionalLight {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
DirectionalLight {
|
DirectionalLight {
|
||||||
color: LegacyColor::rgb(1.0, 1.0, 1.0),
|
color: Color::WHITE,
|
||||||
illuminance: light_consts::lux::AMBIENT_DAYLIGHT,
|
illuminance: light_consts::lux::AMBIENT_DAYLIGHT,
|
||||||
shadows_enabled: false,
|
shadows_enabled: false,
|
||||||
shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS,
|
shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS,
|
||||||
|
@ -635,7 +635,7 @@ fn calculate_cascade(
|
||||||
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
|
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct AmbientLight {
|
pub struct AmbientLight {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
/// A direct scale factor multiplied with `color` before being passed to the shader.
|
/// A direct scale factor multiplied with `color` before being passed to the shader.
|
||||||
pub brightness: f32,
|
pub brightness: f32,
|
||||||
}
|
}
|
||||||
|
@ -643,14 +643,14 @@ pub struct AmbientLight {
|
||||||
impl Default for AmbientLight {
|
impl Default for AmbientLight {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 80.0,
|
brightness: 80.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl AmbientLight {
|
impl AmbientLight {
|
||||||
pub const NONE: AmbientLight = AmbientLight {
|
pub const NONE: AmbientLight = AmbientLight {
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 0.0,
|
brightness: 0.0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,9 @@ use self::{irradiance_volume::IrradianceVolume, prelude::EnvironmentMapLight};
|
||||||
/// # use bevy_pbr::{Material, MaterialMeshBundle};
|
/// # use bevy_pbr::{Material, MaterialMeshBundle};
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_reflect::TypePath;
|
/// # use bevy_reflect::TypePath;
|
||||||
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image, color::LegacyColor};
|
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
|
/// # use bevy_color::palettes::basic::RED;
|
||||||
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
||||||
///
|
///
|
||||||
/// #[derive(AsBindGroup, Debug, Clone, Asset, TypePath)]
|
/// #[derive(AsBindGroup, Debug, Clone, Asset, TypePath)]
|
||||||
|
@ -57,7 +59,7 @@ use self::{irradiance_volume::IrradianceVolume, prelude::EnvironmentMapLight};
|
||||||
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
||||||
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
||||||
/// // add the sampler attribute with a different binding index.
|
/// // add the sampler attribute with a different binding index.
|
||||||
/// #[texture(1)]
|
/// #[texture(1)]
|
||||||
|
@ -77,7 +79,7 @@ use self::{irradiance_volume::IrradianceVolume, prelude::EnvironmentMapLight};
|
||||||
/// fn setup(mut commands: Commands, mut materials: ResMut<Assets<CustomMaterial>>, asset_server: Res<AssetServer>) {
|
/// fn setup(mut commands: Commands, mut materials: ResMut<Assets<CustomMaterial>>, asset_server: Res<AssetServer>) {
|
||||||
/// commands.spawn(MaterialMeshBundle {
|
/// commands.spawn(MaterialMeshBundle {
|
||||||
/// material: materials.add(CustomMaterial {
|
/// material: materials.add(CustomMaterial {
|
||||||
/// color: LegacyColor::RED,
|
/// color: RED.into(),
|
||||||
/// color_texture: asset_server.load("some_image.png"),
|
/// color_texture: asset_server.load("some_image.png"),
|
||||||
/// }),
|
/// }),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use bevy_asset::Asset;
|
use bevy_asset::Asset;
|
||||||
|
use bevy_color::Alpha;
|
||||||
use bevy_math::{Affine2, Mat3, Vec4};
|
use bevy_math::{Affine2, Mat3, Vec4};
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_render::{mesh::MeshVertexBufferLayout, render_asset::RenderAssets, render_resource::*};
|
use bevy_render::{mesh::MeshVertexBufferLayout, render_asset::RenderAssets, render_resource::*};
|
||||||
|
@ -10,7 +11,7 @@ use crate::*;
|
||||||
/// Standard property values with pictures here
|
/// Standard property values with pictures here
|
||||||
/// <https://google.github.io/filament/Material%20Properties.pdf>.
|
/// <https://google.github.io/filament/Material%20Properties.pdf>.
|
||||||
///
|
///
|
||||||
/// May be created directly from a [`LegacyColor`] or an [`Image`].
|
/// May be created directly from a [`Color`] or an [`Image`].
|
||||||
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
|
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
|
||||||
#[bind_group_data(StandardMaterialKey)]
|
#[bind_group_data(StandardMaterialKey)]
|
||||||
#[uniform(0, StandardMaterialUniform)]
|
#[uniform(0, StandardMaterialUniform)]
|
||||||
|
@ -22,15 +23,15 @@ pub struct StandardMaterial {
|
||||||
/// in between. If used together with a `base_color_texture`, this is factored into the final
|
/// in between. If used together with a `base_color_texture`, this is factored into the final
|
||||||
/// base color as `base_color * base_color_texture_value`
|
/// base color as `base_color * base_color_texture_value`
|
||||||
///
|
///
|
||||||
/// Defaults to [`LegacyColor::WHITE`].
|
/// Defaults to [`Color::WHITE`].
|
||||||
pub base_color: LegacyColor,
|
pub base_color: Color,
|
||||||
|
|
||||||
/// The texture component of the material's color before lighting.
|
/// The texture component of the material's color before lighting.
|
||||||
/// The actual pre-lighting color is `base_color * this_texture`.
|
/// The actual pre-lighting color is `base_color * this_texture`.
|
||||||
///
|
///
|
||||||
/// See [`base_color`] for details.
|
/// See [`base_color`] for details.
|
||||||
///
|
///
|
||||||
/// You should set `base_color` to [`LegacyColor::WHITE`] (the default)
|
/// You should set `base_color` to [`Color::WHITE`] (the default)
|
||||||
/// if you want the texture to show as-is.
|
/// if you want the texture to show as-is.
|
||||||
///
|
///
|
||||||
/// Setting `base_color` to something else than white will tint
|
/// Setting `base_color` to something else than white will tint
|
||||||
|
@ -54,17 +55,17 @@ pub struct StandardMaterial {
|
||||||
/// This means that for a light emissive value, in darkness,
|
/// This means that for a light emissive value, in darkness,
|
||||||
/// you will mostly see the emissive component.
|
/// you will mostly see the emissive component.
|
||||||
///
|
///
|
||||||
/// The default emissive color is black, which doesn't add anything to the material color.
|
/// The default emissive color is [`Color::BLACK`], which doesn't add anything to the material color.
|
||||||
///
|
///
|
||||||
/// Note that **an emissive material won't light up surrounding areas like a light source**,
|
/// Note that **an emissive material won't light up surrounding areas like a light source**,
|
||||||
/// it just adds a value to the color seen on screen.
|
/// it just adds a value to the color seen on screen.
|
||||||
pub emissive: LegacyColor,
|
pub emissive: Color,
|
||||||
|
|
||||||
/// The emissive map, multiplies pixels with [`emissive`]
|
/// The emissive map, multiplies pixels with [`emissive`]
|
||||||
/// to get the final "emitting" color of a surface.
|
/// to get the final "emitting" color of a surface.
|
||||||
///
|
///
|
||||||
/// This color is multiplied by [`emissive`] to get the final emitted color.
|
/// This color is multiplied by [`emissive`] to get the final emitted color.
|
||||||
/// Meaning that you should set [`emissive`] to [`LegacyColor::WHITE`]
|
/// Meaning that you should set [`emissive`] to [`Color::WHITE`]
|
||||||
/// if you want to use the full range of color of the emissive texture.
|
/// if you want to use the full range of color of the emissive texture.
|
||||||
///
|
///
|
||||||
/// [`emissive`]: StandardMaterial::emissive
|
/// [`emissive`]: StandardMaterial::emissive
|
||||||
|
@ -271,7 +272,7 @@ pub struct StandardMaterial {
|
||||||
|
|
||||||
/// The resulting (non-absorbed) color after white light travels through the attenuation distance.
|
/// The resulting (non-absorbed) color after white light travels through the attenuation distance.
|
||||||
///
|
///
|
||||||
/// Defaults to [`LegacyColor::WHITE`], i.e. no change.
|
/// Defaults to [`Color::WHITE`], i.e. no change.
|
||||||
///
|
///
|
||||||
/// **Note:** To have any effect, must be used in conjunction with:
|
/// **Note:** To have any effect, must be used in conjunction with:
|
||||||
/// - [`StandardMaterial::attenuation_distance`];
|
/// - [`StandardMaterial::attenuation_distance`];
|
||||||
|
@ -279,7 +280,7 @@ pub struct StandardMaterial {
|
||||||
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::specular_transmission`].
|
/// - [`StandardMaterial::diffuse_transmission`] or [`StandardMaterial::specular_transmission`].
|
||||||
#[doc(alias = "absorption_color")]
|
#[doc(alias = "absorption_color")]
|
||||||
#[doc(alias = "extinction_color")]
|
#[doc(alias = "extinction_color")]
|
||||||
pub attenuation_color: LegacyColor,
|
pub attenuation_color: Color,
|
||||||
|
|
||||||
/// Used to fake the lighting of bumps and dents on a material.
|
/// Used to fake the lighting of bumps and dents on a material.
|
||||||
///
|
///
|
||||||
|
@ -479,9 +480,9 @@ impl Default for StandardMaterial {
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
// White because it gets multiplied with texture values if someone uses
|
// White because it gets multiplied with texture values if someone uses
|
||||||
// a texture.
|
// a texture.
|
||||||
base_color: LegacyColor::rgb(1.0, 1.0, 1.0),
|
base_color: Color::WHITE,
|
||||||
base_color_texture: None,
|
base_color_texture: None,
|
||||||
emissive: LegacyColor::BLACK,
|
emissive: Color::BLACK,
|
||||||
emissive_texture: None,
|
emissive_texture: None,
|
||||||
// Matches Blender's default roughness.
|
// Matches Blender's default roughness.
|
||||||
perceptual_roughness: 0.5,
|
perceptual_roughness: 0.5,
|
||||||
|
@ -502,7 +503,7 @@ impl Default for StandardMaterial {
|
||||||
#[cfg(feature = "pbr_transmission_textures")]
|
#[cfg(feature = "pbr_transmission_textures")]
|
||||||
thickness_texture: None,
|
thickness_texture: None,
|
||||||
ior: 1.5,
|
ior: 1.5,
|
||||||
attenuation_color: LegacyColor::WHITE,
|
attenuation_color: Color::WHITE,
|
||||||
attenuation_distance: f32::INFINITY,
|
attenuation_distance: f32::INFINITY,
|
||||||
occlusion_texture: None,
|
occlusion_texture: None,
|
||||||
normal_map_texture: None,
|
normal_map_texture: None,
|
||||||
|
@ -525,11 +526,11 @@ impl Default for StandardMaterial {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LegacyColor> for StandardMaterial {
|
impl From<Color> for StandardMaterial {
|
||||||
fn from(color: LegacyColor) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
StandardMaterial {
|
StandardMaterial {
|
||||||
base_color: color,
|
base_color: color,
|
||||||
alpha_mode: if color.a() < 1.0 {
|
alpha_mode: if color.alpha() < 1.0 {
|
||||||
AlphaMode::Blend
|
AlphaMode::Blend
|
||||||
} else {
|
} else {
|
||||||
AlphaMode::Opaque
|
AlphaMode::Opaque
|
||||||
|
@ -714,8 +715,8 @@ impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial {
|
||||||
}
|
}
|
||||||
|
|
||||||
StandardMaterialUniform {
|
StandardMaterialUniform {
|
||||||
base_color: self.base_color.as_linear_rgba_f32().into(),
|
base_color: LinearRgba::from(self.base_color).to_f32_array().into(),
|
||||||
emissive: self.emissive.as_linear_rgba_f32().into(),
|
emissive: LinearRgba::from(self.base_color).to_f32_array().into(),
|
||||||
roughness: self.perceptual_roughness,
|
roughness: self.perceptual_roughness,
|
||||||
metallic: self.metallic,
|
metallic: self.metallic,
|
||||||
reflectance: self.reflectance,
|
reflectance: self.reflectance,
|
||||||
|
@ -724,7 +725,7 @@ impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial {
|
||||||
thickness: self.thickness,
|
thickness: self.thickness,
|
||||||
ior: self.ior,
|
ior: self.ior,
|
||||||
attenuation_distance: self.attenuation_distance,
|
attenuation_distance: self.attenuation_distance,
|
||||||
attenuation_color: self.attenuation_color.as_linear_rgba_f32().into(),
|
attenuation_color: LinearRgba::from(self.base_color).to_f32_array().into(),
|
||||||
flags: flags.bits(),
|
flags: flags.bits(),
|
||||||
alpha_cutoff,
|
alpha_cutoff,
|
||||||
parallax_depth_scale: self.parallax_depth_scale,
|
parallax_depth_scale: self.parallax_depth_scale,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use bevy_app::{App, Plugin};
|
use bevy_app::{App, Plugin};
|
||||||
use bevy_asset::{load_internal_asset, Handle};
|
use bevy_asset::{load_internal_asset, Handle};
|
||||||
|
use bevy_color::LinearRgba;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_math::{Vec3, Vec4};
|
use bevy_math::{Vec3, Vec4};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
|
@ -65,33 +66,24 @@ pub fn prepare_fog(
|
||||||
match &fog.falloff {
|
match &fog.falloff {
|
||||||
FogFalloff::Linear { start, end } => GpuFog {
|
FogFalloff::Linear { start, end } => GpuFog {
|
||||||
mode: GPU_FOG_MODE_LINEAR,
|
mode: GPU_FOG_MODE_LINEAR,
|
||||||
base_color: fog.color.as_linear_rgba_f32().into(),
|
base_color: LinearRgba::from(fog.color).into(),
|
||||||
directional_light_color: fog
|
directional_light_color: LinearRgba::from(fog.directional_light_color).into(),
|
||||||
.directional_light_color
|
|
||||||
.as_linear_rgba_f32()
|
|
||||||
.into(),
|
|
||||||
directional_light_exponent: fog.directional_light_exponent,
|
directional_light_exponent: fog.directional_light_exponent,
|
||||||
be: Vec3::new(*start, *end, 0.0),
|
be: Vec3::new(*start, *end, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
FogFalloff::Exponential { density } => GpuFog {
|
FogFalloff::Exponential { density } => GpuFog {
|
||||||
mode: GPU_FOG_MODE_EXPONENTIAL,
|
mode: GPU_FOG_MODE_EXPONENTIAL,
|
||||||
base_color: fog.color.as_linear_rgba_f32().into(),
|
base_color: LinearRgba::from(fog.color).into(),
|
||||||
directional_light_color: fog
|
directional_light_color: LinearRgba::from(fog.directional_light_color).into(),
|
||||||
.directional_light_color
|
|
||||||
.as_linear_rgba_f32()
|
|
||||||
.into(),
|
|
||||||
directional_light_exponent: fog.directional_light_exponent,
|
directional_light_exponent: fog.directional_light_exponent,
|
||||||
be: Vec3::new(*density, 0.0, 0.0),
|
be: Vec3::new(*density, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
FogFalloff::ExponentialSquared { density } => GpuFog {
|
FogFalloff::ExponentialSquared { density } => GpuFog {
|
||||||
mode: GPU_FOG_MODE_EXPONENTIAL_SQUARED,
|
mode: GPU_FOG_MODE_EXPONENTIAL_SQUARED,
|
||||||
base_color: fog.color.as_linear_rgba_f32().into(),
|
base_color: LinearRgba::from(fog.color).into(),
|
||||||
directional_light_color: fog
|
directional_light_color: LinearRgba::from(fog.directional_light_color).into(),
|
||||||
.directional_light_color
|
|
||||||
.as_linear_rgba_f32()
|
|
||||||
.into(),
|
|
||||||
directional_light_exponent: fog.directional_light_exponent,
|
directional_light_exponent: fog.directional_light_exponent,
|
||||||
be: Vec3::new(*density, 0.0, 0.0),
|
be: Vec3::new(*density, 0.0, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -101,11 +93,8 @@ pub fn prepare_fog(
|
||||||
inscattering,
|
inscattering,
|
||||||
} => GpuFog {
|
} => GpuFog {
|
||||||
mode: GPU_FOG_MODE_ATMOSPHERIC,
|
mode: GPU_FOG_MODE_ATMOSPHERIC,
|
||||||
base_color: fog.color.as_linear_rgba_f32().into(),
|
base_color: LinearRgba::from(fog.color).into(),
|
||||||
directional_light_color: fog
|
directional_light_color: LinearRgba::from(fog.directional_light_color).into(),
|
||||||
.directional_light_color
|
|
||||||
.as_linear_rgba_f32()
|
|
||||||
.into(),
|
|
||||||
directional_light_exponent: fog.directional_light_exponent,
|
directional_light_exponent: fog.directional_light_exponent,
|
||||||
be: *extinction,
|
be: *extinction,
|
||||||
bi: *inscattering,
|
bi: *inscattering,
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::*;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct ExtractedPointLight {
|
pub struct ExtractedPointLight {
|
||||||
pub color: LegacyColor,
|
pub color: LinearRgba,
|
||||||
/// luminous intensity in lumens per steradian
|
/// luminous intensity in lumens per steradian
|
||||||
pub intensity: f32,
|
pub intensity: f32,
|
||||||
pub range: f32,
|
pub range: f32,
|
||||||
|
@ -42,7 +42,7 @@ pub struct ExtractedPointLight {
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct ExtractedDirectionalLight {
|
pub struct ExtractedDirectionalLight {
|
||||||
pub color: LegacyColor,
|
pub color: LinearRgba,
|
||||||
pub illuminance: f32,
|
pub illuminance: f32,
|
||||||
pub transform: GlobalTransform,
|
pub transform: GlobalTransform,
|
||||||
pub shadows_enabled: bool,
|
pub shadows_enabled: bool,
|
||||||
|
@ -384,7 +384,7 @@ pub fn extract_lights(
|
||||||
// However, since exclusive access to the main world in extract is ill-advised, we just clone here.
|
// However, since exclusive access to the main world in extract is ill-advised, we just clone here.
|
||||||
let render_cubemap_visible_entities = cubemap_visible_entities.clone();
|
let render_cubemap_visible_entities = cubemap_visible_entities.clone();
|
||||||
let extracted_point_light = ExtractedPointLight {
|
let extracted_point_light = ExtractedPointLight {
|
||||||
color: point_light.color,
|
color: point_light.color.into(),
|
||||||
// NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
|
// NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
|
||||||
// for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
|
// for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
|
||||||
// for details.
|
// for details.
|
||||||
|
@ -430,7 +430,7 @@ pub fn extract_lights(
|
||||||
entity,
|
entity,
|
||||||
(
|
(
|
||||||
ExtractedPointLight {
|
ExtractedPointLight {
|
||||||
color: spot_light.color,
|
color: spot_light.color.into(),
|
||||||
// NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
|
// NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
|
||||||
// for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
|
// for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
|
||||||
// for details.
|
// for details.
|
||||||
|
@ -478,7 +478,7 @@ pub fn extract_lights(
|
||||||
let render_visible_entities = visible_entities.clone();
|
let render_visible_entities = visible_entities.clone();
|
||||||
commands.get_or_spawn(entity).insert((
|
commands.get_or_spawn(entity).insert((
|
||||||
ExtractedDirectionalLight {
|
ExtractedDirectionalLight {
|
||||||
color: directional_light.color,
|
color: directional_light.color.into(),
|
||||||
illuminance: directional_light.illuminance,
|
illuminance: directional_light.illuminance,
|
||||||
transform: *transform,
|
transform: *transform,
|
||||||
shadows_enabled: directional_light.shadows_enabled,
|
shadows_enabled: directional_light.shadows_enabled,
|
||||||
|
@ -871,7 +871,7 @@ pub fn prepare_lights(
|
||||||
light_custom_data,
|
light_custom_data,
|
||||||
// premultiply color by intensity
|
// premultiply color by intensity
|
||||||
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
||||||
color_inverse_square_range: (Vec4::from_slice(&light.color.as_linear_rgba_f32())
|
color_inverse_square_range: (Vec4::from_slice(&light.color.to_f32_array())
|
||||||
* light.intensity)
|
* light.intensity)
|
||||||
.xyz()
|
.xyz()
|
||||||
.extend(1.0 / (light.range * light.range)),
|
.extend(1.0 / (light.range * light.range)),
|
||||||
|
@ -908,7 +908,7 @@ pub fn prepare_lights(
|
||||||
cascades: [GpuDirectionalCascade::default(); MAX_CASCADES_PER_LIGHT],
|
cascades: [GpuDirectionalCascade::default(); MAX_CASCADES_PER_LIGHT],
|
||||||
// premultiply color by illuminance
|
// premultiply color by illuminance
|
||||||
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
// we don't use the alpha at all, so no reason to multiply only [0..3]
|
||||||
color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * light.illuminance,
|
color: Vec4::from_slice(&light.color.to_f32_array()) * light.illuminance,
|
||||||
// direction is negated to be ready for N.L
|
// direction is negated to be ready for N.L
|
||||||
dir_to_light: light.transform.back(),
|
dir_to_light: light.transform.back(),
|
||||||
flags: flags.bits(),
|
flags: flags.bits(),
|
||||||
|
@ -982,7 +982,7 @@ pub fn prepare_lights(
|
||||||
let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z;
|
let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z;
|
||||||
let mut gpu_lights = GpuLights {
|
let mut gpu_lights = GpuLights {
|
||||||
directional_lights: gpu_directional_lights,
|
directional_lights: gpu_directional_lights,
|
||||||
ambient_color: Vec4::from_slice(&ambient_light.color.as_linear_rgba_f32())
|
ambient_color: Vec4::from_slice(&LinearRgba::from(ambient_light.color).to_f32_array())
|
||||||
* ambient_light.brightness,
|
* ambient_light.brightness,
|
||||||
cluster_factors: Vec4::new(
|
cluster_factors: Vec4::new(
|
||||||
clusters.dimensions.x as f32 / extracted_view.viewport.z as f32,
|
clusters.dimensions.x as f32 / extracted_view.viewport.z as f32,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{Material, MaterialPipeline, MaterialPipelineKey, MaterialPlugin};
|
use crate::{Material, MaterialPipeline, MaterialPipelineKey, MaterialPlugin};
|
||||||
use bevy_app::{Plugin, Startup, Update};
|
use bevy_app::{Plugin, Startup, Update};
|
||||||
use bevy_asset::{load_internal_asset, Asset, Assets, Handle};
|
use bevy_asset::{load_internal_asset, Asset, Assets, Handle};
|
||||||
|
use bevy_color::{Color, LinearRgba};
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
|
@ -65,7 +66,7 @@ pub struct Wireframe;
|
||||||
#[derive(Component, Debug, Clone, Default, Reflect)]
|
#[derive(Component, Debug, Clone, Default, Reflect)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
pub struct WireframeColor {
|
pub struct WireframeColor {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disables wireframe rendering for any entity it is attached to.
|
/// Disables wireframe rendering for any entity it is attached to.
|
||||||
|
@ -85,7 +86,7 @@ pub struct WireframeConfig {
|
||||||
/// If [`Self::global`] is set, any [`Entity`] that does not have a [`Wireframe`] component attached to it will have
|
/// If [`Self::global`] is set, any [`Entity`] that does not have a [`Wireframe`] component attached to it will have
|
||||||
/// wireframes using this color. Otherwise, this will be the fallback color for any entity that has a [`Wireframe`],
|
/// wireframes using this color. Otherwise, this will be the fallback color for any entity that has a [`Wireframe`],
|
||||||
/// but no [`WireframeColor`].
|
/// but no [`WireframeColor`].
|
||||||
pub default_color: LegacyColor,
|
pub default_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
|
@ -102,7 +103,7 @@ fn setup_global_wireframe_material(
|
||||||
// Create the handle used for the global material
|
// Create the handle used for the global material
|
||||||
commands.insert_resource(GlobalWireframeMaterial {
|
commands.insert_resource(GlobalWireframeMaterial {
|
||||||
handle: materials.add(WireframeMaterial {
|
handle: materials.add(WireframeMaterial {
|
||||||
color: config.default_color,
|
color: config.default_color.into(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -114,7 +115,7 @@ fn global_color_changed(
|
||||||
global_material: Res<GlobalWireframeMaterial>,
|
global_material: Res<GlobalWireframeMaterial>,
|
||||||
) {
|
) {
|
||||||
if let Some(global_material) = materials.get_mut(&global_material.handle) {
|
if let Some(global_material) = materials.get_mut(&global_material.handle) {
|
||||||
global_material.color = config.default_color;
|
global_material.color = config.default_color.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ fn wireframe_color_changed(
|
||||||
) {
|
) {
|
||||||
for (mut handle, wireframe_color) in &mut colors_changed {
|
for (mut handle, wireframe_color) in &mut colors_changed {
|
||||||
*handle = materials.add(WireframeMaterial {
|
*handle = materials.add(WireframeMaterial {
|
||||||
color: wireframe_color.color,
|
color: wireframe_color.color.into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +158,7 @@ fn apply_wireframe_material(
|
||||||
for (e, wireframe_color) in &wireframes {
|
for (e, wireframe_color) in &wireframes {
|
||||||
let material = if let Some(wireframe_color) = wireframe_color {
|
let material = if let Some(wireframe_color) = wireframe_color {
|
||||||
materials.add(WireframeMaterial {
|
materials.add(WireframeMaterial {
|
||||||
color: wireframe_color.color,
|
color: wireframe_color.color.into(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// If there's no color specified we can use the global material since it's already set to use the default_color
|
// If there's no color specified we can use the global material since it's already set to use the default_color
|
||||||
|
@ -196,7 +197,7 @@ fn apply_global_wireframe_material(
|
||||||
#[derive(Default, AsBindGroup, TypePath, Debug, Clone, Asset)]
|
#[derive(Default, AsBindGroup, TypePath, Debug, Clone, Asset)]
|
||||||
pub struct WireframeMaterial {
|
pub struct WireframeMaterial {
|
||||||
#[uniform(0)]
|
#[uniform(0)]
|
||||||
pub color: LegacyColor,
|
pub color: LinearRgba,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material for WireframeMaterial {
|
impl Material for WireframeMaterial {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{color::LegacyColor, extract_resource::ExtractResource};
|
use crate::extract_resource::ExtractResource;
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_derive::{Deref, DerefMut};
|
use bevy_derive::{Deref, DerefMut};
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
||||||
|
@ -12,15 +13,15 @@ pub enum ClearColorConfig {
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
/// The given clear color is used, overriding the [`ClearColor`] resource defined in the world.
|
/// The given clear color is used, overriding the [`ClearColor`] resource defined in the world.
|
||||||
Custom(LegacyColor),
|
Custom(Color),
|
||||||
/// No clear color is used: the camera will simply draw on top of anything already in the viewport.
|
/// No clear color is used: the camera will simply draw on top of anything already in the viewport.
|
||||||
///
|
///
|
||||||
/// This can be useful when multiple cameras are rendering to the same viewport.
|
/// This can be useful when multiple cameras are rendering to the same viewport.
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LegacyColor> for ClearColorConfig {
|
impl From<Color> for ClearColorConfig {
|
||||||
fn from(color: LegacyColor) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
Self::Custom(color)
|
Self::Custom(color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +32,11 @@ impl From<LegacyColor> for ClearColorConfig {
|
||||||
/// when there are portions of the screen with nothing rendered.
|
/// when there are portions of the screen with nothing rendered.
|
||||||
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)]
|
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct ClearColor(pub LegacyColor);
|
pub struct ClearColor(pub Color);
|
||||||
|
|
||||||
/// Match the dark gray bevy website code block color by default.
|
/// Match the dark gray bevy website code block color by default.
|
||||||
impl Default for ClearColor {
|
impl Default for ClearColor {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(LegacyColor::rgb_u8(43, 44, 47))
|
Self(Color::srgb_u8(43, 44, 47))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,6 @@ extern crate core;
|
||||||
pub mod alpha;
|
pub mod alpha;
|
||||||
pub mod batching;
|
pub mod batching;
|
||||||
pub mod camera;
|
pub mod camera;
|
||||||
pub mod color;
|
|
||||||
pub mod deterministic;
|
pub mod deterministic;
|
||||||
pub mod extract_component;
|
pub mod extract_component;
|
||||||
pub mod extract_instances;
|
pub mod extract_instances;
|
||||||
|
@ -38,7 +37,6 @@ pub mod prelude {
|
||||||
Camera, ClearColor, ClearColorConfig, OrthographicProjection, PerspectiveProjection,
|
Camera, ClearColor, ClearColorConfig, OrthographicProjection, PerspectiveProjection,
|
||||||
Projection,
|
Projection,
|
||||||
},
|
},
|
||||||
color::LegacyColor,
|
|
||||||
mesh::{morph::MorphWeights, primitives::Meshable, Mesh},
|
mesh::{morph::MorphWeights, primitives::Meshable, Mesh},
|
||||||
render_resource::Shader,
|
render_resource::Shader,
|
||||||
spatial_bundle::SpatialBundle,
|
spatial_bundle::SpatialBundle,
|
||||||
|
@ -330,7 +328,18 @@ impl Plugin for RenderPlugin {
|
||||||
));
|
));
|
||||||
|
|
||||||
app.register_type::<alpha::AlphaMode>()
|
app.register_type::<alpha::AlphaMode>()
|
||||||
.register_type::<color::LegacyColor>()
|
// These types cannot be registered in bevy_color, as it does not depend on the rest of Bevy
|
||||||
|
// BLOCKED: once https://github.com/bevyengine/bevy/pull/5781 lands, we can remove all but the Color registration
|
||||||
|
.register_type::<bevy_color::Color>()
|
||||||
|
.register_type::<bevy_color::Srgba>()
|
||||||
|
.register_type::<bevy_color::LinearRgba>()
|
||||||
|
.register_type::<bevy_color::Hsla>()
|
||||||
|
.register_type::<bevy_color::Hsva>()
|
||||||
|
.register_type::<bevy_color::Hwba>()
|
||||||
|
.register_type::<bevy_color::Laba>()
|
||||||
|
.register_type::<bevy_color::Lcha>()
|
||||||
|
.register_type::<bevy_color::Xyza>()
|
||||||
|
.register_type::<bevy_color::Oklaba>()
|
||||||
.register_type::<primitives::Aabb>()
|
.register_type::<primitives::Aabb>()
|
||||||
.register_type::<primitives::CascadesFrusta>()
|
.register_type::<primitives::CascadesFrusta>()
|
||||||
.register_type::<primitives::CubemapFrusta>()
|
.register_type::<primitives::CubemapFrusta>()
|
||||||
|
|
|
@ -74,12 +74,13 @@ impl Deref for BindGroup {
|
||||||
/// what their binding type is, and what index they should be bound at:
|
/// what their binding type is, and what index they should be bound at:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::*, texture::Image};
|
/// # use bevy_render::{render_resource::*, texture::Image};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// # use bevy_asset::Handle;
|
/// # use bevy_asset::Handle;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// #[texture(1)]
|
/// #[texture(1)]
|
||||||
/// #[sampler(2)]
|
/// #[sampler(2)]
|
||||||
/// color_texture: Handle<Image>,
|
/// color_texture: Handle<Image>,
|
||||||
|
@ -109,7 +110,7 @@ impl Deref for BindGroup {
|
||||||
/// * `uniform(BINDING_INDEX)`
|
/// * `uniform(BINDING_INDEX)`
|
||||||
/// * The field will be converted to a shader-compatible type using the [`ShaderType`] trait, written to a [`Buffer`], and bound as a uniform.
|
/// * The field will be converted to a shader-compatible type using the [`ShaderType`] trait, written to a [`Buffer`], and bound as a uniform.
|
||||||
/// [`ShaderType`] is implemented for most math types already, such as [`f32`], [`Vec4`](bevy_math::Vec4), and
|
/// [`ShaderType`] is implemented for most math types already, such as [`f32`], [`Vec4`](bevy_math::Vec4), and
|
||||||
/// [`LegacyColor`](crate::color::LegacyColor). It can also be derived for custom structs.
|
/// [`LinearRgba`](bevy_color::LinearRgba). It can also be derived for custom structs.
|
||||||
///
|
///
|
||||||
/// * `texture(BINDING_INDEX, arguments)`
|
/// * `texture(BINDING_INDEX, arguments)`
|
||||||
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture)
|
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture)
|
||||||
|
@ -162,24 +163,26 @@ impl Deref for BindGroup {
|
||||||
///
|
///
|
||||||
/// Note that fields without field-level binding attributes will be ignored.
|
/// Note that fields without field-level binding attributes will be ignored.
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::AsBindGroup};
|
/// # use bevy_render::{render_resource::AsBindGroup};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// # use bevy_asset::Handle;
|
/// # use bevy_asset::Handle;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// this_field_is_ignored: String,
|
/// this_field_is_ignored: String,
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// As mentioned above, [`Option<Handle<Image>>`] is also supported:
|
/// As mentioned above, [`Option<Handle<Image>>`] is also supported:
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::AsBindGroup, texture::Image};
|
/// # use bevy_render::{render_resource::AsBindGroup, texture::Image};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// # use bevy_asset::Handle;
|
/// # use bevy_asset::Handle;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// #[texture(1)]
|
/// #[texture(1)]
|
||||||
/// #[sampler(2)]
|
/// #[sampler(2)]
|
||||||
/// color_texture: Option<Handle<Image>>,
|
/// color_texture: Option<Handle<Image>>,
|
||||||
|
@ -190,11 +193,12 @@ impl Deref for BindGroup {
|
||||||
///
|
///
|
||||||
/// Field uniforms with the same index will be combined into a single binding:
|
/// Field uniforms with the same index will be combined into a single binding:
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::AsBindGroup};
|
/// # use bevy_render::{render_resource::AsBindGroup};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// roughness: f32,
|
/// roughness: f32,
|
||||||
/// }
|
/// }
|
||||||
|
@ -227,17 +231,18 @@ impl Deref for BindGroup {
|
||||||
/// The previous `CoolMaterial` example illustrating "combining multiple field-level uniform attributes with the same binding index" can
|
/// The previous `CoolMaterial` example illustrating "combining multiple field-level uniform attributes with the same binding index" can
|
||||||
/// also be equivalently represented with a single struct-level uniform attribute:
|
/// also be equivalently represented with a single struct-level uniform attribute:
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::{AsBindGroup, ShaderType}};
|
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderType}};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// #[uniform(0, CoolMaterialUniform)]
|
/// #[uniform(0, CoolMaterialUniform)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// roughness: f32,
|
/// roughness: f32,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// #[derive(ShaderType)]
|
/// #[derive(ShaderType)]
|
||||||
/// struct CoolMaterialUniform {
|
/// struct CoolMaterialUniform {
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// roughness: f32,
|
/// roughness: f32,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
@ -253,12 +258,13 @@ impl Deref for BindGroup {
|
||||||
///
|
///
|
||||||
/// Setting `bind_group_data` looks like this:
|
/// Setting `bind_group_data` looks like this:
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_render::{color::LegacyColor, render_resource::AsBindGroup};
|
/// # use bevy_render::{render_resource::AsBindGroup};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// #[derive(AsBindGroup)]
|
/// #[derive(AsBindGroup)]
|
||||||
/// #[bind_group_data(CoolMaterialKey)]
|
/// #[bind_group_data(CoolMaterialKey)]
|
||||||
/// struct CoolMaterial {
|
/// struct CoolMaterial {
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// is_shaded: bool,
|
/// is_shaded: bool,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
|
|
@ -16,6 +16,7 @@ webgpu = []
|
||||||
# bevy
|
# bevy
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
|
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||||
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
bevy_log = { path = "../bevy_log", version = "0.14.0-dev" }
|
bevy_log = { path = "../bevy_log", version = "0.14.0-dev" }
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::{Material2d, Material2dPlugin, MaterialMesh2dBundle};
|
use crate::{Material2d, Material2dPlugin, MaterialMesh2dBundle};
|
||||||
use bevy_app::{App, Plugin};
|
use bevy_app::{App, Plugin};
|
||||||
use bevy_asset::{load_internal_asset, Asset, AssetApp, Assets, Handle};
|
use bevy_asset::{load_internal_asset, Asset, AssetApp, Assets, Handle};
|
||||||
|
use bevy_color::{Color, LinearRgba};
|
||||||
use bevy_math::Vec4;
|
use bevy_math::Vec4;
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_render::{
|
use bevy_render::{render_asset::RenderAssets, render_resource::*, texture::Image};
|
||||||
color::LegacyColor, render_asset::RenderAssets, render_resource::*, texture::Image,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const COLOR_MATERIAL_SHADER_HANDLE: Handle<Shader> =
|
pub const COLOR_MATERIAL_SHADER_HANDLE: Handle<Shader> =
|
||||||
Handle::weak_from_u128(3253086872234592509);
|
Handle::weak_from_u128(3253086872234592509);
|
||||||
|
@ -28,7 +27,7 @@ impl Plugin for ColorMaterialPlugin {
|
||||||
app.world.resource_mut::<Assets<ColorMaterial>>().insert(
|
app.world.resource_mut::<Assets<ColorMaterial>>().insert(
|
||||||
Handle::<ColorMaterial>::default(),
|
Handle::<ColorMaterial>::default(),
|
||||||
ColorMaterial {
|
ColorMaterial {
|
||||||
color: LegacyColor::rgb(1.0, 0.0, 1.0),
|
color: Color::srgb(1.0, 0.0, 1.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -40,7 +39,7 @@ impl Plugin for ColorMaterialPlugin {
|
||||||
#[reflect(Default, Debug)]
|
#[reflect(Default, Debug)]
|
||||||
#[uniform(0, ColorMaterialUniform)]
|
#[uniform(0, ColorMaterialUniform)]
|
||||||
pub struct ColorMaterial {
|
pub struct ColorMaterial {
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
#[texture(1)]
|
#[texture(1)]
|
||||||
#[sampler(2)]
|
#[sampler(2)]
|
||||||
pub texture: Option<Handle<Image>>,
|
pub texture: Option<Handle<Image>>,
|
||||||
|
@ -49,14 +48,14 @@ pub struct ColorMaterial {
|
||||||
impl Default for ColorMaterial {
|
impl Default for ColorMaterial {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ColorMaterial {
|
ColorMaterial {
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
texture: None,
|
texture: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LegacyColor> for ColorMaterial {
|
impl From<Color> for ColorMaterial {
|
||||||
fn from(color: LegacyColor) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
ColorMaterial {
|
ColorMaterial {
|
||||||
color,
|
color,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -98,7 +97,7 @@ impl AsBindGroupShaderType<ColorMaterialUniform> for ColorMaterial {
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorMaterialUniform {
|
ColorMaterialUniform {
|
||||||
color: self.color.as_linear_rgba_f32().into(),
|
color: LinearRgba::from(self.color).to_f32_array().into(),
|
||||||
flags: flags.bits(),
|
flags: flags.bits(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,8 @@ use crate::{
|
||||||
/// # use bevy_sprite::{Material2d, MaterialMesh2dBundle};
|
/// # use bevy_sprite::{Material2d, MaterialMesh2dBundle};
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_reflect::TypePath;
|
/// # use bevy_reflect::TypePath;
|
||||||
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image, color::LegacyColor};
|
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
||||||
///
|
///
|
||||||
/// #[derive(AsBindGroup, Debug, Clone, Asset, TypePath)]
|
/// #[derive(AsBindGroup, Debug, Clone, Asset, TypePath)]
|
||||||
|
@ -62,7 +63,7 @@ use crate::{
|
||||||
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
||||||
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
||||||
/// // add the sampler attribute with a different binding index.
|
/// // add the sampler attribute with a different binding index.
|
||||||
/// #[texture(1)]
|
/// #[texture(1)]
|
||||||
|
@ -82,7 +83,7 @@ use crate::{
|
||||||
/// fn setup(mut commands: Commands, mut materials: ResMut<Assets<CustomMaterial>>, asset_server: Res<AssetServer>) {
|
/// fn setup(mut commands: Commands, mut materials: ResMut<Assets<CustomMaterial>>, asset_server: Res<AssetServer>) {
|
||||||
/// commands.spawn(MaterialMesh2dBundle {
|
/// commands.spawn(MaterialMesh2dBundle {
|
||||||
/// material: materials.add(CustomMaterial {
|
/// material: materials.add(CustomMaterial {
|
||||||
/// color: LegacyColor::RED,
|
/// color: LinearRgba::RED,
|
||||||
/// color_texture: asset_server.load("some_image.png"),
|
/// color_texture: asset_server.load("some_image.png"),
|
||||||
/// }),
|
/// }),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::{
|
||||||
ComputedTextureSlices, Sprite, SPRITE_SHADER_HANDLE,
|
ComputedTextureSlices, Sprite, SPRITE_SHADER_HANDLE,
|
||||||
};
|
};
|
||||||
use bevy_asset::{AssetEvent, AssetId, Assets, Handle};
|
use bevy_asset::{AssetEvent, AssetId, Assets, Handle};
|
||||||
|
use bevy_color::LinearRgba;
|
||||||
use bevy_core_pipeline::{
|
use bevy_core_pipeline::{
|
||||||
core_2d::Transparent2d,
|
core_2d::Transparent2d,
|
||||||
tonemapping::{DebandDither, Tonemapping},
|
tonemapping::{DebandDither, Tonemapping},
|
||||||
|
@ -16,7 +17,6 @@ use bevy_ecs::{
|
||||||
};
|
};
|
||||||
use bevy_math::{Affine3A, Quat, Rect, Vec2, Vec4};
|
use bevy_math::{Affine3A, Quat, Rect, Vec2, Vec4};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
color::LegacyColor,
|
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
render_phase::{
|
render_phase::{
|
||||||
DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline,
|
DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline,
|
||||||
|
@ -295,7 +295,7 @@ impl SpecializedRenderPipeline for SpritePipeline {
|
||||||
|
|
||||||
pub struct ExtractedSprite {
|
pub struct ExtractedSprite {
|
||||||
pub transform: GlobalTransform,
|
pub transform: GlobalTransform,
|
||||||
pub color: LegacyColor,
|
pub color: LinearRgba,
|
||||||
/// Select an area of the texture
|
/// Select an area of the texture
|
||||||
pub rect: Option<Rect>,
|
pub rect: Option<Rect>,
|
||||||
/// Change the on-screen size of the sprite
|
/// Change the on-screen size of the sprite
|
||||||
|
@ -379,7 +379,7 @@ pub fn extract_sprites(
|
||||||
extracted_sprites.sprites.insert(
|
extracted_sprites.sprites.insert(
|
||||||
entity,
|
entity,
|
||||||
ExtractedSprite {
|
ExtractedSprite {
|
||||||
color: sprite.color,
|
color: sprite.color.into(),
|
||||||
transform: *transform,
|
transform: *transform,
|
||||||
rect,
|
rect,
|
||||||
// Pass the custom size
|
// Pass the custom size
|
||||||
|
@ -406,7 +406,7 @@ struct SpriteInstance {
|
||||||
|
|
||||||
impl SpriteInstance {
|
impl SpriteInstance {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(transform: &Affine3A, color: &LegacyColor, uv_offset_scale: &Vec4) -> Self {
|
fn from(transform: &Affine3A, color: &LinearRgba, uv_offset_scale: &Vec4) -> Self {
|
||||||
let transpose_model_3x3 = transform.matrix3.transpose();
|
let transpose_model_3x3 = transform.matrix3.transpose();
|
||||||
Self {
|
Self {
|
||||||
i_model_transpose: [
|
i_model_transpose: [
|
||||||
|
@ -414,7 +414,7 @@ impl SpriteInstance {
|
||||||
transpose_model_3x3.y_axis.extend(transform.translation.y),
|
transpose_model_3x3.y_axis.extend(transform.translation.y),
|
||||||
transpose_model_3x3.z_axis.extend(transform.translation.z),
|
transpose_model_3x3.z_axis.extend(transform.translation.z),
|
||||||
],
|
],
|
||||||
i_color: color.as_linear_rgba_f32(),
|
i_color: color.to_f32_array(),
|
||||||
i_uv_offset_scale: uv_offset_scale.to_array(),
|
i_uv_offset_scale: uv_offset_scale.to_array(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ pub fn queue_sprites(
|
||||||
let sort_key = FloatOrd(extracted_sprite.transform.translation().z);
|
let sort_key = FloatOrd(extracted_sprite.transform.translation().z);
|
||||||
|
|
||||||
// Add the item to the render phase
|
// Add the item to the render phase
|
||||||
if extracted_sprite.color != LegacyColor::WHITE {
|
if extracted_sprite.color != LinearRgba::WHITE {
|
||||||
transparent_phase.add(Transparent2d {
|
transparent_phase.add(Transparent2d {
|
||||||
draw_function: draw_sprite_function,
|
draw_function: draw_sprite_function,
|
||||||
pipeline: colored_pipeline,
|
pipeline: colored_pipeline,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_ecs::{component::Component, reflect::ReflectComponent};
|
use bevy_ecs::{component::Component, reflect::ReflectComponent};
|
||||||
use bevy_math::{Rect, Vec2};
|
use bevy_math::{Rect, Vec2};
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
|
|
||||||
use crate::TextureSlicer;
|
use crate::TextureSlicer;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use crate::TextureSlicer;
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Sprite {
|
pub struct Sprite {
|
||||||
/// The sprite's color tint
|
/// The sprite's color tint
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
/// Flip the sprite along the `X` axis
|
/// Flip the sprite along the `X` axis
|
||||||
pub flip_x: bool,
|
pub flip_x: bool,
|
||||||
/// Flip the sprite along the `Y` axis
|
/// Flip the sprite along the `Y` axis
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl ComputedTextureSlices {
|
||||||
let transform = transform.mul_transform(Transform::from_translation(offset));
|
let transform = transform.mul_transform(Transform::from_translation(offset));
|
||||||
ExtractedSprite {
|
ExtractedSprite {
|
||||||
original_entity: Some(original_entity),
|
original_entity: Some(original_entity),
|
||||||
color: sprite.color,
|
color: sprite.color.into(),
|
||||||
transform,
|
transform,
|
||||||
rect: Some(slice.texture_rect),
|
rect: Some(slice.texture_rect),
|
||||||
custom_size: Some(slice.draw_size),
|
custom_size: Some(slice.draw_size),
|
||||||
|
|
|
@ -16,6 +16,7 @@ default_font = []
|
||||||
# bevy
|
# bevy
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
|
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
||||||
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
|
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_render::color::LegacyColor;
|
|
||||||
use bevy_utils::default;
|
use bevy_utils::default;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl Text {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_asset::Handle;
|
/// # use bevy_asset::Handle;
|
||||||
/// # use bevy_render::color::LegacyColor;
|
/// # use bevy_color::Color;
|
||||||
/// # use bevy_text::{Font, Text, TextStyle, JustifyText};
|
/// # use bevy_text::{Font, Text, TextStyle, JustifyText};
|
||||||
/// #
|
/// #
|
||||||
/// # let font_handle: Handle<Font> = Default::default();
|
/// # let font_handle: Handle<Font> = Default::default();
|
||||||
|
@ -45,7 +45,7 @@ impl Text {
|
||||||
/// TextStyle {
|
/// TextStyle {
|
||||||
/// font: font_handle.clone(),
|
/// font: font_handle.clone(),
|
||||||
/// font_size: 60.0,
|
/// font_size: 60.0,
|
||||||
/// color: LegacyColor::WHITE,
|
/// color: Color::WHITE,
|
||||||
/// },
|
/// },
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
|
@ -54,7 +54,7 @@ impl Text {
|
||||||
/// TextStyle {
|
/// TextStyle {
|
||||||
/// font: font_handle,
|
/// font: font_handle,
|
||||||
/// font_size: 60.0,
|
/// font_size: 60.0,
|
||||||
/// color: LegacyColor::WHITE,
|
/// color: Color::WHITE,
|
||||||
/// },
|
/// },
|
||||||
/// ) // You can still add text justifaction.
|
/// ) // You can still add text justifaction.
|
||||||
/// .with_justify(JustifyText::Center);
|
/// .with_justify(JustifyText::Center);
|
||||||
|
@ -70,7 +70,8 @@ impl Text {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_asset::Handle;
|
/// # use bevy_asset::Handle;
|
||||||
/// # use bevy_render::color::LegacyColor;
|
/// # use bevy_color::Color;
|
||||||
|
/// # use bevy_color::palettes::basic::{RED, BLUE};
|
||||||
/// # use bevy_text::{Font, Text, TextStyle, TextSection};
|
/// # use bevy_text::{Font, Text, TextStyle, TextSection};
|
||||||
/// #
|
/// #
|
||||||
/// # let font_handle: Handle<Font> = Default::default();
|
/// # let font_handle: Handle<Font> = Default::default();
|
||||||
|
@ -81,7 +82,7 @@ impl Text {
|
||||||
/// TextStyle {
|
/// TextStyle {
|
||||||
/// font: font_handle.clone(),
|
/// font: font_handle.clone(),
|
||||||
/// font_size: 60.0,
|
/// font_size: 60.0,
|
||||||
/// color: LegacyColor::BLUE,
|
/// color: BLUE.into(),
|
||||||
/// },
|
/// },
|
||||||
/// ),
|
/// ),
|
||||||
/// TextSection::new(
|
/// TextSection::new(
|
||||||
|
@ -89,7 +90,7 @@ impl Text {
|
||||||
/// TextStyle {
|
/// TextStyle {
|
||||||
/// font: font_handle,
|
/// font: font_handle,
|
||||||
/// font_size: 60.0,
|
/// font_size: 60.0,
|
||||||
/// color: LegacyColor::RED,
|
/// color: RED.into(),
|
||||||
/// },
|
/// },
|
||||||
/// ),
|
/// ),
|
||||||
/// ]);
|
/// ]);
|
||||||
|
@ -204,7 +205,7 @@ pub struct TextStyle {
|
||||||
/// A new font atlas is generated for every combination of font handle and scaled font size
|
/// A new font atlas is generated for every combination of font handle and scaled font size
|
||||||
/// which can have a strong performance impact.
|
/// which can have a strong performance impact.
|
||||||
pub font_size: f32,
|
pub font_size: f32,
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TextStyle {
|
impl Default for TextStyle {
|
||||||
|
@ -212,7 +213,7 @@ impl Default for TextStyle {
|
||||||
Self {
|
Self {
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
font_size: 12.0,
|
font_size: 12.0,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
TextPipeline, TextSettings, YAxisOrientation,
|
TextPipeline, TextSettings, YAxisOrientation,
|
||||||
};
|
};
|
||||||
use bevy_asset::Assets;
|
use bevy_asset::Assets;
|
||||||
|
use bevy_color::LinearRgba;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
bundle::Bundle,
|
bundle::Bundle,
|
||||||
change_detection::{DetectChanges, Ref},
|
change_detection::{DetectChanges, Ref},
|
||||||
|
@ -17,7 +18,6 @@ use bevy_ecs::{
|
||||||
use bevy_math::Vec2;
|
use bevy_math::Vec2;
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
prelude::LegacyColor,
|
|
||||||
primitives::Aabb,
|
primitives::Aabb,
|
||||||
texture::Image,
|
texture::Image,
|
||||||
view::{InheritedVisibility, NoFrustumCulling, ViewVisibility, Visibility},
|
view::{InheritedVisibility, NoFrustumCulling, ViewVisibility, Visibility},
|
||||||
|
@ -117,7 +117,7 @@ pub fn extract_text2d_sprite(
|
||||||
let transform = *global_transform
|
let transform = *global_transform
|
||||||
* GlobalTransform::from_translation(alignment_translation.extend(0.))
|
* GlobalTransform::from_translation(alignment_translation.extend(0.))
|
||||||
* scaling;
|
* scaling;
|
||||||
let mut color = LegacyColor::WHITE;
|
let mut color = LinearRgba::WHITE;
|
||||||
let mut current_section = usize::MAX;
|
let mut current_section = usize::MAX;
|
||||||
for PositionedGlyph {
|
for PositionedGlyph {
|
||||||
position,
|
position,
|
||||||
|
@ -127,7 +127,7 @@ pub fn extract_text2d_sprite(
|
||||||
} in &text_layout_info.glyphs
|
} in &text_layout_info.glyphs
|
||||||
{
|
{
|
||||||
if *section_index != current_section {
|
if *section_index != current_section {
|
||||||
color = text.sections[*section_index].style.color.as_rgba_linear();
|
color = LinearRgba::from(text.sections[*section_index].style.color);
|
||||||
current_section = *section_index;
|
current_section = *section_index;
|
||||||
}
|
}
|
||||||
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();
|
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();
|
||||||
|
|
|
@ -13,6 +13,7 @@ keywords = ["bevy"]
|
||||||
bevy_a11y = { path = "../bevy_a11y", version = "0.14.0-dev" }
|
bevy_a11y = { path = "../bevy_a11y", version = "0.14.0-dev" }
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
|
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||||
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
|
||||||
bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" }
|
bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
|
|
|
@ -8,11 +8,9 @@ use crate::{
|
||||||
UiMaterial, ZIndex,
|
UiMaterial, ZIndex,
|
||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_ecs::bundle::Bundle;
|
use bevy_ecs::bundle::Bundle;
|
||||||
use bevy_render::{
|
use bevy_render::view::{InheritedVisibility, ViewVisibility, Visibility};
|
||||||
prelude::LegacyColor,
|
|
||||||
view::{InheritedVisibility, ViewVisibility, Visibility},
|
|
||||||
};
|
|
||||||
use bevy_sprite::TextureAtlas;
|
use bevy_sprite::TextureAtlas;
|
||||||
#[cfg(feature = "bevy_text")]
|
#[cfg(feature = "bevy_text")]
|
||||||
use bevy_text::{BreakLineOn, JustifyText, Text, TextLayoutInfo, TextSection, TextStyle};
|
use bevy_text::{BreakLineOn, JustifyText, Text, TextLayoutInfo, TextSection, TextStyle};
|
||||||
|
@ -60,8 +58,8 @@ impl Default for NodeBundle {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
NodeBundle {
|
NodeBundle {
|
||||||
// Transparent background
|
// Transparent background
|
||||||
background_color: LegacyColor::NONE.into(),
|
background_color: Color::NONE.into(),
|
||||||
border_color: LegacyColor::NONE.into(),
|
border_color: Color::NONE.into(),
|
||||||
node: Default::default(),
|
node: Default::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
focus_policy: Default::default(),
|
focus_policy: Default::default(),
|
||||||
|
@ -227,7 +225,7 @@ impl Default for TextBundle {
|
||||||
view_visibility: Default::default(),
|
view_visibility: Default::default(),
|
||||||
z_index: Default::default(),
|
z_index: Default::default(),
|
||||||
// Transparent background
|
// Transparent background
|
||||||
background_color: BackgroundColor(LegacyColor::NONE),
|
background_color: BackgroundColor(Color::NONE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +265,7 @@ impl TextBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns this [`TextBundle`] with a new [`BackgroundColor`].
|
/// Returns this [`TextBundle`] with a new [`BackgroundColor`].
|
||||||
pub const fn with_background_color(mut self, color: LegacyColor) -> Self {
|
pub const fn with_background_color(mut self, color: Color) -> Self {
|
||||||
self.background_color = BackgroundColor(color);
|
self.background_color = BackgroundColor(color);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -343,7 +341,7 @@ impl Default for ButtonBundle {
|
||||||
node: Default::default(),
|
node: Default::default(),
|
||||||
button: Default::default(),
|
button: Default::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
border_color: BorderColor(LegacyColor::NONE),
|
border_color: BorderColor(Color::NONE),
|
||||||
interaction: Default::default(),
|
interaction: Default::default(),
|
||||||
background_color: Default::default(),
|
background_color: Default::default(),
|
||||||
image: Default::default(),
|
image: Default::default(),
|
||||||
|
|
|
@ -2,6 +2,7 @@ mod pipeline;
|
||||||
mod render_pass;
|
mod render_pass;
|
||||||
mod ui_material_pipeline;
|
mod ui_material_pipeline;
|
||||||
|
|
||||||
|
use bevy_color::{Alpha, LinearRgba};
|
||||||
use bevy_core_pipeline::core_2d::graph::{Core2d, Node2d};
|
use bevy_core_pipeline::core_2d::graph::{Core2d, Node2d};
|
||||||
use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
|
use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
|
||||||
use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
|
use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
|
||||||
|
@ -25,7 +26,6 @@ use bevy_ecs::prelude::*;
|
||||||
use bevy_math::{Mat4, Rect, URect, UVec4, Vec2, Vec3, Vec4Swizzles};
|
use bevy_math::{Mat4, Rect, URect, UVec4, Vec2, Vec3, Vec4Swizzles};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
color::LegacyColor,
|
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
render_graph::{RenderGraph, RunGraphOnViewNode},
|
render_graph::{RenderGraph, RunGraphOnViewNode},
|
||||||
render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions, RenderPhase},
|
render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions, RenderPhase},
|
||||||
|
@ -130,7 +130,7 @@ fn get_ui_graph(render_app: &mut App) -> RenderGraph {
|
||||||
pub struct ExtractedUiNode {
|
pub struct ExtractedUiNode {
|
||||||
pub stack_index: u32,
|
pub stack_index: u32,
|
||||||
pub transform: Mat4,
|
pub transform: Mat4,
|
||||||
pub color: LegacyColor,
|
pub color: LinearRgba,
|
||||||
pub rect: Rect,
|
pub rect: Rect,
|
||||||
pub image: AssetId<Image>,
|
pub image: AssetId<Image>,
|
||||||
pub atlas_size: Option<Vec2>,
|
pub atlas_size: Option<Vec2>,
|
||||||
|
@ -264,7 +264,7 @@ pub fn extract_uinode_borders(
|
||||||
stack_index: node.stack_index,
|
stack_index: node.stack_index,
|
||||||
// This translates the uinode's transform to the center of the current border rectangle
|
// This translates the uinode's transform to the center of the current border rectangle
|
||||||
transform: transform * Mat4::from_translation(edge.center().extend(0.)),
|
transform: transform * Mat4::from_translation(edge.center().extend(0.)),
|
||||||
color: border_color.0,
|
color: border_color.0.into(),
|
||||||
rect: Rect {
|
rect: Rect {
|
||||||
max: edge.size(),
|
max: edge.size(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -355,7 +355,7 @@ pub fn extract_uinode_outlines(
|
||||||
stack_index: node.stack_index,
|
stack_index: node.stack_index,
|
||||||
// This translates the uinode's transform to the center of the current border rectangle
|
// This translates the uinode's transform to the center of the current border rectangle
|
||||||
transform: transform * Mat4::from_translation(edge.center().extend(0.)),
|
transform: transform * Mat4::from_translation(edge.center().extend(0.)),
|
||||||
color: outline.color,
|
color: outline.color.into(),
|
||||||
rect: Rect {
|
rect: Rect {
|
||||||
max: edge.size(),
|
max: edge.size(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -458,7 +458,7 @@ pub fn extract_uinodes(
|
||||||
ExtractedUiNode {
|
ExtractedUiNode {
|
||||||
stack_index: uinode.stack_index,
|
stack_index: uinode.stack_index,
|
||||||
transform: transform.compute_matrix(),
|
transform: transform.compute_matrix(),
|
||||||
color: color.0,
|
color: color.0.into(),
|
||||||
rect,
|
rect,
|
||||||
clip: clip.map(|clip| clip.clip),
|
clip: clip.map(|clip| clip.clip),
|
||||||
image,
|
image,
|
||||||
|
@ -598,7 +598,7 @@ pub fn extract_text_uinodes(
|
||||||
let transform = Mat4::from(global_transform.affine())
|
let transform = Mat4::from(global_transform.affine())
|
||||||
* Mat4::from_translation(logical_top_left_nearest_pixel.extend(0.));
|
* Mat4::from_translation(logical_top_left_nearest_pixel.extend(0.));
|
||||||
|
|
||||||
let mut color = LegacyColor::WHITE;
|
let mut color = LinearRgba::WHITE;
|
||||||
let mut current_section = usize::MAX;
|
let mut current_section = usize::MAX;
|
||||||
for PositionedGlyph {
|
for PositionedGlyph {
|
||||||
position,
|
position,
|
||||||
|
@ -608,7 +608,7 @@ pub fn extract_text_uinodes(
|
||||||
} in &text_layout_info.glyphs
|
} in &text_layout_info.glyphs
|
||||||
{
|
{
|
||||||
if *section_index != current_section {
|
if *section_index != current_section {
|
||||||
color = text.sections[*section_index].style.color.as_rgba_linear();
|
color = LinearRgba::from(text.sections[*section_index].style.color);
|
||||||
current_section = *section_index;
|
current_section = *section_index;
|
||||||
}
|
}
|
||||||
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();
|
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();
|
||||||
|
@ -935,7 +935,7 @@ pub fn prepare_uinodes(
|
||||||
.map(|pos| pos / atlas_extent)
|
.map(|pos| pos / atlas_extent)
|
||||||
};
|
};
|
||||||
|
|
||||||
let color = extracted_uinode.color.as_linear_rgba_f32();
|
let color = extracted_uinode.color.to_f32_array();
|
||||||
for i in QUAD_INDICES {
|
for i in QUAD_INDICES {
|
||||||
ui_meta.vertices.push(UiVertex {
|
ui_meta.vertices.push(UiVertex {
|
||||||
position: positions_clipped[i].into(),
|
position: positions_clipped[i].into(),
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl ComputedTextureSlices {
|
||||||
let atlas_size = Some(self.image_size * scale);
|
let atlas_size = Some(self.image_size * scale);
|
||||||
ExtractedUiNode {
|
ExtractedUiNode {
|
||||||
stack_index: node.stack_index,
|
stack_index: node.stack_index,
|
||||||
color: background_color.0,
|
color: background_color.0.into(),
|
||||||
transform: transform.compute_matrix(),
|
transform: transform.compute_matrix(),
|
||||||
rect,
|
rect,
|
||||||
flip_x,
|
flip_x,
|
||||||
|
|
|
@ -24,7 +24,8 @@ use bevy_render::render_resource::{AsBindGroup, RenderPipelineDescriptor, Shader
|
||||||
/// # use bevy_ui::prelude::*;
|
/// # use bevy_ui::prelude::*;
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_reflect::TypePath;
|
/// # use bevy_reflect::TypePath;
|
||||||
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image, color::LegacyColor};
|
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image};
|
||||||
|
/// # use bevy_color::LinearRgba;
|
||||||
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
/// # use bevy_asset::{Handle, AssetServer, Assets, Asset};
|
||||||
///
|
///
|
||||||
/// #[derive(AsBindGroup, Asset, TypePath, Debug, Clone)]
|
/// #[derive(AsBindGroup, Asset, TypePath, Debug, Clone)]
|
||||||
|
@ -32,7 +33,7 @@ use bevy_render::render_resource::{AsBindGroup, RenderPipelineDescriptor, Shader
|
||||||
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
|
||||||
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
/// // its shader-compatible equivalent. Most core math types already implement `ShaderType`.
|
||||||
/// #[uniform(0)]
|
/// #[uniform(0)]
|
||||||
/// color: LegacyColor,
|
/// color: LinearRgba,
|
||||||
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
/// // Images can be bound as textures in shaders. If the Image's sampler is also needed, just
|
||||||
/// // add the sampler attribute with a different binding index.
|
/// // add the sampler attribute with a different binding index.
|
||||||
/// #[texture(1)]
|
/// #[texture(1)]
|
||||||
|
@ -56,7 +57,7 @@ use bevy_render::render_resource::{AsBindGroup, RenderPipelineDescriptor, Shader
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// },
|
/// },
|
||||||
/// material: materials.add(CustomMaterial {
|
/// material: materials.add(CustomMaterial {
|
||||||
/// color: LegacyColor::RED,
|
/// color: LinearRgba::RED,
|
||||||
/// color_texture: asset_server.load("some_image.png"),
|
/// color_texture: asset_server.load("some_image.png"),
|
||||||
/// }),
|
/// }),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::{UiRect, Val};
|
use crate::{UiRect, Val};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_color::Color;
|
||||||
use bevy_ecs::{prelude::*, system::SystemParam};
|
use bevy_ecs::{prelude::*, system::SystemParam};
|
||||||
use bevy_math::{Rect, Vec2};
|
use bevy_math::{Rect, Vec2};
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
camera::{Camera, RenderTarget},
|
camera::{Camera, RenderTarget},
|
||||||
color::LegacyColor,
|
|
||||||
texture::Image,
|
texture::Image,
|
||||||
};
|
};
|
||||||
use bevy_transform::prelude::GlobalTransform;
|
use bevy_transform::prelude::GlobalTransform;
|
||||||
|
@ -1597,10 +1597,10 @@ pub enum GridPlacementError {
|
||||||
derive(serde::Serialize, serde::Deserialize),
|
derive(serde::Serialize, serde::Deserialize),
|
||||||
reflect(Serialize, Deserialize)
|
reflect(Serialize, Deserialize)
|
||||||
)]
|
)]
|
||||||
pub struct BackgroundColor(pub LegacyColor);
|
pub struct BackgroundColor(pub Color);
|
||||||
|
|
||||||
impl BackgroundColor {
|
impl BackgroundColor {
|
||||||
pub const DEFAULT: Self = Self(LegacyColor::WHITE);
|
pub const DEFAULT: Self = Self(Color::WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BackgroundColor {
|
impl Default for BackgroundColor {
|
||||||
|
@ -1609,9 +1609,9 @@ impl Default for BackgroundColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LegacyColor> for BackgroundColor {
|
impl<T: Into<Color>> From<T> for BackgroundColor {
|
||||||
fn from(color: LegacyColor) -> Self {
|
fn from(color: T) -> Self {
|
||||||
Self(color)
|
Self(color.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1623,16 +1623,16 @@ impl From<LegacyColor> for BackgroundColor {
|
||||||
derive(serde::Serialize, serde::Deserialize),
|
derive(serde::Serialize, serde::Deserialize),
|
||||||
reflect(Serialize, Deserialize)
|
reflect(Serialize, Deserialize)
|
||||||
)]
|
)]
|
||||||
pub struct BorderColor(pub LegacyColor);
|
pub struct BorderColor(pub Color);
|
||||||
|
|
||||||
impl From<LegacyColor> for BorderColor {
|
impl<T: Into<Color>> From<T> for BorderColor {
|
||||||
fn from(color: LegacyColor) -> Self {
|
fn from(color: T) -> Self {
|
||||||
Self(color)
|
Self(color.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BorderColor {
|
impl BorderColor {
|
||||||
pub const DEFAULT: Self = BorderColor(LegacyColor::WHITE);
|
pub const DEFAULT: Self = BorderColor(Color::WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BorderColor {
|
impl Default for BorderColor {
|
||||||
|
@ -1655,7 +1655,7 @@ impl Default for BorderColor {
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ui::prelude::*;
|
/// # use bevy_ui::prelude::*;
|
||||||
/// # use bevy_render::prelude::LegacyColor;
|
/// # use bevy_color::palettes::basic::{RED, BLUE};
|
||||||
/// fn setup_ui(mut commands: Commands) {
|
/// fn setup_ui(mut commands: Commands) {
|
||||||
/// commands.spawn((
|
/// commands.spawn((
|
||||||
/// NodeBundle {
|
/// NodeBundle {
|
||||||
|
@ -1664,10 +1664,10 @@ impl Default for BorderColor {
|
||||||
/// height: Val::Px(100.),
|
/// height: Val::Px(100.),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// },
|
/// },
|
||||||
/// background_color: LegacyColor::BLUE.into(),
|
/// background_color: BLUE.into(),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// },
|
/// },
|
||||||
/// Outline::new(Val::Px(10.), Val::ZERO, LegacyColor::RED)
|
/// Outline::new(Val::Px(10.), Val::ZERO, RED.into())
|
||||||
/// ));
|
/// ));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1676,7 +1676,7 @@ impl Default for BorderColor {
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ui::prelude::*;
|
/// # use bevy_ui::prelude::*;
|
||||||
/// # use bevy_render::prelude::LegacyColor;
|
/// # use bevy_color::Color;
|
||||||
/// fn outline_hovered_button_system(
|
/// fn outline_hovered_button_system(
|
||||||
/// mut commands: Commands,
|
/// mut commands: Commands,
|
||||||
/// mut node_query: Query<(Entity, &Interaction, Option<&mut Outline>), Changed<Interaction>>,
|
/// mut node_query: Query<(Entity, &Interaction, Option<&mut Outline>), Changed<Interaction>>,
|
||||||
|
@ -1684,9 +1684,9 @@ impl Default for BorderColor {
|
||||||
/// for (entity, interaction, mut maybe_outline) in node_query.iter_mut() {
|
/// for (entity, interaction, mut maybe_outline) in node_query.iter_mut() {
|
||||||
/// let outline_color =
|
/// let outline_color =
|
||||||
/// if matches!(*interaction, Interaction::Hovered) {
|
/// if matches!(*interaction, Interaction::Hovered) {
|
||||||
/// LegacyColor::WHITE
|
/// Color::WHITE
|
||||||
/// } else {
|
/// } else {
|
||||||
/// LegacyColor::NONE
|
/// Color::NONE
|
||||||
/// };
|
/// };
|
||||||
/// if let Some(mut outline) = maybe_outline {
|
/// if let Some(mut outline) = maybe_outline {
|
||||||
/// outline.color = outline_color;
|
/// outline.color = outline_color;
|
||||||
|
@ -1697,7 +1697,7 @@ impl Default for BorderColor {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// Inserting and removing an [`Outline`] component repeatedly will result in table moves, so it is generally preferable to
|
/// Inserting and removing an [`Outline`] component repeatedly will result in table moves, so it is generally preferable to
|
||||||
/// set `Outline::color` to `LegacyColor::NONE` to hide an outline.
|
/// set `Outline::color` to [`Color::NONE`] to hide an outline.
|
||||||
pub struct Outline {
|
pub struct Outline {
|
||||||
/// The width of the outline.
|
/// The width of the outline.
|
||||||
///
|
///
|
||||||
|
@ -1709,14 +1709,14 @@ pub struct Outline {
|
||||||
pub offset: Val,
|
pub offset: Val,
|
||||||
/// The color of the outline.
|
/// The color of the outline.
|
||||||
///
|
///
|
||||||
/// If you are frequently toggling outlines for a UI node on and off it is recommended to set `LegacyColor::NONE` to hide the outline.
|
/// If you are frequently toggling outlines for a UI node on and off it is recommended to set [`Color::NONE`] to hide the outline.
|
||||||
/// This avoids the table moves that would occur from the repeated insertion and removal of the `Outline` component.
|
/// This avoids the table moves that would occur from the repeated insertion and removal of the `Outline` component.
|
||||||
pub color: LegacyColor,
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Outline {
|
impl Outline {
|
||||||
/// Create a new outline
|
/// Create a new outline
|
||||||
pub const fn new(width: Val, offset: Val, color: LegacyColor) -> Self {
|
pub const fn new(width: Val, offset: Val, color: Color) -> Self {
|
||||||
Self {
|
Self {
|
||||||
width,
|
width,
|
||||||
offset,
|
offset,
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn setup_cube(
|
||||||
// cube
|
// cube
|
||||||
parent.spawn(PbrBundle {
|
parent.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -81,7 +81,7 @@ fn setup_cube(
|
||||||
// cube
|
// cube
|
||||||
parent.spawn(PbrBundle {
|
parent.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn setup(
|
||||||
|
|
||||||
for (i, shape) in shapes.into_iter().enumerate() {
|
for (i, shape) in shapes.into_iter().enumerate() {
|
||||||
// Distribute colors evenly across the rainbow.
|
// Distribute colors evenly across the rainbow.
|
||||||
let color = LegacyColor::hsl(360. * i as f32 / num_shapes as f32, 0.95, 0.7);
|
let color = Color::hsl(360. * i as f32 / num_shapes as f32, 0.95, 0.7);
|
||||||
|
|
||||||
commands.spawn(MaterialMesh2dBundle {
|
commands.spawn(MaterialMesh2dBundle {
|
||||||
mesh: shape,
|
mesh: shape,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! This example demonstrates how to use the `Camera::viewport_to_world_2d` method.
|
//! This example demonstrates how to use the `Camera::viewport_to_world_2d` method.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::{color::palettes::basic::WHITE, prelude::*};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -26,7 +26,7 @@ fn draw_cursor(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
gizmos.circle_2d(point, 10., LegacyColor::WHITE);
|
gizmos.circle_2d(point, 10., WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands) {
|
fn setup(mut commands: Commands) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn setup(
|
||||||
commands.spawn(SpriteBundle {
|
commands.spawn(SpriteBundle {
|
||||||
texture: asset_server.load("branding/bevy_bird_dark.png"),
|
texture: asset_server.load("branding/bevy_bird_dark.png"),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
color: LegacyColor::rgb(5.0, 5.0, 5.0), // 4. Put something bright in a dark environment to see the effect
|
color: Color::srgb(5.0, 5.0, 5.0), // 4. Put something bright in a dark environment to see the effect
|
||||||
custom_size: Some(Vec2::splat(160.0)),
|
custom_size: Some(Vec2::splat(160.0)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -50,7 +50,7 @@ fn setup(
|
||||||
commands.spawn(MaterialMesh2dBundle {
|
commands.spawn(MaterialMesh2dBundle {
|
||||||
mesh: meshes.add(Circle::new(100.)).into(),
|
mesh: meshes.add(Circle::new(100.)).into(),
|
||||||
// 4. Put something bright in a dark environment to see the effect
|
// 4. Put something bright in a dark environment to see the effect
|
||||||
material: materials.add(LegacyColor::rgb(7.5, 0.0, 7.5)),
|
material: materials.add(Color::srgb(7.5, 0.0, 7.5)),
|
||||||
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
|
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -59,7 +59,7 @@ fn setup(
|
||||||
commands.spawn(MaterialMesh2dBundle {
|
commands.spawn(MaterialMesh2dBundle {
|
||||||
mesh: meshes.add(RegularPolygon::new(100., 6)).into(),
|
mesh: meshes.add(RegularPolygon::new(100., 6)).into(),
|
||||||
// 4. Put something bright in a dark environment to see the effect
|
// 4. Put something bright in a dark environment to see the effect
|
||||||
material: materials.add(LegacyColor::rgb(6.25, 9.4, 9.1)),
|
material: materials.add(Color::srgb(6.25, 9.4, 9.1)),
|
||||||
transform: Transform::from_translation(Vec3::new(200., 0., 0.)),
|
transform: Transform::from_translation(Vec3::new(200., 0., 0.)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ fn setup(
|
||||||
"",
|
"",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font_size: 18.0,
|
font_size: 18.0,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! This example demonstrates bounding volume intersections.
|
//! This example demonstrates bounding volume intersections.
|
||||||
|
|
||||||
use bevy::{math::bounding::*, prelude::*};
|
use bevy::{color::palettes::css::*, math::bounding::*, prelude::*};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -97,7 +97,7 @@ enum Shape {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_shapes(mut gizmos: Gizmos, query: Query<(&Shape, &Transform)>) {
|
fn render_shapes(mut gizmos: Gizmos, query: Query<(&Shape, &Transform)>) {
|
||||||
let color = LegacyColor::GRAY;
|
let color = GRAY;
|
||||||
for (shape, transform) in query.iter() {
|
for (shape, transform) in query.iter() {
|
||||||
let translation = transform.translation.xy();
|
let translation = transform.translation.xy();
|
||||||
let rotation = transform.rotation.to_euler(EulerRot::YXZ).2;
|
let rotation = transform.rotation.to_euler(EulerRot::YXZ).2;
|
||||||
|
@ -177,11 +177,7 @@ fn update_volumes(
|
||||||
|
|
||||||
fn render_volumes(mut gizmos: Gizmos, query: Query<(&CurrentVolume, &Intersects)>) {
|
fn render_volumes(mut gizmos: Gizmos, query: Query<(&CurrentVolume, &Intersects)>) {
|
||||||
for (volume, intersects) in query.iter() {
|
for (volume, intersects) in query.iter() {
|
||||||
let color = if **intersects {
|
let color = if **intersects { CYAN } else { ORANGE_RED };
|
||||||
LegacyColor::CYAN
|
|
||||||
} else {
|
|
||||||
LegacyColor::ORANGE_RED
|
|
||||||
};
|
|
||||||
match volume {
|
match volume {
|
||||||
CurrentVolume::Aabb(a) => {
|
CurrentVolume::Aabb(a) => {
|
||||||
gizmos.rect_2d(a.center(), 0., a.half_size() * 2., color);
|
gizmos.rect_2d(a.center(), 0., a.half_size() * 2., color);
|
||||||
|
@ -292,10 +288,10 @@ fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
|
||||||
gizmos.line_2d(
|
gizmos.line_2d(
|
||||||
ray.ray.origin,
|
ray.ray.origin,
|
||||||
ray.ray.origin + *ray.ray.direction * ray.max,
|
ray.ray.origin + *ray.ray.direction * ray.max,
|
||||||
LegacyColor::WHITE,
|
WHITE,
|
||||||
);
|
);
|
||||||
for r in [1., 2., 3.] {
|
for r in [1., 2., 3.] {
|
||||||
gizmos.circle_2d(ray.ray.origin, r, LegacyColor::FUCHSIA);
|
gizmos.circle_2d(ray.ray.origin, r, FUCHSIA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +327,7 @@ fn ray_cast_system(
|
||||||
gizmos.circle_2d(
|
gizmos.circle_2d(
|
||||||
ray_cast.ray.origin + *ray_cast.ray.direction * toi,
|
ray_cast.ray.origin + *ray_cast.ray.direction * toi,
|
||||||
r,
|
r,
|
||||||
LegacyColor::GREEN,
|
GREEN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,7 +359,7 @@ fn aabb_cast_system(
|
||||||
+ aabb_cast.aabb.center(),
|
+ aabb_cast.aabb.center(),
|
||||||
0.,
|
0.,
|
||||||
aabb_cast.aabb.half_size() * 2.,
|
aabb_cast.aabb.half_size() * 2.,
|
||||||
LegacyColor::GREEN,
|
GREEN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,7 +389,7 @@ fn bounding_circle_cast_system(
|
||||||
+ *circle_cast.ray.ray.direction * toi
|
+ *circle_cast.ray.ray.direction * toi
|
||||||
+ circle_cast.circle.center(),
|
+ circle_cast.circle.center(),
|
||||||
circle_cast.circle.radius(),
|
circle_cast.circle.radius(),
|
||||||
LegacyColor::GREEN,
|
GREEN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,7 +408,7 @@ fn aabb_intersection_system(
|
||||||
) {
|
) {
|
||||||
let center = get_intersection_position(&time);
|
let center = get_intersection_position(&time);
|
||||||
let aabb = Aabb2d::new(center, Vec2::splat(50.));
|
let aabb = Aabb2d::new(center, Vec2::splat(50.));
|
||||||
gizmos.rect_2d(center, 0., aabb.half_size() * 2., LegacyColor::YELLOW);
|
gizmos.rect_2d(center, 0., aabb.half_size() * 2., YELLOW);
|
||||||
|
|
||||||
for (volume, mut intersects) in volumes.iter_mut() {
|
for (volume, mut intersects) in volumes.iter_mut() {
|
||||||
let hit = match volume {
|
let hit = match volume {
|
||||||
|
@ -431,7 +427,7 @@ fn circle_intersection_system(
|
||||||
) {
|
) {
|
||||||
let center = get_intersection_position(&time);
|
let center = get_intersection_position(&time);
|
||||||
let circle = BoundingCircle::new(center, 50.);
|
let circle = BoundingCircle::new(center, 50.);
|
||||||
gizmos.circle_2d(center, circle.radius(), LegacyColor::YELLOW);
|
gizmos.circle_2d(center, circle.radius(), YELLOW);
|
||||||
|
|
||||||
for (volume, mut intersects) in volumes.iter_mut() {
|
for (volume, mut intersects) in volumes.iter_mut() {
|
||||||
let hit = match volume {
|
let hit = match volume {
|
||||||
|
|
|
@ -21,7 +21,7 @@ const ATTRIBUTE_BARYCENTRIC: MeshVertexAttribute =
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.insert_resource(AmbientLight {
|
.insert_resource(AmbientLight {
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 1.0 / 5.0f32,
|
brightness: 1.0 / 5.0f32,
|
||||||
})
|
})
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! [`Quad`]: shape::Quad
|
//! [`Quad`]: shape::Quad
|
||||||
|
|
||||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
use bevy::{color::palettes::basic::PURPLE, prelude::*, sprite::MaterialMesh2dBundle};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -20,7 +20,7 @@ fn setup(
|
||||||
commands.spawn(MaterialMesh2dBundle {
|
commands.spawn(MaterialMesh2dBundle {
|
||||||
mesh: meshes.add(Rectangle::default()).into(),
|
mesh: meshes.add(Rectangle::default()).into(),
|
||||||
transform: Transform::default().with_scale(Vec3::splat(128.)),
|
transform: Transform::default().with_scale(Vec3::splat(128.)),
|
||||||
material: materials.add(LegacyColor::PURPLE),
|
material: materials.add(Color::from(PURPLE)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
//! [`Material2d`]: bevy::sprite::Material2d
|
//! [`Material2d`]: bevy::sprite::Material2d
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::basic::YELLOW,
|
||||||
core_pipeline::core_2d::Transparent2d,
|
core_pipeline::core_2d::Transparent2d,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
mesh::{Indices, MeshVertexAttribute},
|
mesh::{Indices, MeshVertexAttribute},
|
||||||
render_asset::RenderAssetUsages,
|
render_asset::{RenderAssetUsages, RenderAssets},
|
||||||
render_asset::RenderAssets,
|
|
||||||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
BlendState, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
|
BlendState, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
|
||||||
|
@ -80,8 +80,8 @@ fn star(
|
||||||
// Set the position attribute
|
// Set the position attribute
|
||||||
star.insert_attribute(Mesh::ATTRIBUTE_POSITION, v_pos);
|
star.insert_attribute(Mesh::ATTRIBUTE_POSITION, v_pos);
|
||||||
// And a RGB color attribute as well
|
// And a RGB color attribute as well
|
||||||
let mut v_color: Vec<u32> = vec![LegacyColor::BLACK.as_linear_rgba_u32()];
|
let mut v_color: Vec<u32> = vec![LinearRgba::BLACK.as_u32()];
|
||||||
v_color.extend_from_slice(&[LegacyColor::YELLOW.as_linear_rgba_u32(); 10]);
|
v_color.extend_from_slice(&[LinearRgba::from(YELLOW).as_u32(); 10]);
|
||||||
star.insert_attribute(
|
star.insert_attribute(
|
||||||
MeshVertexAttribute::new("Vertex_Color", 1, VertexFormat::Uint32),
|
MeshVertexAttribute::new("Vertex_Color", 1, VertexFormat::Uint32),
|
||||||
v_color,
|
v_color,
|
||||||
|
|
|
@ -27,10 +27,10 @@ fn setup(
|
||||||
let mut mesh = Mesh::from(Rectangle::default());
|
let mut mesh = Mesh::from(Rectangle::default());
|
||||||
// Build vertex colors for the quad. One entry per vertex (the corners of the quad)
|
// Build vertex colors for the quad. One entry per vertex (the corners of the quad)
|
||||||
let vertex_colors: Vec<[f32; 4]> = vec![
|
let vertex_colors: Vec<[f32; 4]> = vec![
|
||||||
LegacyColor::RED.as_rgba_f32(),
|
LinearRgba::RED.to_f32_array(),
|
||||||
LegacyColor::GREEN.as_rgba_f32(),
|
LinearRgba::GREEN.to_f32_array(),
|
||||||
LegacyColor::BLUE.as_rgba_f32(),
|
LinearRgba::BLUE.to_f32_array(),
|
||||||
LegacyColor::WHITE.as_rgba_f32(),
|
LinearRgba::WHITE.to_f32_array(),
|
||||||
];
|
];
|
||||||
// Insert the vertex colors as an attribute
|
// Insert the vertex colors as an attribute
|
||||||
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, vertex_colors);
|
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, vertex_colors);
|
||||||
|
|
|
@ -85,7 +85,7 @@ fn setup_mesh(
|
||||||
MaterialMesh2dBundle {
|
MaterialMesh2dBundle {
|
||||||
mesh: meshes.add(Capsule2d::default()).into(),
|
mesh: meshes.add(Capsule2d::default()).into(),
|
||||||
transform: Transform::from_xyz(40., 0., 2.).with_scale(Vec3::splat(32.)),
|
transform: Transform::from_xyz(40., 0., 2.).with_scale(Vec3::splat(32.)),
|
||||||
material: materials.add(LegacyColor::BLACK),
|
material: materials.add(Color::BLACK),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Rotate,
|
Rotate,
|
||||||
|
|
|
@ -114,7 +114,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let style = TextStyle {
|
let style = TextStyle {
|
||||||
font: font.clone(),
|
font: font.clone(),
|
||||||
font_size: 16.0,
|
font_size: 16.0,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load textures
|
// Load textures
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! viewport, you may want to look at `games/contributors.rs` or `ui/text.rs`.
|
//! viewport, you may want to look at `games/contributors.rs` or `ui/text.rs`.
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::css::*,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
sprite::Anchor,
|
sprite::Anchor,
|
||||||
text::{BreakLineOn, Text2dBounds},
|
text::{BreakLineOn, Text2dBounds},
|
||||||
|
@ -36,7 +37,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let text_style = TextStyle {
|
let text_style = TextStyle {
|
||||||
font: font.clone(),
|
font: font.clone(),
|
||||||
font_size: 60.0,
|
font_size: 60.0,
|
||||||
color: LegacyColor::WHITE,
|
..default()
|
||||||
};
|
};
|
||||||
let text_justification = JustifyText::Center;
|
let text_justification = JustifyText::Center;
|
||||||
// 2d camera
|
// 2d camera
|
||||||
|
@ -72,14 +73,14 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let slightly_smaller_text_style = TextStyle {
|
let slightly_smaller_text_style = TextStyle {
|
||||||
font,
|
font,
|
||||||
font_size: 42.0,
|
font_size: 42.0,
|
||||||
color: LegacyColor::WHITE,
|
..default()
|
||||||
};
|
};
|
||||||
let box_size = Vec2::new(300.0, 200.0);
|
let box_size = Vec2::new(300.0, 200.0);
|
||||||
let box_position = Vec2::new(0.0, -250.0);
|
let box_position = Vec2::new(0.0, -250.0);
|
||||||
commands
|
commands
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
color: LegacyColor::rgb(0.25, 0.25, 0.75),
|
color: Color::srgb(0.25, 0.25, 0.75),
|
||||||
custom_size: Some(Vec2::new(box_size.x, box_size.y)),
|
custom_size: Some(Vec2::new(box_size.x, box_size.y)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -111,7 +112,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
commands
|
commands
|
||||||
.spawn(SpriteBundle {
|
.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
color: LegacyColor::rgb(0.20, 0.3, 0.70),
|
color: Color::srgb(0.20, 0.3, 0.70),
|
||||||
custom_size: Some(Vec2::new(other_box_size.x, other_box_size.y)),
|
custom_size: Some(Vec2::new(other_box_size.x, other_box_size.y)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -139,10 +140,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (text_anchor, color) in [
|
for (text_anchor, color) in [
|
||||||
(Anchor::TopLeft, LegacyColor::RED),
|
(Anchor::TopLeft, Color::Srgba(RED)),
|
||||||
(Anchor::TopRight, LegacyColor::GREEN),
|
(Anchor::TopRight, Color::Srgba(GREEN)),
|
||||||
(Anchor::BottomRight, LegacyColor::BLUE),
|
(Anchor::BottomRight, Color::Srgba(BLUE)),
|
||||||
(Anchor::BottomLeft, LegacyColor::YELLOW),
|
(Anchor::BottomLeft, Color::Srgba(YELLOW)),
|
||||||
] {
|
] {
|
||||||
commands.spawn(Text2dBundle {
|
commands.spawn(Text2dBundle {
|
||||||
text: Text {
|
text: Text {
|
||||||
|
|
|
@ -124,7 +124,7 @@ fn setup(
|
||||||
let text_style: TextStyle = TextStyle {
|
let text_style: TextStyle = TextStyle {
|
||||||
font: font.clone(),
|
font: font.clone(),
|
||||||
font_size: 50.0,
|
font_size: 50.0,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// labels to indicate padding
|
// labels to indicate padding
|
||||||
|
@ -173,7 +173,7 @@ fn setup(
|
||||||
let sampling_label_style = TextStyle {
|
let sampling_label_style = TextStyle {
|
||||||
font,
|
font,
|
||||||
font_size: 30.0,
|
font_size: 30.0,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_y = 170.0; // y position of the sprites
|
let base_y = 170.0; // y position of the sprites
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
commands.spawn(SpriteBundle {
|
commands.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
// Alpha channel of the color controls transparency.
|
// Alpha channel of the color controls transparency.
|
||||||
color: LegacyColor::rgba(0.0, 0.0, 1.0, 0.7),
|
color: Color::srgba(0.0, 0.0, 1.0, 0.7),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
texture: sprite_handle.clone(),
|
texture: sprite_handle.clone(),
|
||||||
|
@ -31,7 +31,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
});
|
});
|
||||||
commands.spawn(SpriteBundle {
|
commands.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
color: LegacyColor::rgba(0.0, 1.0, 0.0, 0.3),
|
color: Color::srgba(0.0, 1.0, 0.0, 0.3),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
texture: sprite_handle,
|
texture: sprite_handle,
|
||||||
|
|
|
@ -18,14 +18,14 @@ fn setup(
|
||||||
// circular base
|
// circular base
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Circle::new(4.0)),
|
mesh: meshes.add(Circle::new(4.0)),
|
||||||
material: materials.add(LegacyColor::WHITE),
|
material: materials.add(Color::WHITE),
|
||||||
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cube
|
// cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||||
material: materials.add(LegacyColor::rgb_u8(124, 144, 255)),
|
material: materials.add(Color::srgb_u8(124, 144, 255)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::basic::SILVER,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
render_asset::RenderAssetUsages,
|
render_asset::RenderAssetUsages,
|
||||||
|
@ -78,7 +79,7 @@ fn setup(
|
||||||
// ground plane
|
// ground plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
||||||
material: materials.add(LegacyColor::SILVER),
|
material: materials.add(Color::from(SILVER)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! This example demonstrates how to use the `Camera::viewport_to_world` method.
|
//! This example demonstrates how to use the `Camera::viewport_to_world` method.
|
||||||
|
|
||||||
use bevy::math::Dir3;
|
use bevy::{math::Dir3, prelude::*};
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -41,7 +40,7 @@ fn draw_cursor(
|
||||||
point + ground.up() * 0.01,
|
point + ground.up() * 0.01,
|
||||||
Dir3::new_unchecked(ground.up()), // Up vector is already normalized.
|
Dir3::new_unchecked(ground.up()), // Up vector is already normalized.
|
||||||
0.2,
|
0.2,
|
||||||
LegacyColor::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ fn setup(
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(20., 20.)),
|
mesh: meshes.add(Plane3d::default().mesh().size(20., 20.)),
|
||||||
material: materials.add(LegacyColor::rgb(0.3, 0.5, 0.3)),
|
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Ground,
|
Ground,
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn setup(
|
||||||
for z in -1..2 {
|
for z in -1..2 {
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: cube.clone(),
|
mesh: cube.clone(),
|
||||||
material: materials.add(LegacyColor::WHITE),
|
material: materials.add(Color::WHITE),
|
||||||
transform: Transform::from_translation(Vec3::new(x as f32, 0.0, z as f32)),
|
transform: Transform::from_translation(Vec3::new(x as f32, 0.0, z as f32)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -49,12 +49,11 @@ fn animate_materials(
|
||||||
) {
|
) {
|
||||||
for (i, material_handle) in material_handles.iter().enumerate() {
|
for (i, material_handle) in material_handles.iter().enumerate() {
|
||||||
if let Some(material) = materials.get_mut(material_handle) {
|
if let Some(material) = materials.get_mut(material_handle) {
|
||||||
let color = LegacyColor::hsl(
|
material.base_color = Color::hsl(
|
||||||
((i as f32 * 2.345 + time.elapsed_seconds_wrapped()) * 100.0) % 360.0,
|
((i as f32 * 2.345 + time.elapsed_seconds_wrapped()) * 100.0) % 360.0,
|
||||||
1.0,
|
1.0,
|
||||||
0.5,
|
0.5,
|
||||||
);
|
);
|
||||||
material.base_color = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ fn setup(
|
||||||
// Plane
|
// Plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.1, 0.2, 0.1)),
|
material: materials.add(Color::srgb(0.1, 0.2, 0.1)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ fn setup(
|
||||||
intensity: 150.0,
|
intensity: 150.0,
|
||||||
},
|
},
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba_u8(43, 44, 47, 255),
|
color: Color::srgba_u8(43, 44, 47, 255),
|
||||||
falloff: FogFalloff::Linear {
|
falloff: FogFalloff::Linear {
|
||||||
start: 1.0,
|
start: 1.0,
|
||||||
end: 4.0,
|
end: 4.0,
|
||||||
|
|
|
@ -31,13 +31,13 @@ fn setup_camera_fog(mut commands: Commands) {
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba(0.35, 0.48, 0.66, 1.0),
|
color: Color::srgba(0.35, 0.48, 0.66, 1.0),
|
||||||
directional_light_color: LegacyColor::rgba(1.0, 0.95, 0.85, 0.5),
|
directional_light_color: Color::srgba(1.0, 0.95, 0.85, 0.5),
|
||||||
directional_light_exponent: 30.0,
|
directional_light_exponent: 30.0,
|
||||||
falloff: FogFalloff::from_visibility_colors(
|
falloff: FogFalloff::from_visibility_colors(
|
||||||
15.0, // distance in world units up to which objects retain visibility (>= 5% contrast)
|
15.0, // distance in world units up to which objects retain visibility (>= 5% contrast)
|
||||||
LegacyColor::rgb(0.35, 0.5, 0.66), // atmospheric extinction color (after light is lost due to absorption by atmospheric particles)
|
Color::srgb(0.35, 0.5, 0.66), // atmospheric extinction color (after light is lost due to absorption by atmospheric particles)
|
||||||
LegacyColor::rgb(0.8, 0.844, 1.0), // atmospheric inscattering color (light gained due to scattering from the sun)
|
Color::srgb(0.8, 0.844, 1.0), // atmospheric inscattering color (light gained due to scattering from the sun)
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -60,7 +60,7 @@ fn setup_terrain_scene(
|
||||||
// Sun
|
// Sun
|
||||||
commands.spawn(DirectionalLightBundle {
|
commands.spawn(DirectionalLightBundle {
|
||||||
directional_light: DirectionalLight {
|
directional_light: DirectionalLight {
|
||||||
color: LegacyColor::rgb(0.98, 0.95, 0.82),
|
color: Color::srgb(0.98, 0.95, 0.82),
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -81,7 +81,7 @@ fn setup_terrain_scene(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("888888").unwrap(),
|
base_color: Srgba::hex("888888").unwrap().into(),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
cull_mode: None,
|
cull_mode: None,
|
||||||
..default()
|
..default()
|
||||||
|
@ -115,12 +115,12 @@ fn toggle_system(keycode: Res<ButtonInput<KeyCode>>, mut fog: Query<&mut FogSett
|
||||||
let mut fog_settings = fog.single_mut();
|
let mut fog_settings = fog.single_mut();
|
||||||
|
|
||||||
if keycode.just_pressed(KeyCode::Space) {
|
if keycode.just_pressed(KeyCode::Space) {
|
||||||
let a = fog_settings.color.a();
|
let a = fog_settings.color.alpha();
|
||||||
fog_settings.color.set_a(1.0 - a);
|
fog_settings.color.set_alpha(1.0 - a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.just_pressed(KeyCode::KeyS) {
|
if keycode.just_pressed(KeyCode::KeyS) {
|
||||||
let a = fog_settings.directional_light_color.a();
|
let a = fog_settings.directional_light_color.alpha();
|
||||||
fog_settings.directional_light_color.set_a(0.5 - a);
|
fog_settings.directional_light_color.set_alpha(0.5 - a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
//! | `Spacebar` | Toggle Unlit |
|
//! | `Spacebar` | Toggle Unlit |
|
||||||
//! | `C` | Randomize Colors |
|
//! | `C` | Randomize Colors |
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::{color::palettes::css::ORANGE, prelude::*};
|
||||||
use rand::random;
|
use rand::random;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -36,7 +36,7 @@ fn setup(
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
let base_color = LegacyColor::rgba(0.9, 0.2, 0.3, 1.0);
|
let base_color = Color::srgb(0.9, 0.2, 0.3);
|
||||||
let icosphere_mesh = meshes.add(Sphere::new(0.9).mesh().ico(7).unwrap());
|
let icosphere_mesh = meshes.add(Sphere::new(0.9).mesh().ico(7).unwrap());
|
||||||
|
|
||||||
// Opaque
|
// Opaque
|
||||||
|
@ -140,8 +140,8 @@ fn setup(
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
// Chessboard Plane
|
// Chessboard Plane
|
||||||
let black_material = materials.add(LegacyColor::BLACK);
|
let black_material = materials.add(Color::BLACK);
|
||||||
let white_material = materials.add(LegacyColor::WHITE);
|
let white_material = materials.add(Color::WHITE);
|
||||||
|
|
||||||
let plane_mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
|
let plane_mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ fn setup(
|
||||||
let label_text_style = TextStyle {
|
let label_text_style = TextStyle {
|
||||||
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
||||||
font_size: 25.0,
|
font_size: 25.0,
|
||||||
color: LegacyColor::ORANGE,
|
color: ORANGE.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn(
|
commands.spawn(
|
||||||
|
@ -300,13 +300,19 @@ fn example_control_system(
|
||||||
|
|
||||||
for (material_handle, controls) in &controllable {
|
for (material_handle, controls) in &controllable {
|
||||||
let material = materials.get_mut(material_handle).unwrap();
|
let material = materials.get_mut(material_handle).unwrap();
|
||||||
material.base_color.set_a(state.alpha);
|
|
||||||
|
|
||||||
if controls.color && randomize_colors {
|
if controls.color && randomize_colors {
|
||||||
material.base_color.set_r(random());
|
material.base_color = Srgba {
|
||||||
material.base_color.set_g(random());
|
red: random(),
|
||||||
material.base_color.set_b(random());
|
green: random(),
|
||||||
|
blue: random(),
|
||||||
|
alpha: state.alpha,
|
||||||
|
}
|
||||||
|
.into();
|
||||||
|
} else {
|
||||||
|
material.base_color.set_alpha(state.alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if controls.unlit {
|
if controls.unlit {
|
||||||
material.unlit = state.unlit;
|
material.unlit = state.unlit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Illustrates bloom post-processing using HDR and emissive materials.
|
//! Illustrates bloom post-processing using HDR and emissive materials.
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::basic::GRAY,
|
||||||
core_pipeline::{
|
core_pipeline::{
|
||||||
bloom::{BloomCompositeMode, BloomSettings},
|
bloom::{BloomCompositeMode, BloomSettings},
|
||||||
tonemapping::Tonemapping,
|
tonemapping::Tonemapping,
|
||||||
|
@ -39,19 +40,19 @@ fn setup_scene(
|
||||||
));
|
));
|
||||||
|
|
||||||
let material_emissive1 = materials.add(StandardMaterial {
|
let material_emissive1 = materials.add(StandardMaterial {
|
||||||
emissive: LegacyColor::rgb_linear(2300.0, 900.0, 300.0), // 4. Put something bright in a dark environment to see the effect
|
emissive: Color::linear_rgb(2300.0, 900.0, 300.0), // 4. Put something bright in a dark environment to see the effect
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let material_emissive2 = materials.add(StandardMaterial {
|
let material_emissive2 = materials.add(StandardMaterial {
|
||||||
emissive: LegacyColor::rgb_linear(300.0, 2300.0, 900.0),
|
emissive: Color::linear_rgb(300.0, 2300.0, 900.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let material_emissive3 = materials.add(StandardMaterial {
|
let material_emissive3 = materials.add(StandardMaterial {
|
||||||
emissive: LegacyColor::rgb_linear(900.0, 300.0, 2300.0),
|
emissive: Color::linear_rgb(900.0, 300.0, 2300.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let material_non_emissive = materials.add(StandardMaterial {
|
let material_non_emissive = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::GRAY,
|
base_color: GRAY.into(),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ fn setup_scene(
|
||||||
"",
|
"",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font_size: 20.0,
|
font_size: 20.0,
|
||||||
color: LegacyColor::BLACK,
|
color: Color::BLACK,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba_u8(43, 44, 47, 255),
|
color: Color::srgb_u8(43, 44, 47),
|
||||||
falloff: FogFalloff::Linear {
|
falloff: FogFalloff::Linear {
|
||||||
start: 1.0,
|
start: 1.0,
|
||||||
end: 8.0,
|
end: 8.0,
|
||||||
|
@ -95,7 +95,7 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut forward_mat: StandardMaterial = LegacyColor::rgb(0.1, 0.2, 0.1).into();
|
let mut forward_mat: StandardMaterial = Color::srgb(0.1, 0.2, 0.1).into();
|
||||||
forward_mat.opaque_render_method = OpaqueRendererMethod::Forward;
|
forward_mat.opaque_render_method = OpaqueRendererMethod::Forward;
|
||||||
let forward_mat_h = materials.add(forward_mat);
|
let forward_mat_h = materials.add(forward_mat);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let sphere_color = LegacyColor::rgb(10.0, 4.0, 1.0);
|
let sphere_color = Color::srgb(10.0, 4.0, 1.0);
|
||||||
let sphere_pos = Transform::from_xyz(0.4, 0.5, -0.8);
|
let sphere_pos = Transform::from_xyz(0.4, 0.5, -0.8);
|
||||||
// Emissive sphere
|
// Emissive sphere
|
||||||
let mut unlit_mat: StandardMaterial = sphere_color.into();
|
let mut unlit_mat: StandardMaterial = sphere_color.into();
|
||||||
|
@ -156,21 +156,21 @@ fn setup(
|
||||||
let s_val = if i < 3 { 0.0 } else { 0.2 };
|
let s_val = if i < 3 { 0.0 } else { 0.2 };
|
||||||
let material = if j == 0 {
|
let material = if j == 0 {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(s_val, s_val, 1.0),
|
base_color: Color::srgb(s_val, s_val, 1.0),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
} else if j == 1 {
|
} else if j == 1 {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(s_val, 1.0, s_val),
|
base_color: Color::srgb(s_val, 1.0, s_val),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(1.0, s_val, s_val),
|
base_color: Color::srgb(1.0, s_val, s_val),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
|
@ -193,7 +193,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("888888").unwrap(),
|
base_color: Srgba::hex("888888").unwrap().into(),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
cull_mode: None,
|
cull_mode: None,
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -40,7 +40,7 @@ fn setup(
|
||||||
let mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
|
let mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
|
||||||
let nb_plane = 10;
|
let nb_plane = 10;
|
||||||
for i in 0..nb_plane {
|
for i in 0..nb_plane {
|
||||||
let color = LegacyColor::hsl(i as f32 * 360.0 / nb_plane as f32, 1.0, 0.5);
|
let color = Color::hsl(i as f32 * 360.0 / nb_plane as f32, 1.0, 0.5);
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: mesh.clone(),
|
mesh: mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
|
|
|
@ -35,7 +35,7 @@ fn setup_camera_fog(mut commands: Commands) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Camera3dBundle::default(),
|
Camera3dBundle::default(),
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba(0.25, 0.25, 0.25, 1.0),
|
color: Color::srgb(0.25, 0.25, 0.25),
|
||||||
falloff: FogFalloff::Linear {
|
falloff: FogFalloff::Linear {
|
||||||
start: 5.0,
|
start: 5.0,
|
||||||
end: 20.0,
|
end: 20.0,
|
||||||
|
@ -51,7 +51,7 @@ fn setup_pyramid_scene(
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let stone = materials.add(StandardMaterial {
|
let stone = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("28221B").unwrap(),
|
base_color: Srgba::hex("28221B").unwrap().into(),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -71,7 +71,7 @@ fn setup_pyramid_scene(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::default()),
|
mesh: meshes.add(Sphere::default()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("126212CC").unwrap(),
|
base_color: Srgba::hex("126212CC").unwrap().into(),
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
perceptual_roughness: 0.0,
|
perceptual_roughness: 0.0,
|
||||||
metallic: 0.5,
|
metallic: 0.5,
|
||||||
|
@ -102,7 +102,7 @@ fn setup_pyramid_scene(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("888888").unwrap(),
|
base_color: Srgba::hex("888888").unwrap().into(),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
cull_mode: None,
|
cull_mode: None,
|
||||||
..default()
|
..default()
|
||||||
|
@ -259,43 +259,41 @@ fn update_system(
|
||||||
.value
|
.value
|
||||||
.push_str("\n\n- / = - Red\n[ / ] - Green\n; / ' - Blue\n. / ? - Alpha");
|
.push_str("\n\n- / = - Red\n[ / ] - Green\n; / ' - Blue\n. / ? - Alpha");
|
||||||
|
|
||||||
|
// We're performing various operations in the sRGB color space,
|
||||||
|
// so we convert the fog color to sRGB here, then modify it,
|
||||||
|
// and finally when we're done we can convert it back and set it.
|
||||||
|
let mut fog_color = Srgba::from(fog.color);
|
||||||
if keycode.pressed(KeyCode::Minus) {
|
if keycode.pressed(KeyCode::Minus) {
|
||||||
let r = (fog.color.r() - 0.1 * delta).max(0.0);
|
fog_color.red = (fog_color.red - 0.1 * delta).max(0.0);
|
||||||
fog.color.set_r(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.any_pressed([KeyCode::Equal, KeyCode::NumpadEqual]) {
|
if keycode.any_pressed([KeyCode::Equal, KeyCode::NumpadEqual]) {
|
||||||
let r = (fog.color.r() + 0.1 * delta).min(1.0);
|
fog_color.red = (fog_color.red + 0.1 * delta).min(1.0);
|
||||||
fog.color.set_r(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::BracketLeft) {
|
if keycode.pressed(KeyCode::BracketLeft) {
|
||||||
let g = (fog.color.g() - 0.1 * delta).max(0.0);
|
fog_color.green = (fog_color.green - 0.1 * delta).max(0.0);
|
||||||
fog.color.set_g(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::BracketRight) {
|
if keycode.pressed(KeyCode::BracketRight) {
|
||||||
let g = (fog.color.g() + 0.1 * delta).min(1.0);
|
fog_color.green = (fog_color.green + 0.1 * delta).min(1.0);
|
||||||
fog.color.set_g(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::Semicolon) {
|
if keycode.pressed(KeyCode::Semicolon) {
|
||||||
let b = (fog.color.b() - 0.1 * delta).max(0.0);
|
fog_color.blue = (fog_color.blue - 0.1 * delta).max(0.0);
|
||||||
fog.color.set_b(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::Quote) {
|
if keycode.pressed(KeyCode::Quote) {
|
||||||
let b = (fog.color.b() + 0.1 * delta).min(1.0);
|
fog_color.blue = (fog_color.blue + 0.1 * delta).min(1.0);
|
||||||
fog.color.set_b(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::Period) {
|
if keycode.pressed(KeyCode::Period) {
|
||||||
let a = (fog.color.a() - 0.1 * delta).max(0.0);
|
fog_color.alpha = (fog_color.alpha - 0.1 * delta).max(0.0);
|
||||||
fog.color.set_a(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if keycode.pressed(KeyCode::Slash) {
|
if keycode.pressed(KeyCode::Slash) {
|
||||||
let a = (fog.color.a() + 0.1 * delta).min(1.0);
|
fog_color.alpha = (fog_color.alpha + 0.1 * delta).min(1.0);
|
||||||
fog.color.set_a(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fog.color = Color::from(fog_color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
//!
|
//!
|
||||||
//! * Clicking anywhere moves the object.
|
//! * Clicking anywhere moves the object.
|
||||||
|
|
||||||
|
use bevy::color::palettes::css::*;
|
||||||
use bevy::core_pipeline::Skybox;
|
use bevy::core_pipeline::Skybox;
|
||||||
use bevy::math::{uvec3, vec3};
|
use bevy::math::{uvec3, vec3};
|
||||||
use bevy::pbr::irradiance_volume::IrradianceVolume;
|
use bevy::pbr::irradiance_volume::IrradianceVolume;
|
||||||
|
@ -47,7 +48,7 @@ static SWITCH_TO_SPHERE_HELP_TEXT: &str = "Tab: Switch to a plain sphere mesh";
|
||||||
|
|
||||||
static CLICK_TO_MOVE_HELP_TEXT: &str = "Left click: Move the object";
|
static CLICK_TO_MOVE_HELP_TEXT: &str = "Left click: Move the object";
|
||||||
|
|
||||||
static GIZMO_COLOR: LegacyColor = LegacyColor::YELLOW;
|
static GIZMO_COLOR: Color = Color::Srgba(YELLOW);
|
||||||
|
|
||||||
static VOXEL_TRANSFORM: Mat4 = Mat4::from_cols_array_2d(&[
|
static VOXEL_TRANSFORM: Mat4 = Mat4::from_cols_array_2d(&[
|
||||||
[-42.317566, 0.0, 0.0, 0.0],
|
[-42.317566, 0.0, 0.0, 0.0],
|
||||||
|
@ -148,7 +149,7 @@ fn main() {
|
||||||
.init_resource::<AppStatus>()
|
.init_resource::<AppStatus>()
|
||||||
.init_resource::<ExampleAssets>()
|
.init_resource::<ExampleAssets>()
|
||||||
.insert_resource(AmbientLight {
|
.insert_resource(AmbientLight {
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 0.0,
|
brightness: 0.0,
|
||||||
})
|
})
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
|
@ -362,7 +363,7 @@ impl AppStatus {
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
||||||
font_size: 24.0,
|
font_size: 24.0,
|
||||||
color: LegacyColor::ANTIQUE_WHITE,
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -515,7 +516,7 @@ impl FromWorld for ExampleAssets {
|
||||||
ExampleAssets {
|
ExampleAssets {
|
||||||
main_sphere: world.add_asset(Sphere::default().mesh().uv(32, 18)),
|
main_sphere: world.add_asset(Sphere::default().mesh().uv(32, 18)),
|
||||||
fox: world.load_asset("models/animated/Fox.glb#Scene0"),
|
fox: world.load_asset("models/animated/Fox.glb#Scene0"),
|
||||||
main_sphere_material: world.add_asset(LegacyColor::SILVER),
|
main_sphere_material: world.add_asset(Color::from(SILVER)),
|
||||||
main_scene: world
|
main_scene: world
|
||||||
.load_asset("models/IrradianceVolumeExample/IrradianceVolumeExample.glb#Scene0"),
|
.load_asset("models/IrradianceVolumeExample/IrradianceVolumeExample.glb#Scene0"),
|
||||||
irradiance_volume: world.load_asset("irradiance_volumes/Example.vxgi.ktx2"),
|
irradiance_volume: world.load_asset("irradiance_volumes/Example.vxgi.ktx2"),
|
||||||
|
@ -563,7 +564,7 @@ fn create_cubes(
|
||||||
let resolution = image.texture_descriptor.size;
|
let resolution = image.texture_descriptor.size;
|
||||||
|
|
||||||
let voxel_cube_material = voxel_visualization_material_assets.add(ExtendedMaterial {
|
let voxel_cube_material = voxel_visualization_material_assets.add(ExtendedMaterial {
|
||||||
base: StandardMaterial::from(LegacyColor::RED),
|
base: StandardMaterial::from(Color::from(RED)),
|
||||||
extension: VoxelVisualizationExtension {
|
extension: VoxelVisualizationExtension {
|
||||||
irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo {
|
irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo {
|
||||||
transform: VOXEL_TRANSFORM.inverse(),
|
transform: VOXEL_TRANSFORM.inverse(),
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::css::*,
|
||||||
pbr::{light_consts, CascadeShadowConfigBuilder},
|
pbr::{light_consts, CascadeShadowConfigBuilder},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::camera::{Exposure, PhysicalCameraParameters},
|
render::camera::{Exposure, PhysicalCameraParameters},
|
||||||
|
@ -40,7 +41,7 @@ fn setup(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(10.0, 10.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(10.0, 10.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -54,7 +55,7 @@ fn setup(
|
||||||
mesh: meshes.add(Cuboid::new(5.0, 0.15, 5.0)),
|
mesh: meshes.add(Cuboid::new(5.0, 0.15, 5.0)),
|
||||||
transform,
|
transform,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::INDIGO,
|
base_color: INDIGO.into(),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -67,7 +68,7 @@ fn setup(
|
||||||
mesh: meshes.add(Cuboid::new(5.0, 0.15, 5.0)),
|
mesh: meshes.add(Cuboid::new(5.0, 0.15, 5.0)),
|
||||||
transform,
|
transform,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::INDIGO,
|
base_color: INDIGO.into(),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -98,7 +99,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::PINK,
|
base_color: PINK.into(),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
|
@ -111,7 +112,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.5).mesh().uv(32, 18)),
|
mesh: meshes.add(Sphere::new(0.5).mesh().uv(32, 18)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::LIME_GREEN,
|
base_color: LIMEGREEN.into(),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(1.5, 1.0, 1.5),
|
transform: Transform::from_xyz(1.5, 1.0, 1.5),
|
||||||
|
@ -122,7 +123,7 @@ fn setup(
|
||||||
|
|
||||||
// ambient light
|
// ambient light
|
||||||
commands.insert_resource(AmbientLight {
|
commands.insert_resource(AmbientLight {
|
||||||
color: LegacyColor::ORANGE_RED,
|
color: ORANGE_RED.into(),
|
||||||
brightness: 0.02,
|
brightness: 0.02,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ fn setup(
|
||||||
transform: Transform::from_xyz(1.0, 2.0, 0.0),
|
transform: Transform::from_xyz(1.0, 2.0, 0.0),
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
intensity: 100_000.0,
|
intensity: 100_000.0,
|
||||||
color: LegacyColor::RED,
|
color: RED.into(),
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -143,8 +144,8 @@ fn setup(
|
||||||
builder.spawn(PbrBundle {
|
builder.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)),
|
mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::RED,
|
base_color: RED.into(),
|
||||||
emissive: LegacyColor::rgba_linear(7.13, 0.0, 0.0, 0.0),
|
emissive: Color::linear_rgba(7.13, 0.0, 0.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
|
@ -158,7 +159,7 @@ fn setup(
|
||||||
.looking_at(Vec3::new(-1.0, 0.0, 0.0), Vec3::Z),
|
.looking_at(Vec3::new(-1.0, 0.0, 0.0), Vec3::Z),
|
||||||
spot_light: SpotLight {
|
spot_light: SpotLight {
|
||||||
intensity: 100_000.0,
|
intensity: 100_000.0,
|
||||||
color: LegacyColor::GREEN,
|
color: GREEN.into(),
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
inner_angle: 0.6,
|
inner_angle: 0.6,
|
||||||
outer_angle: 0.8,
|
outer_angle: 0.8,
|
||||||
|
@ -171,8 +172,8 @@ fn setup(
|
||||||
transform: Transform::from_rotation(Quat::from_rotation_x(PI / 2.0)),
|
transform: Transform::from_rotation(Quat::from_rotation_x(PI / 2.0)),
|
||||||
mesh: meshes.add(Capsule3d::new(0.1, 0.125)),
|
mesh: meshes.add(Capsule3d::new(0.1, 0.125)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::GREEN,
|
base_color: GREEN.into(),
|
||||||
emissive: LegacyColor::rgba_linear(0.0, 7.13, 0.0, 0.0),
|
emissive: Color::linear_rgba(0.0, 7.13, 0.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
|
@ -186,7 +187,7 @@ fn setup(
|
||||||
transform: Transform::from_xyz(0.0, 4.0, 0.0),
|
transform: Transform::from_xyz(0.0, 4.0, 0.0),
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
intensity: 100_000.0,
|
intensity: 100_000.0,
|
||||||
color: LegacyColor::BLUE,
|
color: BLUE.into(),
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -196,8 +197,8 @@ fn setup(
|
||||||
builder.spawn(PbrBundle {
|
builder.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)),
|
mesh: meshes.add(Sphere::new(0.1).mesh().uv(32, 18)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::BLUE,
|
base_color: BLUE.into(),
|
||||||
emissive: LegacyColor::rgba_linear(0.0, 0.0, 7.13, 0.0),
|
emissive: Color::linear_rgba(0.0, 0.0, 7.13, 0.0),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -36,7 +36,8 @@ fn add_lightmaps_to_meshes(
|
||||||
let exposure = 250.0;
|
let exposure = 250.0;
|
||||||
for (entity, name, material) in meshes.iter() {
|
for (entity, name, material) in meshes.iter() {
|
||||||
if &**name == "Light" {
|
if &**name == "Light" {
|
||||||
materials.get_mut(material).unwrap().emissive = LegacyColor::WHITE * exposure;
|
materials.get_mut(material).unwrap().emissive =
|
||||||
|
Color::LinearRgba(LinearRgba::WHITE * exposure);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn setup(
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(-1.5, 0.0, 0.0),
|
transform: Transform::from_xyz(-1.5, 0.0, 0.0),
|
||||||
material: materials.add(LineMaterial {
|
material: materials.add(LineMaterial {
|
||||||
color: LegacyColor::GREEN,
|
color: LinearRgba::GREEN,
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ fn setup(
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(0.5, 0.0, 0.0),
|
transform: Transform::from_xyz(0.5, 0.0, 0.0),
|
||||||
material: materials.add(LineMaterial {
|
material: materials.add(LineMaterial {
|
||||||
color: LegacyColor::BLUE,
|
color: LinearRgba::BLUE,
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -67,7 +67,7 @@ fn setup(
|
||||||
#[derive(Asset, TypePath, Default, AsBindGroup, Debug, Clone)]
|
#[derive(Asset, TypePath, Default, AsBindGroup, Debug, Clone)]
|
||||||
struct LineMaterial {
|
struct LineMaterial {
|
||||||
#[uniform(0)]
|
#[uniform(0)]
|
||||||
color: LegacyColor,
|
color: LinearRgba,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material for LineMaterial {
|
impl Material for LineMaterial {
|
||||||
|
|
|
@ -30,31 +30,31 @@ fn setup(
|
||||||
// plane
|
// plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.3, 0.5, 0.3)),
|
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cubes
|
// cubes
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(1.5, 0.5, 1.5),
|
transform: Transform::from_xyz(1.5, 0.5, 1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(1.5, 0.5, -1.5),
|
transform: Transform::from_xyz(1.5, 0.5, -1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(-1.5, 0.5, 1.5),
|
transform: Transform::from_xyz(-1.5, 0.5, 1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(-1.5, 0.5, -1.5),
|
transform: Transform::from_xyz(-1.5, 0.5, -1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
|
@ -243,7 +243,7 @@ fn setup(
|
||||||
// with roughness and reflectance set.
|
// with roughness and reflectance set.
|
||||||
perceptual_roughness: 0.45,
|
perceptual_roughness: 0.45,
|
||||||
reflectance: 0.18,
|
reflectance: 0.18,
|
||||||
..LegacyColor::rgb_u8(0, 80, 0).into()
|
..Color::srgb_u8(0, 80, 0).into()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(0.0, -1.0, 0.0),
|
transform: Transform::from_xyz(0.0, -1.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn setup(
|
||||||
) {
|
) {
|
||||||
let cube_handle = meshes.add(Cuboid::new(2.0, 2.0, 2.0));
|
let cube_handle = meshes.add(Cuboid::new(2.0, 2.0, 2.0));
|
||||||
let cube_material_handle = materials.add(StandardMaterial {
|
let cube_material_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.8, 0.7, 0.6),
|
base_color: Color::srgb(0.8, 0.7, 0.6),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn setup(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: sphere_mesh.clone(),
|
mesh: sphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("#ffd891").unwrap(),
|
base_color: Srgba::hex("#ffd891").unwrap().into(),
|
||||||
// vary key PBR parameters on a grid of spheres to show the effect
|
// vary key PBR parameters on a grid of spheres to show the effect
|
||||||
metallic: y01,
|
metallic: y01,
|
||||||
perceptual_roughness: x01,
|
perceptual_roughness: x01,
|
||||||
|
@ -42,7 +42,7 @@ fn setup(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: sphere_mesh,
|
mesh: sphere_mesh,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("#ffd891").unwrap(),
|
base_color: Srgba::hex("#ffd891").unwrap().into(),
|
||||||
// vary key PBR parameters on a grid of spheres to show the effect
|
// vary key PBR parameters on a grid of spheres to show the effect
|
||||||
unlit: true,
|
unlit: true,
|
||||||
..default()
|
..default()
|
||||||
|
@ -103,7 +103,7 @@ fn setup(
|
||||||
"Loading Environment Map...",
|
"Loading Environment Map...",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font_size: 36.0,
|
font_size: 36.0,
|
||||||
color: LegacyColor::RED,
|
color: Color::WHITE,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -128,7 +128,7 @@ fn spawn_sphere(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: sphere_mesh.clone(),
|
mesh: sphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::hex("#ffd891").unwrap(),
|
base_color: Srgba::hex("#ffd891").unwrap().into(),
|
||||||
metallic: 1.0,
|
metallic: 1.0,
|
||||||
perceptual_roughness: 0.0,
|
perceptual_roughness: 0.0,
|
||||||
..StandardMaterial::default()
|
..StandardMaterial::default()
|
||||||
|
@ -293,7 +293,7 @@ impl AppStatus {
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
||||||
font_size: 24.0,
|
font_size: 24.0,
|
||||||
color: LegacyColor::ANTIQUE_WHITE,
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ fn setup(
|
||||||
|
|
||||||
let cube_handle = meshes.add(Cuboid::new(4.0, 4.0, 4.0));
|
let cube_handle = meshes.add(Cuboid::new(4.0, 4.0, 4.0));
|
||||||
let cube_material_handle = materials.add(StandardMaterial {
|
let cube_material_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.8, 0.7, 0.6),
|
base_color: Color::srgb(0.8, 0.7, 0.6),
|
||||||
reflectance: 0.02,
|
reflectance: 0.02,
|
||||||
unlit: false,
|
unlit: false,
|
||||||
..default()
|
..default()
|
||||||
|
@ -103,7 +103,7 @@ fn setup(
|
||||||
// render before the "main pass" camera
|
// render before the "main pass" camera
|
||||||
order: -1,
|
order: -1,
|
||||||
target: image_handle.clone().into(),
|
target: image_handle.clone().into(),
|
||||||
clear_color: LegacyColor::WHITE.into(),
|
clear_color: Color::WHITE.into(),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
|
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn setup(
|
||||||
let sphere_radius = 0.25;
|
let sphere_radius = 0.25;
|
||||||
|
|
||||||
let white_handle = materials.add(StandardMaterial {
|
let white_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,7 @@ fn setup(
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
intensity: 0.0,
|
intensity: 0.0,
|
||||||
range: spawn_plane_depth,
|
range: spawn_plane_depth,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
shadow_depth_bias: 0.0,
|
shadow_depth_bias: 0.0,
|
||||||
shadow_normal_bias: 0.0,
|
shadow_normal_bias: 0.0,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
|
@ -125,7 +125,7 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
z_index: ZIndex::Global(i32::MAX),
|
z_index: ZIndex::Global(i32::MAX),
|
||||||
background_color: LegacyColor::BLACK.with_a(0.75).into(),
|
background_color: Color::BLACK.with_alpha(0.75).into(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|c| {
|
.with_children(|c| {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::basic::{BLUE, GREEN, RED},
|
||||||
pbr::{light_consts, CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver},
|
pbr::{light_consts, CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
@ -32,7 +33,7 @@ fn setup(
|
||||||
let sphere_radius = 0.25;
|
let sphere_radius = 0.25;
|
||||||
|
|
||||||
let white_handle = materials.add(StandardMaterial {
|
let white_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -41,7 +42,7 @@ fn setup(
|
||||||
// sphere - initially a caster
|
// sphere - initially a caster
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: sphere_handle.clone(),
|
mesh: sphere_handle.clone(),
|
||||||
material: materials.add(LegacyColor::RED),
|
material: materials.add(Color::from(RED)),
|
||||||
transform: Transform::from_xyz(-1.0, spawn_height, 0.0),
|
transform: Transform::from_xyz(-1.0, spawn_height, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -50,7 +51,7 @@ fn setup(
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: sphere_handle,
|
mesh: sphere_handle,
|
||||||
material: materials.add(LegacyColor::BLUE),
|
material: materials.add(Color::from(BLUE)),
|
||||||
transform: Transform::from_xyz(1.0, spawn_height, 0.0),
|
transform: Transform::from_xyz(1.0, spawn_height, 0.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -61,7 +62,7 @@ fn setup(
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(20.0, 20.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(20.0, 20.0)),
|
||||||
material: materials.add(LegacyColor::GREEN),
|
material: materials.add(Color::from(GREEN)),
|
||||||
transform: Transform::from_xyz(0.0, 1.0, -10.0),
|
transform: Transform::from_xyz(0.0, 1.0, -10.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -83,7 +84,7 @@ fn setup(
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
intensity: 0.0,
|
intensity: 0.0,
|
||||||
range: spawn_plane_depth,
|
range: spawn_plane_depth,
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
// NOTE: The ambient light is used to scale how bright the environment map is so with a bright
|
// NOTE: The ambient light is used to scale how bright the environment map is so with a bright
|
||||||
// environment map, use an appropriate color and brightness to match
|
// environment map, use an appropriate color and brightness to match
|
||||||
commands.insert_resource(AmbientLight {
|
commands.insert_resource(AmbientLight {
|
||||||
color: LegacyColor::rgb_u8(210, 220, 240),
|
color: Color::srgb_u8(210, 220, 240),
|
||||||
brightness: 1.0,
|
brightness: 1.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ fn setup(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.2, 0.2, 0.2),
|
base_color: Color::srgb(0.2, 0.2, 0.2),
|
||||||
perceptual_roughness: 0.08,
|
perceptual_roughness: 0.08,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -51,7 +51,7 @@ fn setup(
|
||||||
.spawn(PbrBundle {
|
.spawn(PbrBundle {
|
||||||
mesh: mesh.clone(),
|
mesh: mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.5, 0.5, 1.0),
|
base_color: Color::srgb(0.5, 0.5, 1.0),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -63,7 +63,7 @@ fn setup(
|
||||||
children.spawn(PointLightBundle {
|
children.spawn(PointLightBundle {
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
radius,
|
radius,
|
||||||
color: LegacyColor::rgb(0.2, 0.2, 1.0),
|
color: Color::srgb(0.2, 0.2, 1.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
pbr::CascadeShadowConfigBuilder, prelude::*, render::camera::Viewport, window::WindowResized,
|
color::palettes::css::DARK_GRAY, pbr::CascadeShadowConfigBuilder, prelude::*,
|
||||||
|
render::camera::Viewport, window::WindowResized,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -24,7 +25,7 @@ fn setup(
|
||||||
// plane
|
// plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.3, 0.5, 0.3)),
|
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -145,8 +146,8 @@ fn setup(
|
||||||
align_items: AlignItems::Center,
|
align_items: AlignItems::Center,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
border_color: LegacyColor::WHITE.into(),
|
border_color: Color::WHITE.into(),
|
||||||
background_color: LegacyColor::DARK_GRAY.into(),
|
background_color: DARK_GRAY.into(),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
use std::f32::consts::*;
|
use std::f32::consts::*;
|
||||||
|
|
||||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
use bevy::{
|
||||||
|
color::palettes::basic::{MAROON, RED},
|
||||||
|
pbr::NotShadowCaster,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use rand::{rngs::StdRng, Rng, SeedableRng};
|
use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||||
|
|
||||||
const INSTRUCTIONS: &str = "\
|
const INSTRUCTIONS: &str = "\
|
||||||
|
@ -37,7 +41,7 @@ fn setup(
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)),
|
||||||
material: materials.add(LegacyColor::WHITE),
|
material: materials.add(Color::WHITE),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Movable,
|
Movable,
|
||||||
|
@ -46,7 +50,7 @@ fn setup(
|
||||||
// cubes
|
// cubes
|
||||||
let mut rng = StdRng::seed_from_u64(19878367467713);
|
let mut rng = StdRng::seed_from_u64(19878367467713);
|
||||||
let cube_mesh = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
|
let cube_mesh = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
|
||||||
let blue = materials.add(LegacyColor::rgb_u8(124, 144, 255));
|
let blue = materials.add(Color::srgb_u8(124, 144, 255));
|
||||||
|
|
||||||
commands.spawn_batch(
|
commands.spawn_batch(
|
||||||
std::iter::repeat_with(move || {
|
std::iter::repeat_with(move || {
|
||||||
|
@ -70,13 +74,13 @@ fn setup(
|
||||||
let sphere_mesh = meshes.add(Sphere::new(0.05).mesh().uv(32, 18));
|
let sphere_mesh = meshes.add(Sphere::new(0.05).mesh().uv(32, 18));
|
||||||
let sphere_mesh_direction = meshes.add(Sphere::new(0.1).mesh().uv(32, 18));
|
let sphere_mesh_direction = meshes.add(Sphere::new(0.1).mesh().uv(32, 18));
|
||||||
let red_emissive = materials.add(StandardMaterial {
|
let red_emissive = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::RED,
|
base_color: RED.into(),
|
||||||
emissive: LegacyColor::rgba_linear(100.0, 0.0, 0.0, 0.0),
|
emissive: Color::linear_rgba(100.0, 0.0, 0.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let maroon_emissive = materials.add(StandardMaterial {
|
let maroon_emissive = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::MAROON,
|
base_color: MAROON.into(),
|
||||||
emissive: LegacyColor::rgba_linear(50.0, 0.0, 0.0, 0.0),
|
emissive: Color::linear_rgba(50.0, 0.0, 0.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,7 +95,7 @@ fn setup(
|
||||||
.looking_at(Vec3::new(1.0 + x, 0.0, z), Vec3::X),
|
.looking_at(Vec3::new(1.0 + x, 0.0, z), Vec3::X),
|
||||||
spot_light: SpotLight {
|
spot_light: SpotLight {
|
||||||
intensity: 40_000.0, // lumens
|
intensity: 40_000.0, // lumens
|
||||||
color: LegacyColor::WHITE,
|
color: Color::WHITE,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
inner_angle: PI / 4.0 * 0.85,
|
inner_angle: PI / 4.0 * 0.85,
|
||||||
outer_angle: PI / 4.0,
|
outer_angle: PI / 4.0,
|
||||||
|
|
|
@ -42,7 +42,7 @@ fn setup(
|
||||||
.insert(TemporalAntiAliasBundle::default());
|
.insert(TemporalAntiAliasBundle::default());
|
||||||
|
|
||||||
let material = materials.add(StandardMaterial {
|
let material = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.5, 0.5, 0.5),
|
base_color: Color::srgb(0.5, 0.5, 0.5),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
|
@ -69,7 +69,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.4).mesh().uv(72, 36)),
|
mesh: meshes.add(Sphere::new(0.4).mesh().uv(72, 36)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(0.4, 0.4, 0.4),
|
base_color: Color::srgb(0.4, 0.4, 0.4),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn setup(
|
||||||
|
|
||||||
// this material modulates the texture to make it red (and slightly transparent)
|
// this material modulates the texture to make it red (and slightly transparent)
|
||||||
let red_material_handle = materials.add(StandardMaterial {
|
let red_material_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgba(1.0, 0.0, 0.0, 0.5),
|
base_color: Color::srgba(1.0, 0.0, 0.0, 0.5),
|
||||||
base_color_texture: Some(texture_handle.clone()),
|
base_color_texture: Some(texture_handle.clone()),
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Blend,
|
||||||
unlit: true,
|
unlit: true,
|
||||||
|
@ -45,7 +45,7 @@ fn setup(
|
||||||
|
|
||||||
// and lets make this one blue! (and also slightly transparent)
|
// and lets make this one blue! (and also slightly transparent)
|
||||||
let blue_material_handle = materials.add(StandardMaterial {
|
let blue_material_handle = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgba(0.0, 0.0, 1.0, 0.5),
|
base_color: Color::srgba(0.0, 0.0, 1.0, 0.5),
|
||||||
base_color_texture: Some(texture_handle),
|
base_color_texture: Some(texture_handle),
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Blend,
|
||||||
unlit: true,
|
unlit: true,
|
||||||
|
|
|
@ -66,7 +66,7 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
FogSettings {
|
FogSettings {
|
||||||
color: LegacyColor::rgba_u8(43, 44, 47, 255),
|
color: Color::srgb_u8(43, 44, 47),
|
||||||
falloff: FogFalloff::Linear {
|
falloff: FogFalloff::Linear {
|
||||||
start: 1.0,
|
start: 1.0,
|
||||||
end: 8.0,
|
end: 8.0,
|
||||||
|
@ -109,7 +109,7 @@ fn setup_basic_scene(
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.1, 0.2, 0.1)),
|
material: materials.add(Color::srgb(0.1, 0.2, 0.1)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
SceneNumber(1),
|
SceneNumber(1),
|
||||||
|
@ -141,21 +141,21 @@ fn setup_basic_scene(
|
||||||
let s_val = if i < 3 { 0.0 } else { 0.2 };
|
let s_val = if i < 3 { 0.0 } else { 0.2 };
|
||||||
let material = if j == 0 {
|
let material = if j == 0 {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(s_val, s_val, 1.0),
|
base_color: Color::srgb(s_val, s_val, 1.0),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
} else if j == 1 {
|
} else if j == 1 {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(s_val, 1.0, s_val),
|
base_color: Color::srgb(s_val, 1.0, s_val),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
materials.add(StandardMaterial {
|
materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgb(1.0, s_val, s_val),
|
base_color: Color::srgb(1.0, s_val, s_val),
|
||||||
perceptual_roughness: 0.089,
|
perceptual_roughness: 0.089,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
..default()
|
..default()
|
||||||
|
@ -266,7 +266,7 @@ fn setup_image_viewer_scene(
|
||||||
"Drag and drop an HDR or EXR file",
|
"Drag and drop an HDR or EXR file",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font_size: 36.0,
|
font_size: 36.0,
|
||||||
color: LegacyColor::BLACK,
|
color: Color::BLACK,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,14 +21,17 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
color::palettes::css::*,
|
||||||
core_pipeline::{
|
core_pipeline::{
|
||||||
bloom::BloomSettings, core_3d::ScreenSpaceTransmissionQuality, prepass::DepthPrepass,
|
bloom::BloomSettings, core_3d::ScreenSpaceTransmissionQuality, prepass::DepthPrepass,
|
||||||
tonemapping::Tonemapping,
|
tonemapping::Tonemapping,
|
||||||
},
|
},
|
||||||
pbr::{NotShadowCaster, PointLightShadowMap, TransmittedShadowReceiver},
|
pbr::{NotShadowCaster, PointLightShadowMap, TransmittedShadowReceiver},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::camera::{Exposure, TemporalJitter},
|
render::{
|
||||||
render::view::ColorGrading,
|
camera::{Exposure, TemporalJitter},
|
||||||
|
view::ColorGrading,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
|
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
|
||||||
|
@ -41,7 +44,7 @@ fn main() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
|
||||||
app.add_plugins(DefaultPlugins)
|
app.add_plugins(DefaultPlugins)
|
||||||
.insert_resource(ClearColor(LegacyColor::BLACK))
|
.insert_resource(ClearColor(Color::BLACK))
|
||||||
.insert_resource(PointLightShadowMap { size: 2048 })
|
.insert_resource(PointLightShadowMap { size: 2048 })
|
||||||
.insert_resource(AmbientLight {
|
.insert_resource(AmbientLight {
|
||||||
brightness: 0.0,
|
brightness: 0.0,
|
||||||
|
@ -117,7 +120,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: cylinder_mesh,
|
mesh: cylinder_mesh,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgba(0.9, 0.2, 0.3, 1.0),
|
base_color: Color::srgb(0.9, 0.2, 0.3),
|
||||||
diffuse_transmission: 0.7,
|
diffuse_transmission: 0.7,
|
||||||
perceptual_roughness: 0.32,
|
perceptual_roughness: 0.32,
|
||||||
thickness: 0.2,
|
thickness: 0.2,
|
||||||
|
@ -134,11 +137,21 @@ fn setup(
|
||||||
));
|
));
|
||||||
|
|
||||||
// Candle Flame
|
// Candle Flame
|
||||||
|
let scaled_white = LinearRgba::from(ANTIQUE_WHITE) * 80.;
|
||||||
|
let scaled_orange = LinearRgba::from(ORANGE_RED) * 16.;
|
||||||
|
let emissive = LinearRgba {
|
||||||
|
red: scaled_white.red + scaled_orange.red,
|
||||||
|
green: scaled_white.green + scaled_orange.green,
|
||||||
|
blue: scaled_white.blue + scaled_orange.blue,
|
||||||
|
alpha: 1.0,
|
||||||
|
}
|
||||||
|
.into();
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: icosphere_mesh.clone(),
|
mesh: icosphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
emissive: LegacyColor::ANTIQUE_WHITE * 80.0 + LegacyColor::ORANGE_RED * 16.0,
|
emissive,
|
||||||
diffuse_transmission: 1.0,
|
diffuse_transmission: 1.0,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -154,7 +167,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: icosphere_mesh.clone(),
|
mesh: icosphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
specular_transmission: 0.9,
|
specular_transmission: 0.9,
|
||||||
diffuse_transmission: 1.0,
|
diffuse_transmission: 1.0,
|
||||||
thickness: 1.8,
|
thickness: 1.8,
|
||||||
|
@ -177,7 +190,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: icosphere_mesh.clone(),
|
mesh: icosphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::RED,
|
base_color: RED.into(),
|
||||||
specular_transmission: 0.9,
|
specular_transmission: 0.9,
|
||||||
diffuse_transmission: 1.0,
|
diffuse_transmission: 1.0,
|
||||||
thickness: 1.8,
|
thickness: 1.8,
|
||||||
|
@ -200,7 +213,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: icosphere_mesh.clone(),
|
mesh: icosphere_mesh.clone(),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::GREEN,
|
base_color: GREEN.into(),
|
||||||
specular_transmission: 0.9,
|
specular_transmission: 0.9,
|
||||||
diffuse_transmission: 1.0,
|
diffuse_transmission: 1.0,
|
||||||
thickness: 1.8,
|
thickness: 1.8,
|
||||||
|
@ -223,7 +236,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: icosphere_mesh,
|
mesh: icosphere_mesh,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::BLUE,
|
base_color: BLUE.into(),
|
||||||
specular_transmission: 0.9,
|
specular_transmission: 0.9,
|
||||||
diffuse_transmission: 1.0,
|
diffuse_transmission: 1.0,
|
||||||
thickness: 1.8,
|
thickness: 1.8,
|
||||||
|
@ -243,14 +256,14 @@ fn setup(
|
||||||
|
|
||||||
// Chessboard Plane
|
// Chessboard Plane
|
||||||
let black_material = materials.add(StandardMaterial {
|
let black_material = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::BLACK,
|
base_color: Color::BLACK,
|
||||||
reflectance: 0.3,
|
reflectance: 0.3,
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let white_material = materials.add(StandardMaterial {
|
let white_material = materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
reflectance: 0.3,
|
reflectance: 0.3,
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
..default()
|
..default()
|
||||||
|
@ -283,7 +296,7 @@ fn setup(
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: plane_mesh,
|
mesh: plane_mesh,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::WHITE,
|
base_color: Color::WHITE,
|
||||||
diffuse_transmission: 0.6,
|
diffuse_transmission: 0.6,
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
|
@ -309,7 +322,9 @@ fn setup(
|
||||||
PointLightBundle {
|
PointLightBundle {
|
||||||
transform: Transform::from_xyz(-1.0, 1.7, 0.0),
|
transform: Transform::from_xyz(-1.0, 1.7, 0.0),
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
color: LegacyColor::ANTIQUE_WHITE * 0.8 + LegacyColor::ORANGE_RED * 0.2,
|
color: Color::from(
|
||||||
|
LinearRgba::from(ANTIQUE_WHITE).mix(&LinearRgba::from(ORANGE_RED), 0.2),
|
||||||
|
),
|
||||||
intensity: 4_000.0,
|
intensity: 4_000.0,
|
||||||
radius: 0.2,
|
radius: 0.2,
|
||||||
range: 5.0,
|
range: 5.0,
|
||||||
|
@ -350,8 +365,7 @@ fn setup(
|
||||||
// Controls Text
|
// Controls Text
|
||||||
let text_style = TextStyle {
|
let text_style = TextStyle {
|
||||||
font_size: 18.0,
|
font_size: 18.0,
|
||||||
color: LegacyColor::WHITE,
|
..default()
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -476,9 +490,8 @@ fn example_control_system(
|
||||||
}
|
}
|
||||||
|
|
||||||
if controls.color && randomize_colors {
|
if controls.color && randomize_colors {
|
||||||
material.base_color.set_r(random());
|
material.base_color =
|
||||||
material.base_color.set_g(random());
|
Color::srgba(random(), random(), random(), material.base_color.alpha());
|
||||||
material.base_color.set_b(random());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn setup(
|
||||||
// Opaque plane, uses `alpha_mode: Opaque` by default
|
// Opaque plane, uses `alpha_mode: Opaque` by default
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(6.0, 6.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(6.0, 6.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.3, 0.5, 0.3)),
|
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ fn setup(
|
||||||
// We set it to 0.0 here, because it will be changed over time in the
|
// We set it to 0.0 here, because it will be changed over time in the
|
||||||
// `fade_transparency` function.
|
// `fade_transparency` function.
|
||||||
// Note that the transparency has no effect on the objects shadow.
|
// Note that the transparency has no effect on the objects shadow.
|
||||||
base_color: LegacyColor::rgba(0.2, 0.7, 0.1, 0.0),
|
base_color: Color::srgba(0.2, 0.7, 0.1, 0.0),
|
||||||
// Mask sets a cutoff for transparency. Alpha values below are fully transparent,
|
// Mask sets a cutoff for transparency. Alpha values below are fully transparent,
|
||||||
// alpha values above are fully opaque.
|
// alpha values above are fully opaque.
|
||||||
alpha_mode: AlphaMode::Mask(0.5),
|
alpha_mode: AlphaMode::Mask(0.5),
|
||||||
|
@ -47,7 +47,7 @@ fn setup(
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.5).mesh().ico(3).unwrap()),
|
mesh: meshes.add(Sphere::new(0.5).mesh().ico(3).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: LegacyColor::rgba(0.2, 0.7, 0.1, 0.0),
|
base_color: Color::srgba(0.2, 0.7, 0.1, 0.0),
|
||||||
alpha_mode: AlphaMode::Mask(0.5),
|
alpha_mode: AlphaMode::Mask(0.5),
|
||||||
unlit: true,
|
unlit: true,
|
||||||
..default()
|
..default()
|
||||||
|
@ -62,7 +62,7 @@ fn setup(
|
||||||
// Notice how there is no need to set the `alpha_mode` explicitly here.
|
// Notice how there is no need to set the `alpha_mode` explicitly here.
|
||||||
// When converting a color to a material using `into()`, the alpha mode is
|
// When converting a color to a material using `into()`, the alpha mode is
|
||||||
// automatically set to `Blend` if the alpha channel is anything lower than 1.0.
|
// automatically set to `Blend` if the alpha channel is anything lower than 1.0.
|
||||||
material: materials.add(LegacyColor::rgba(0.5, 0.5, 1.0, 0.0)),
|
material: materials.add(Color::srgba(0.5, 0.5, 1.0, 0.0)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ fn setup(
|
||||||
// Opaque sphere
|
// Opaque sphere
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.5).mesh().ico(3).unwrap()),
|
mesh: meshes.add(Sphere::new(0.5).mesh().ico(3).unwrap()),
|
||||||
material: materials.add(LegacyColor::rgb(0.7, 0.2, 0.1)),
|
material: materials.add(Color::srgb(0.7, 0.2, 0.1)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, -1.5),
|
transform: Transform::from_xyz(0.0, 0.5, -1.5),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
@ -101,6 +101,6 @@ fn setup(
|
||||||
pub fn fade_transparency(time: Res<Time>, mut materials: ResMut<Assets<StandardMaterial>>) {
|
pub fn fade_transparency(time: Res<Time>, mut materials: ResMut<Assets<StandardMaterial>>) {
|
||||||
let alpha = (time.elapsed_seconds().sin() / 2.0) + 0.5;
|
let alpha = (time.elapsed_seconds().sin() / 2.0) + 0.5;
|
||||||
for (_, material) in materials.iter_mut() {
|
for (_, material) in materials.iter_mut() {
|
||||||
material.base_color.set_a(alpha);
|
material.base_color.set_alpha(alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ fn setup(
|
||||||
// Plane
|
// Plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
|
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
|
||||||
material: materials.add(LegacyColor::rgb(0.3, 0.5, 0.3)),
|
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cube
|
// Cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::default()),
|
mesh: meshes.add(Cuboid::default()),
|
||||||
material: materials.add(LegacyColor::rgb(0.8, 0.7, 0.6)),
|
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue