format
This commit is contained in:
parent
6ad8530dd2
commit
29d73555ad
@ -1,29 +1,26 @@
|
|||||||
//! Demonstrates using a custom extension to the `StandardMaterial` to modify the results of the builtin pbr shader.
|
//! Demonstrates using a custom extension to the `StandardMaterial` to modify the results of the builtin pbr shader.
|
||||||
|
|
||||||
use bevy::pbr::MaterialExtensionKey;
|
use bevy::pbr::MaterialExtensionKey;
|
||||||
use bevy::pbr::{MaterialExtensionPipeline,};
|
use bevy::pbr::MaterialExtensionPipeline;
|
||||||
use bevy_render::mesh::MeshVertexAttribute;
|
|
||||||
use bevy_render::mesh::MeshVertexBufferLayoutRef;
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
color::palettes::basic::RED,
|
color::palettes::basic::RED,
|
||||||
|
pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
|
||||||
pbr::{ ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::render_resource::*,
|
render::render_resource::*,
|
||||||
};
|
};
|
||||||
|
use bevy_render::mesh::MeshVertexAttribute;
|
||||||
|
use bevy_render::mesh::MeshVertexBufferLayoutRef;
|
||||||
|
|
||||||
/// This example uses a shader source file from the assets subdirectory
|
/// This example uses a shader source file from the assets subdirectory
|
||||||
//const SHADER_ASSET_PATH: &str = "shaders/extended_material.wgsl";
|
//const SHADER_ASSET_PATH: &str = "shaders/extended_material.wgsl";
|
||||||
|
|
||||||
const SHADER_ASSET_PATH: &str = "shaders/extended_vertex_material.wgsl";
|
const SHADER_ASSET_PATH: &str = "shaders/extended_vertex_material.wgsl";
|
||||||
|
|
||||||
|
|
||||||
// A "high" random id should be used for custom attributes to ensure consistent sorting and avoid collisions with other attributes.
|
// A "high" random id should be used for custom attributes to ensure consistent sorting and avoid collisions with other attributes.
|
||||||
// See the MeshVertexAttribute docs for more info.
|
// See the MeshVertexAttribute docs for more info.
|
||||||
const ATTRIBUTE_BLEND_COLOR: MeshVertexAttribute =
|
const ATTRIBUTE_BLEND_COLOR: MeshVertexAttribute =
|
||||||
MeshVertexAttribute::new("BlendColor", 988540917, VertexFormat::Float32x4);
|
MeshVertexAttribute::new("BlendColor", 988540917, VertexFormat::Float32x4);
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
@ -40,8 +37,6 @@ fn setup(
|
|||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, MyExtension>>>,
|
mut materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, MyExtension>>>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
||||||
let mesh = Mesh::from(Cuboid::default())
|
let mesh = Mesh::from(Cuboid::default())
|
||||||
// Sets the custom attribute
|
// Sets the custom attribute
|
||||||
.with_inserted_attribute(
|
.with_inserted_attribute(
|
||||||
@ -50,11 +45,9 @@ fn setup(
|
|||||||
vec![[1.0, 0.0, 0.0, 1.0]; 24],
|
vec![[1.0, 0.0, 0.0, 1.0]; 24],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// sphere
|
// sphere
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(meshes.add( mesh )),
|
Mesh3d(meshes.add(mesh)),
|
||||||
MeshMaterial3d(materials.add(ExtendedMaterial {
|
MeshMaterial3d(materials.add(ExtendedMaterial {
|
||||||
base: StandardMaterial {
|
base: StandardMaterial {
|
||||||
base_color: RED.into(),
|
base_color: RED.into(),
|
||||||
@ -101,8 +94,6 @@ struct MyExtension {
|
|||||||
// so we start from binding slot 100, leaving slots 0-99 for the base material.
|
// so we start from binding slot 100, leaving slots 0-99 for the base material.
|
||||||
#[uniform(100)]
|
#[uniform(100)]
|
||||||
time_ms_elapsed: u32,
|
time_ms_elapsed: u32,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaterialExtension for MyExtension {
|
impl MaterialExtension for MyExtension {
|
||||||
@ -119,11 +110,10 @@ impl MaterialExtension for MyExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn specialize(
|
fn specialize(
|
||||||
_pipeline: &MaterialExtensionPipeline ,
|
_pipeline: &MaterialExtensionPipeline,
|
||||||
descriptor: &mut RenderPipelineDescriptor,
|
descriptor: &mut RenderPipelineDescriptor,
|
||||||
layout: &MeshVertexBufferLayoutRef ,
|
layout: &MeshVertexBufferLayoutRef,
|
||||||
_key: MaterialExtensionKey<Self>
|
_key: MaterialExtensionKey<Self>,
|
||||||
|
|
||||||
) -> Result<(), SpecializedMeshPipelineError> {
|
) -> Result<(), SpecializedMeshPipelineError> {
|
||||||
let vertex_layout = layout.0.get_layout(&[
|
let vertex_layout = layout.0.get_layout(&[
|
||||||
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||||
|
Loading…
Reference in New Issue
Block a user