From a0307d36a218cab3b7843acc0cc896a0c4ef993c Mon Sep 17 00:00:00 2001 From: sam edelsten Date: Thu, 2 Nov 2023 16:52:19 +0000 Subject: [PATCH] shader imports figured out --- assets/shaders/test.wgsl | 5 ++++- assets/shaders/test_export.wgsl | 5 +++++ examples/shader_2d.rs | 9 +++++---- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 assets/shaders/test_export.wgsl diff --git a/assets/shaders/test.wgsl b/assets/shaders/test.wgsl index 69ffe91..ee73d75 100644 --- a/assets/shaders/test.wgsl +++ b/assets/shaders/test.wgsl @@ -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, @@ -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 = vec4(t_1, t_2, t_1, 1.0); +var color: vec4 = 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); } diff --git a/assets/shaders/test_export.wgsl b/assets/shaders/test_export.wgsl new file mode 100644 index 0000000..8bc0d44 --- /dev/null +++ b/assets/shaders/test_export.wgsl @@ -0,0 +1,5 @@ +#define_import_path test_export + +fn i_say_one() -> f32 { + return 1.0; + } diff --git a/examples/shader_2d.rs b/examples/shader_2d.rs index b25003f..b378238 100644 --- a/examples/shader_2d.rs +++ b/examples/shader_2d.rs @@ -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, }; @@ -43,9 +40,13 @@ fn setup( mut commands: Commands, mut materials: ResMut>, mut meshes: ResMut>, + asset_server: Res, ) { commands.spawn(Camera2dBundle::default()); + // Shaders need to be in loaded to be accessed + commands.spawn(asset_server.load("shaders/test_export.wgsl") as Handle); + // Sprite editor let editor = commands .spawn((CosmicEditBundle {