-
Notifications
You must be signed in to change notification settings - Fork 50
/
custom_shader.rs
68 lines (61 loc) · 2.04 KB
/
custom_shader.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use bevy::{prelude::*, reflect::TypePath, render::render_resource::AsBindGroup};
use kayak_ui::{
prelude::{widgets::*, *},
CameraUIKayak,
};
#[derive(AsBindGroup, Asset, TypePath, Debug, Clone)]
pub struct MyUIMaterial {}
impl MaterialUI for MyUIMaterial {
fn fragment_shader() -> bevy::render::render_resource::ShaderRef {
"rainbow_shader.wgsl".into()
}
}
fn startup(
mut commands: Commands,
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<MyUIMaterial>>,
) {
let camera_entity = commands
.spawn(Camera2dBundle::default())
.insert(CameraUIKayak)
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let my_material = MyUIMaterial {};
let my_material_handle = materials.add(my_material);
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
<KayakAppBundle>
<TextWidgetBundle
styles={KStyle {
position_type: KPositionType::SelfDirected.into(),
left: Units::Pixels(20.0).into(),
top: Units::Pixels(5.0).into(),
material: MaterialHandle::new(move |commands, entity| {
commands.entity(entity).insert(my_material_handle.clone_weak());
}).into(),
..Default::default()
}}
text={TextProps {
content: "Hello Shader!".into(),
size: 20.0,
..Default::default()
}}
/>
</KayakAppBundle>
};
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((
KayakContextPlugin,
KayakWidgets,
MaterialUIPlugin::<MyUIMaterial>::default(),
))
.add_systems(Startup, startup)
.run()
}