1//! Very simple shader used to demonstrate how to get the world position and pass data2//! between the vertex and fragment shader. Also shows the custom vertex layout.4// First we import everything we need from bevy_pbr5// A 2D shader would be very similar but import from bevy_sprite instead6#import bevy_pbr::{7 mesh_functions,8 view_transformations::position_world_to_clip9}11struct Vertex {12 // This is needed if you are using batching and/or gpu preprocessing13 // It's a built in so you don't need to define it in the vertex layout14 @builtin(instance_index) instance_index: u32,15 // Like we defined for the vertex layout16 // position is at location 017 @location(0) position: vec3<f32>,18 // and color at location 119 @location(1) color: vec4<f32>,20};22// This is the output of the vertex shader and we also use it as the input for the fragment shader23struct VertexOutput {24 @builtin(position) clip_position: vec4<f32>,25 @location(0) world_position: vec4<f32>,26 @location(1) color: vec3<f32>,27};29@vertex30fn vertex(vertex: Vertex) -> VertexOutput {31 var out: VertexOutput;32 // This is how bevy computes the world position33 // The vertex.instance_index is very important. Especially if you are using batching and gpu preprocessing34 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);35 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0));36 out.clip_position = position_world_to_clip(out.world_position.xyz);38 // We just use the raw vertex color39 out.color = vertex.color.rgb;41 return out;42}44@fragment45fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {46 // output the color directly47 return vec4(in.color, 1.0);48}