done board.
This commit is contained in:
1 parent
9852f30581
commit
08f8931502
3 files changed
+113
No files matched your search
@@ -0,0 +1,84 @@
|
|||||||
|
import bevy_ui_render::ui_vertex_output::UiVertexOutput;
|
||||||
|
|
||||||
|
fn random (pos: vec2<f32>) -> f32 {
|
||||||
|
return fract(sin(dot(pos.xy,
|
||||||
|
vec2(12.9898,78.233)))*
|
||||||
|
43758.5453123);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn noise (st: vec2<f32>) -> f32 {
|
||||||
|
let i = floor(st);
|
||||||
|
let f = fract(st);
|
||||||
|
|
||||||
|
// Four corners in 2D of a tile
|
||||||
|
let a = random(i);
|
||||||
|
let b = random(i + vec2(1.0, 0.0));
|
||||||
|
let c = random(i + vec2(0.0, 1.0));
|
||||||
|
let d = random(i + vec2(1.0, 1.0));
|
||||||
|
|
||||||
|
let u = f * f * (3.0 - 2.0 * f);
|
||||||
|
|
||||||
|
return mix(a, b, u.x) +
|
||||||
|
(c - a)* u.y * (1.0 - u.x) +
|
||||||
|
(d - b) * u.x * u.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fbm(st: vec2<f32>) -> f32 {
|
||||||
|
var value = 0.0;
|
||||||
|
var amplitude = 0.5;
|
||||||
|
var p = st;
|
||||||
|
|
||||||
|
for (var i: u32 = 0u; i < 6u; i += 1u) {
|
||||||
|
value += amplitude * noise(p);
|
||||||
|
p *= 2.0;
|
||||||
|
amplitude *= 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sp(in: f32) -> f32 {
|
||||||
|
return min(in * 2.0, -in * 2.0 + 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sp2(in: f32) -> f32 {
|
||||||
|
return max(sp(in * 2.0), sp(in * 2.0) - 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wood(uv: vec2<f32>, color: vec3<f32>, sel: bool) -> vec3<f32> {
|
||||||
|
let b = select(color, color * 0.6, sel);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scene(uv: vec2<f32>) -> vec4<f32> {
|
||||||
|
let cell = floor(uv * 8.0);
|
||||||
|
|
||||||
|
let dark_green = vec3<f32>(0.08, 0.28, 0.16);
|
||||||
|
let light_beige = vec3<f32>(0.88, 0.84, 0.72);
|
||||||
|
|
||||||
|
let color = select(
|
||||||
|
wood(uv, dark_green, sp(fbm(uv * 40.0)) > 0.9),
|
||||||
|
wood(uv, light_beige, sp(fbm(uv * 60.0 + vec2<f32>(400.0, 400.0))) > 0.9),
|
||||||
|
(i32(cell.x) + i32(cell.y)) % 2 == 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return vec4<f32>(color, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn antialias(uv: vec2<f32>, delta: vec2<f32>) -> vec4<f32> {
|
||||||
|
var color = vec4<f32>(0.0);
|
||||||
|
|
||||||
|
color += scene(uv + delta * vec2<f32>(-0.5, -0.5));
|
||||||
|
color += scene(uv + delta * vec2<f32>( 0.5, -0.5));
|
||||||
|
color += scene(uv + delta * vec2<f32>(-0.5, 0.5));
|
||||||
|
color += scene(uv + delta * vec2<f32>( 0.5, 0.5));
|
||||||
|
|
||||||
|
return color * 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
|
||||||
|
let delta = fwidth(in.uv) * 0.5;
|
||||||
|
|
||||||
|
return antialias(in.uv, delta);
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
mod ui_matireal;
|
||||||
|
use ui_matireal::BoardMaterial;
|
||||||
|
|
||||||
pub struct Cli;
|
pub struct Cli;
|
||||||
|
|
||||||
impl Plugin for Cli {
|
impl Plugin for Cli {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_plugins(UiMaterialPlugin::<BoardMaterial>::default());
|
||||||
app.add_systems(Startup, setup_scene);
|
app.add_systems(Startup, setup_scene);
|
||||||
// app.add_systems(Update, my_system);
|
// app.add_systems(Update, my_system);
|
||||||
}
|
}
|
||||||
@@ -12,6 +16,7 @@ impl Plugin for Cli {
|
|||||||
|
|
||||||
fn setup_scene(
|
fn setup_scene(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
mut materials: ResMut<Assets<BoardMaterial>>,
|
||||||
) {
|
) {
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
|
|
||||||
@@ -33,6 +38,17 @@ fn setup_scene(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
BackgroundColor(Color::srgb(0.2, 0.6, 0.8)),
|
BackgroundColor(Color::srgb(0.2, 0.6, 0.8)),
|
||||||
|
children![
|
||||||
|
(
|
||||||
|
Node {
|
||||||
|
width: Val::Percent(100.0),
|
||||||
|
height: Val::Percent(100.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
MaterialNode(materials.add(BoardMaterial {
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy::render::render_resource::AsBindGroup;
|
||||||
|
use bevy::shader::ShaderRef;
|
||||||
|
|
||||||
|
// Пустая структура — наш флаг-материал.
|
||||||
|
#[derive(AsBindGroup, Asset, TypePath, Debug, Clone)]
|
||||||
|
pub struct BoardMaterial {}
|
||||||
|
|
||||||
|
impl UiMaterial for BoardMaterial {
|
||||||
|
fn fragment_shader() -> ShaderRef {
|
||||||
|
"shaders/custom_ui_material.wesl".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user