Skip to content

Commit

Permalink
shader imports figured out
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemunch committed Nov 2, 2023
1 parent 07c5001 commit a0307d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assets/shaders/test.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import bevy_sprite::mesh2d_view_bindings globals
#import bevy_sprite::mesh2d_vertex_output MeshVertexOutput
#import test_export

struct CustomMaterial {
color: vec4<f32>,
Expand All @@ -20,7 +21,9 @@ fn fragment(
let t_1 = sin(globals.time*2.0)*0.5+0.5;
let t_2 = cos(globals.time*2.0);

let color: vec4<f32> = vec4(t_1, t_2, t_1, 1.0);
var color: vec4<f32> = vec4(t_1, t_2, t_1, 0.0);

color.a = test_export::i_say_one();

return color * textureSample(base_color_texture, base_color_sampler, mesh.uv);
}
5 changes: 5 additions & 0 deletions assets/shaders/test_export.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define_import_path test_export

fn i_say_one() -> f32 {
return 1.0;
}
9 changes: 5 additions & 4 deletions examples/shader_2d.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use bevy::{
prelude::*,
reflect::{TypePath, TypeUuid},
render::{
render_resource::{AsBindGroup, ShaderRef},
texture::DEFAULT_IMAGE_HANDLE,
},
render::render_resource::{AsBindGroup, ShaderRef},
sprite::{Material2d, MaterialMesh2dBundle},
window::PrimaryWindow,
};
Expand Down Expand Up @@ -43,9 +40,13 @@ fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<CustomMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
asset_server: Res<AssetServer>,
) {
commands.spawn(Camera2dBundle::default());

// Shaders need to be in loaded to be accessed
commands.spawn(asset_server.load("shaders/test_export.wgsl") as Handle<Shader>);

// Sprite editor
let editor = commands
.spawn((CosmicEditBundle {
Expand Down

0 comments on commit a0307d3

Please sign in to comment.