custom_vertex_attribute.wgsl 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #import bevy_pbr::mesh_functions::{get_model_matrix, mesh_position_local_to_clip}
  2. struct CustomMaterial {
  3. color: vec4<f32>,
  4. };
  5. @group(1) @binding(0) var<uniform> material: CustomMaterial;
  6. struct Vertex {
  7. @builtin(instance_index) instance_index: u32,
  8. @location(0) position: vec3<f32>,
  9. @location(1) blend_color: vec4<f32>,
  10. };
  11. struct VertexOutput {
  12. @builtin(position) clip_position: vec4<f32>,
  13. @location(0) blend_color: vec4<f32>,
  14. };
  15. @vertex
  16. fn vertex(vertex: Vertex) -> VertexOutput {
  17. var out: VertexOutput;
  18. out.clip_position = mesh_position_local_to_clip(
  19. get_model_matrix(vertex.instance_index),
  20. vec4<f32>(vertex.position, 1.0),
  21. );
  22. out.blend_color = vertex.blend_color;
  23. return out;
  24. }
  25. struct FragmentInput {
  26. @location(0) blend_color: vec4<f32>,
  27. };
  28. @fragment
  29. fn fragment(input: FragmentInput) -> @location(0) vec4<f32> {
  30. return material.color * input.blend_color;
  31. }