diff --git a/assets/mask.png b/assets/mask.png deleted file mode 100644 index 1bb8f93..0000000 Binary files a/assets/mask.png and /dev/null differ diff --git a/assets/normal.png b/assets/normal.png deleted file mode 100644 index cd7ee06..0000000 Binary files a/assets/normal.png and /dev/null differ diff --git a/assets/pawn_combined.png b/assets/pawn_combined.png new file mode 100644 index 0000000..7087180 Binary files /dev/null and b/assets/pawn_combined.png differ diff --git a/assets/pawn_combined30.png b/assets/pawn_combined30.png new file mode 100644 index 0000000..bcf7009 Binary files /dev/null and b/assets/pawn_combined30.png differ diff --git a/assets/shaders/pawn.wesl b/assets/shaders/pawn.wesl new file mode 100644 index 0000000..eeb558e --- /dev/null +++ b/assets/shaders/pawn.wesl @@ -0,0 +1,56 @@ +import bevy_ui_render::ui_vertex_output::UiVertexOutput; + +@group(1) @binding(1) var combined_texture: texture_2d; +@group(1) @binding(2) var combined_sampler: sampler; + +fn scene(uv: vec2) -> vec4 { + let tex_color = textureSample(combined_texture, combined_sampler, uv); + let mask = tex_color.a; + + // Alpha cutout по маске + if mask < 0.1 { + discard; + } + + // Распаковка нормали: [0, 1] -> [-1, 1] + // Если тени выглядят вывернутыми — поменяйте знак у G-компонента. + let normal = normalize(vec3( + tex_color.r * 2.0 - 1.0, + tex_color.g * 2.0 - 1.0, + tex_color.b * 2.0 - 1.0, + )); + + // Направленный свет: постоянный вектор к источнику + let light_dir = normalize(vec3(-0.5, -1.0, 0.5)); + let ndotl = max(dot(normal, light_dir), 0.0); + + // Ambient, чтобы затенённые участки не были чёрными + let ambient = 0.25; + let lighting = ambient + ndotl * 0.75; + + // Базовый цвет поверхности — например, тот же зелёный, что был у вас. + // (или можно взять из uniform-поля материала, если добавите) + let base_color = vec3(0.08, 0.28, 0.4); + + let final_color = base_color * lighting; + + return vec4(final_color, 1.0); +} + +fn antialias(uv: vec2, delta: vec2) -> vec4 { + var color = vec4(0.0); + + color += scene(uv + delta * vec2(-0.5, -0.5)); + color += scene(uv + delta * vec2( 0.5, -0.5)); + color += scene(uv + delta * vec2(-0.5, 0.5)); + color += scene(uv + delta * vec2( 0.5, 0.5)); + + return color * 0.25; +} + +@fragment +fn fragment(in: UiVertexOutput) -> @location(0) vec4 { + let delta = fwidth(in.uv) * 0.5; + + return antialias(in.uv, delta); +} diff --git a/src/game_client/mod.rs b/src/game_client/mod.rs index 7ada41e..c099104 100644 --- a/src/game_client/mod.rs +++ b/src/game_client/mod.rs @@ -1,13 +1,14 @@ use bevy::prelude::*; mod ui_matireal; -use ui_matireal::BoardMaterial; +use ui_matireal::{BoardMaterial, PawnMaterial}; pub struct Cli; impl Plugin for Cli { fn build(&self, app: &mut App) { app.add_plugins(UiMaterialPlugin::::default()); + app.add_plugins(UiMaterialPlugin::::default()); app.add_systems(Startup, setup_scene); // app.add_systems(Update, my_system); } @@ -16,10 +17,15 @@ impl Plugin for Cli { fn setup_scene( mut commands: Commands, - mut materials: ResMut>, + mut b_materials: ResMut>, + mut p_materials: ResMut>, + asset: Res, ) { commands.spawn(Camera2d); + let texture_handle: Handle = asset.load("pawn_combined.png"); + let texture_handle30: Handle = asset.load("pawn_combined30.png"); + commands.spawn(( Node { width: Val::Percent(100.0), @@ -45,8 +51,29 @@ fn setup_scene( height: Val::Percent(100.0), ..default() }, - MaterialNode(materials.add(BoardMaterial { - })), + MaterialNode(b_materials.add(BoardMaterial {})), + children![ + ( + Node { + width: Val::Percent(12.5), + height: Val::Percent(12.5), + ..default() + }, + MaterialNode(p_materials.add(PawnMaterial { + combined_map: texture_handle + })), + ), + ( + Node { + width: Val::Percent(12.5), + height: Val::Percent(12.5), + ..default() + }, + MaterialNode(p_materials.add(PawnMaterial { + combined_map: texture_handle30 + })), + ), + ] ), ], ) diff --git a/src/game_client/ui_matireal.rs b/src/game_client/ui_matireal.rs index 40cc8dd..7c45602 100644 --- a/src/game_client/ui_matireal.rs +++ b/src/game_client/ui_matireal.rs @@ -11,3 +11,17 @@ impl UiMaterial for BoardMaterial { "shaders/custom_ui_material.wesl".into() } } + + +#[derive(AsBindGroup, Asset, TypePath, Debug, Clone)] +pub struct PawnMaterial { + #[texture(1)] + #[sampler(2)] + pub combined_map: Handle, +} + +impl UiMaterial for PawnMaterial { + fn fragment_shader() -> ShaderRef { + "shaders/pawn.wesl".into() + } +}