Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ethereumdegen committed Jan 9, 2025
1 parent 6ad8530 commit 29d7355
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions examples/shader/extended_vertex_material.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
//! Demonstrates using a custom extension to the `StandardMaterial` to modify the results of the builtin pbr shader.
use bevy::pbr::MaterialExtensionKey;
use bevy::pbr::{MaterialExtensionPipeline,};
use bevy_render::mesh::MeshVertexAttribute;
use bevy_render::mesh::MeshVertexBufferLayoutRef;
use bevy::pbr::MaterialExtensionPipeline;
use bevy::{
color::palettes::basic::RED,

pbr::{ ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
prelude::*,
render::render_resource::*,
};
use bevy_render::mesh::MeshVertexAttribute;
use bevy_render::mesh::MeshVertexBufferLayoutRef;

/// 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_vertex_material.wgsl";


// 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.
const ATTRIBUTE_BLEND_COLOR: MeshVertexAttribute =
MeshVertexAttribute::new("BlendColor", 988540917, VertexFormat::Float32x4);


fn main() {
App::new()
.add_plugins(DefaultPlugins)
Expand All @@ -40,21 +37,17 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, MyExtension>>>,
) {


let mesh = Mesh::from(Cuboid::default())
let mesh = Mesh::from(Cuboid::default())
// Sets the custom attribute
.with_inserted_attribute(
ATTRIBUTE_BLEND_COLOR,
// The cube mesh has 24 vertices (6 faces, 4 vertices per face), so we insert one BlendColor for each
vec![[1.0, 0.0, 0.0, 1.0]; 24],
);



// sphere
commands.spawn((
Mesh3d(meshes.add( mesh )),
Mesh3d(meshes.add(mesh)),
MeshMaterial3d(materials.add(ExtendedMaterial {
base: StandardMaterial {
base_color: RED.into(),
Expand Down Expand Up @@ -101,8 +94,6 @@ struct MyExtension {
// so we start from binding slot 100, leaving slots 0-99 for the base material.
#[uniform(100)]
time_ms_elapsed: u32,


}

impl MaterialExtension for MyExtension {
Expand All @@ -119,11 +110,10 @@ impl MaterialExtension for MyExtension {
}

fn specialize(
_pipeline: &MaterialExtensionPipeline ,
_pipeline: &MaterialExtensionPipeline,
descriptor: &mut RenderPipelineDescriptor,
layout: &MeshVertexBufferLayoutRef ,
_key: MaterialExtensionKey<Self>

layout: &MeshVertexBufferLayoutRef,
_key: MaterialExtensionKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
let vertex_layout = layout.0.get_layout(&[
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
Expand Down

0 comments on commit 29d7355

Please sign in to comment.