refactor: use bevy_sk PbrMaterial instead of StandardMaterial
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -40,6 +40,7 @@ use bevy_mod_openxr::resources::{OxrFrameState, OxrFrameWaiter, OxrSessionConfig
|
|||||||
use bevy_mod_openxr::types::AppInfo;
|
use bevy_mod_openxr::types::AppInfo;
|
||||||
use bevy_mod_xr::camera::XrProjection;
|
use bevy_mod_xr::camera::XrProjection;
|
||||||
use bevy_mod_xr::session::{XrFirst, XrHandleEvents, XrSessionPlugin};
|
use bevy_mod_xr::session::{XrFirst, XrHandleEvents, XrSessionPlugin};
|
||||||
|
use bevy_sk::vr_materials::PbrMaterial;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use core::client::{Client, tick_internal_client};
|
use core::client::{Client, tick_internal_client};
|
||||||
use core::entity_handle::EntityHandlePlugin;
|
use core::entity_handle::EntityHandlePlugin;
|
||||||
@@ -103,7 +104,7 @@ struct CliArgs {
|
|||||||
restore: Option<String>,
|
restore: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BevyMaterial = StandardMaterial;
|
pub type BevyMaterial = PbrMaterial;
|
||||||
|
|
||||||
static STARDUST_INSTANCE: OnceLock<String> = OnceLock::new();
|
static STARDUST_INSTANCE: OnceLock<String> = OnceLock::new();
|
||||||
|
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ fn build_line_mesh(
|
|||||||
Name::new("LinesNode"),
|
Name::new("LinesNode"),
|
||||||
SpatialNode(Arc::downgrade(&lines.spatial)),
|
SpatialNode(Arc::downgrade(&lines.spatial)),
|
||||||
MeshMaterial3d(materials.add(BevyMaterial {
|
MeshMaterial3d(materials.add(BevyMaterial {
|
||||||
base_color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
perceptual_roughness: 1.0,
|
roughness: 1.0,
|
||||||
alpha_mode: AlphaMode::Opaque,
|
alpha_mode: AlphaMode::Opaque,
|
||||||
..default()
|
..default()
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -237,10 +237,10 @@ impl HashedPbrMaterial {
|
|||||||
Self(hasher.finish())
|
Self(hasher.finish())
|
||||||
}
|
}
|
||||||
fn hash_pbr_mat<H: Hasher>(mat: &BevyMaterial, state: &mut H) {
|
fn hash_pbr_mat<H: Hasher>(mat: &BevyMaterial, state: &mut H) {
|
||||||
hash_color(mat.base_color, state);
|
hash_color(mat.color, state);
|
||||||
hash_color(mat.emissive.into(), state);
|
hash_color(mat.emission_factor.into(), state);
|
||||||
state.write_u32(mat.metallic.to_bits());
|
state.write_u32(mat.metallic.to_bits());
|
||||||
state.write_u32(mat.perceptual_roughness.to_bits());
|
state.write_u32(mat.roughness.to_bits());
|
||||||
match mat.alpha_mode {
|
match mat.alpha_mode {
|
||||||
AlphaMode::Opaque => state.write_u8(0),
|
AlphaMode::Opaque => state.write_u8(0),
|
||||||
AlphaMode::Mask(v) => {
|
AlphaMode::Mask(v) => {
|
||||||
@@ -254,9 +254,9 @@ impl HashedPbrMaterial {
|
|||||||
AlphaMode::Multiply => state.write_u8(6),
|
AlphaMode::Multiply => state.write_u8(6),
|
||||||
}
|
}
|
||||||
state.write_u8(mat.double_sided as u8);
|
state.write_u8(mat.double_sided as u8);
|
||||||
mat.base_color_texture.hash(state);
|
mat.diffuse_texture.hash(state);
|
||||||
mat.emissive_texture.hash(state);
|
mat.emission_texture.hash(state);
|
||||||
mat.metallic_roughness_texture.hash(state);
|
mat.metal_texture.hash(state);
|
||||||
mat.occlusion_texture.hash(state);
|
mat.occlusion_texture.hash(state);
|
||||||
// should always be the same, TODO: make the spherical harmonics buffer a per mesh instance thing
|
// should always be the same, TODO: make the spherical harmonics buffer a per mesh instance thing
|
||||||
// mat.spherical_harmonics.hash(state);
|
// mat.spherical_harmonics.hash(state);
|
||||||
@@ -350,7 +350,7 @@ impl MaterialParameter {
|
|||||||
MaterialParameter::Float(val) => {
|
MaterialParameter::Float(val) => {
|
||||||
match parameter_name {
|
match parameter_name {
|
||||||
"metallic" => mat.metallic = *val,
|
"metallic" => mat.metallic = *val,
|
||||||
"roughness" => mat.perceptual_roughness = *val,
|
"roughness" => mat.roughness = *val,
|
||||||
// we probably don't want to expose tex_scale
|
// we probably don't want to expose tex_scale
|
||||||
// "tex_scale" => mat.tex_scale = *val,
|
// "tex_scale" => mat.tex_scale = *val,
|
||||||
v => {
|
v => {
|
||||||
@@ -365,8 +365,8 @@ impl MaterialParameter {
|
|||||||
// nothing uses a Vec3
|
// nothing uses a Vec3
|
||||||
}
|
}
|
||||||
MaterialParameter::Color(color) => match parameter_name {
|
MaterialParameter::Color(color) => match parameter_name {
|
||||||
"color" => mat.base_color = color.to_bevy(),
|
"color" => mat.color = color.to_bevy(),
|
||||||
"emission_factor" => mat.emissive = color.to_bevy().to_linear(),
|
"emission_factor" => mat.emission_factor = color.to_bevy(),
|
||||||
v => {
|
v => {
|
||||||
error!("unknown param_name ({v}) for color")
|
error!("unknown param_name ({v}) for color")
|
||||||
}
|
}
|
||||||
@@ -379,9 +379,9 @@ impl MaterialParameter {
|
|||||||
};
|
};
|
||||||
let handle = asset_server.load(texture_path);
|
let handle = asset_server.load(texture_path);
|
||||||
match parameter_name {
|
match parameter_name {
|
||||||
"diffuse" => mat.base_color_texture = Some(handle),
|
"diffuse" => mat.diffuse_texture = Some(handle),
|
||||||
"emission" => mat.emissive_texture = Some(handle),
|
"emission" => mat.emission_texture = Some(handle),
|
||||||
"metal" => mat.metallic_roughness_texture = Some(handle),
|
"metal" => mat.metal_texture = Some(handle),
|
||||||
"occlusion" => mat.occlusion_texture = Some(handle),
|
"occlusion" => mat.occlusion_texture = Some(handle),
|
||||||
v => {
|
v => {
|
||||||
error!("unknown param_name ({v}) for texture");
|
error!("unknown param_name ({v}) for texture");
|
||||||
@@ -410,21 +410,21 @@ pub struct Material {
|
|||||||
impl Material {
|
impl Material {
|
||||||
fn to_pbr_mat(&self, asset_server: &AssetServer) -> BevyMaterial {
|
fn to_pbr_mat(&self, asset_server: &AssetServer) -> BevyMaterial {
|
||||||
BevyMaterial {
|
BevyMaterial {
|
||||||
base_color: self.color,
|
color: self.color,
|
||||||
emissive: self.emission_factor.to_linear(),
|
emission_factor: self.emission_factor,
|
||||||
metallic: self.metallic,
|
metallic: self.metallic,
|
||||||
perceptual_roughness: self.roughness,
|
roughness: self.roughness,
|
||||||
alpha_mode: self.alpha_mode,
|
alpha_mode: self.alpha_mode,
|
||||||
double_sided: self.double_sided,
|
double_sided: self.double_sided,
|
||||||
base_color_texture: self
|
diffuse_texture: self
|
||||||
.diffuse_texture
|
.diffuse_texture
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| asset_server.load(p.as_path())),
|
.map(|p| asset_server.load(p.as_path())),
|
||||||
emissive_texture: self
|
emission_texture: self
|
||||||
.emission_texture
|
.emission_texture
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| asset_server.load(p.as_path())),
|
.map(|p| asset_server.load(p.as_path())),
|
||||||
metallic_roughness_texture: self
|
metal_texture: self
|
||||||
.metal_texture
|
.metal_texture
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| asset_server.load(p.as_path())),
|
.map(|p| asset_server.load(p.as_path())),
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ fn spawn_text(
|
|||||||
text: text_string,
|
text: text_string,
|
||||||
material: material_registry.get_handle(
|
material: material_registry.get_handle(
|
||||||
BevyMaterial {
|
BevyMaterial {
|
||||||
base_color: style.color.to_bevy(),
|
color: style.color.to_bevy(),
|
||||||
emissive: Color::WHITE.to_linear(),
|
emission_factor: Color::WHITE,
|
||||||
metallic: 0.0,
|
metallic: 0.0,
|
||||||
perceptual_roughness: 1.0,
|
roughness: 1.0,
|
||||||
// If alpha is supported on text we need to change this
|
// If alpha is supported on text we need to change this
|
||||||
alpha_mode: AlphaMode::Opaque,
|
alpha_mode: AlphaMode::Opaque,
|
||||||
double_sided: false,
|
double_sided: false,
|
||||||
|
|||||||
@@ -219,10 +219,10 @@ impl OxrHandInput {
|
|||||||
let input = InputMethod::add_to(&node.0, hand, datamap)?;
|
let input = InputMethod::add_to(&node.0, hand, datamap)?;
|
||||||
|
|
||||||
let material = materials.add(BevyMaterial {
|
let material = materials.add(BevyMaterial {
|
||||||
base_color: Srgba::new(1.0, 1.0, 1.0, 1.0).into(),
|
color: Srgba::new(1.0, 1.0, 1.0, 1.0).into(),
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Blend,
|
||||||
base_color_texture: Some(GRADIENT_TEXTURE_HANDLE),
|
diffuse_texture: Some(GRADIENT_TEXTURE_HANDLE),
|
||||||
perceptual_roughness: 1.0,
|
roughness: 1.0,
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
Ok(OxrHandInput {
|
Ok(OxrHandInput {
|
||||||
@@ -329,10 +329,10 @@ impl OxrHandInput {
|
|||||||
*self.input.datamap.lock() = Datamap::from_typed(&self.datamap).unwrap();
|
*self.input.datamap.lock() = Datamap::from_typed(&self.datamap).unwrap();
|
||||||
let captured = self.capture_manager.capture.upgrade().is_some();
|
let captured = self.capture_manager.capture.upgrade().is_some();
|
||||||
if captured && !self.captured {
|
if captured && !self.captured {
|
||||||
materials.get_mut(&self.material).unwrap().base_color =
|
materials.get_mut(&self.material).unwrap().color =
|
||||||
Srgba::rgb(0., 1., 0.75).into();
|
Srgba::rgb(0., 1., 0.75).into();
|
||||||
} else if self.captured && !captured {
|
} else if self.captured && !captured {
|
||||||
materials.get_mut(&self.material).unwrap().base_color =
|
materials.get_mut(&self.material).unwrap().color =
|
||||||
Srgba::rgb(1., 1.0, 1.0).into();
|
Srgba::rgb(1., 1.0, 1.0).into();
|
||||||
}
|
}
|
||||||
self.captured = captured;
|
self.captured = captured;
|
||||||
|
|||||||
Reference in New Issue
Block a user