mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Restore procedural grid shader
This commit is contained in:
@@ -1,41 +1,38 @@
|
||||
// TODO: Figure out asset paths/loading for web
|
||||
|
||||
#[rustfmt::skip]
|
||||
use bevy::{
|
||||
// pbr::NotShadowCaster,
|
||||
pbr::NotShadowCaster,
|
||||
prelude::*,
|
||||
// reflect::{TypePath, TypeUuid},
|
||||
// render::render_resource::{AsBindGroup, ShaderRef},
|
||||
reflect::{TypePath, TypeUuid},
|
||||
render::render_resource::{AsBindGroup, ShaderRef},
|
||||
};
|
||||
|
||||
// use crate::orbit_cam::{self, OrbitCam};
|
||||
use crate::orbit_cam::{self, OrbitCam};
|
||||
|
||||
pub struct TestScenePlugin;
|
||||
|
||||
impl Plugin for TestScenePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(ClearColor(Color::hsl(0.0, 0.0, 0.25)))
|
||||
// .add_plugins(MaterialPlugin::<ProceduralGridMaterial> {
|
||||
// prepass_enabled: true,
|
||||
// ..default()
|
||||
// })
|
||||
.add_plugins(MaterialPlugin::<ProceduralGridMaterial> {
|
||||
prepass_enabled: true,
|
||||
..default()
|
||||
})
|
||||
.add_systems(Startup, spawn_scene)
|
||||
// .add_systems(
|
||||
// PostUpdate,
|
||||
// move_plane_with_camera.after(orbit_cam::pan_orbit_camera),
|
||||
// );
|
||||
;
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
move_plane_with_camera.after(orbit_cam::pan_orbit_camera),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Component)]
|
||||
// struct WorldGridPlane;
|
||||
#[derive(Component)]
|
||||
struct WorldGridPlane;
|
||||
|
||||
fn spawn_scene(
|
||||
mut cmd: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut std_mats: ResMut<Assets<StandardMaterial>>,
|
||||
// mut mat_proc_grid: ResMut<Assets<ProceduralGridMaterial>>,
|
||||
mut mat_proc_grid: ResMut<Assets<ProceduralGridMaterial>>,
|
||||
) {
|
||||
let mut light_xform = Transform::IDENTITY;
|
||||
light_xform.rotation = Quat::from_rotation_y(f32::to_radians(-70.0)) * light_xform.rotation;
|
||||
@@ -63,60 +60,60 @@ fn spawn_scene(
|
||||
});
|
||||
|
||||
// Plane
|
||||
// let plane = meshes.add(Mesh::from(shape::Plane {
|
||||
// size: 200.0,
|
||||
// subdivisions: 0,
|
||||
// }));
|
||||
// let proc_grid = mat_proc_grid.add(ProceduralGridMaterial {});
|
||||
let plane = meshes.add(Mesh::from(shape::Plane {
|
||||
size: 200.0,
|
||||
subdivisions: 0,
|
||||
}));
|
||||
let proc_grid = mat_proc_grid.add(ProceduralGridMaterial {});
|
||||
|
||||
// cmd.spawn((
|
||||
// SpatialBundle::from_transform(Transform::IDENTITY),
|
||||
// WorldGridPlane,
|
||||
// ))
|
||||
// .with_children(|parent| {
|
||||
// parent.spawn((
|
||||
// MaterialMeshBundle {
|
||||
// mesh: plane.clone(),
|
||||
// material: proc_grid.clone(),
|
||||
// transform: Transform::IDENTITY,
|
||||
// ..default()
|
||||
// },
|
||||
// NotShadowCaster,
|
||||
// ));
|
||||
// parent.spawn((
|
||||
// MaterialMeshBundle {
|
||||
// mesh: plane,
|
||||
// material: proc_grid,
|
||||
// transform: Transform::IDENTITY.looking_to(Vec3::Z, Vec3::NEG_Y),
|
||||
// ..default()
|
||||
// },
|
||||
// NotShadowCaster,
|
||||
// ));
|
||||
// });
|
||||
cmd.spawn((
|
||||
SpatialBundle::from_transform(Transform::IDENTITY),
|
||||
WorldGridPlane,
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent.spawn((
|
||||
MaterialMeshBundle {
|
||||
mesh: plane.clone(),
|
||||
material: proc_grid.clone(),
|
||||
transform: Transform::IDENTITY,
|
||||
..default()
|
||||
},
|
||||
NotShadowCaster,
|
||||
));
|
||||
parent.spawn((
|
||||
MaterialMeshBundle {
|
||||
mesh: plane,
|
||||
material: proc_grid,
|
||||
transform: Transform::IDENTITY.looking_to(Vec3::Z, Vec3::NEG_Y),
|
||||
..default()
|
||||
},
|
||||
NotShadowCaster,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
// fn move_plane_with_camera(
|
||||
// mut plane: Query<(&WorldGridPlane, &mut Transform)>,
|
||||
// camera: Query<&OrbitCam, Changed<OrbitCam>>,
|
||||
// ) {
|
||||
// if let Ok(&OrbitCam { focus, .. }) = camera.get_single() {
|
||||
// let (_, mut xform) = plane.single_mut();
|
||||
fn move_plane_with_camera(
|
||||
mut plane: Query<(&WorldGridPlane, &mut Transform)>,
|
||||
camera: Query<&OrbitCam, Changed<OrbitCam>>,
|
||||
) {
|
||||
if let Ok(&OrbitCam { focus, .. }) = camera.get_single() {
|
||||
let (_, mut xform) = plane.single_mut();
|
||||
|
||||
// xform.translation.x = focus.x;
|
||||
// xform.translation.z = focus.z;
|
||||
// }
|
||||
// }
|
||||
xform.translation.x = focus.x;
|
||||
xform.translation.z = focus.z;
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
|
||||
// #[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
|
||||
// struct ProceduralGridMaterial {}
|
||||
#[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
|
||||
#[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
|
||||
struct ProceduralGridMaterial {}
|
||||
|
||||
// impl Material for ProceduralGridMaterial {
|
||||
// fn fragment_shader() -> ShaderRef {
|
||||
// "shaders/procedural_grid.wgsl".into()
|
||||
// }
|
||||
impl Material for ProceduralGridMaterial {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/procedural_grid.wgsl".into()
|
||||
}
|
||||
|
||||
// fn alpha_mode(&self) -> AlphaMode {
|
||||
// AlphaMode::Blend
|
||||
// }
|
||||
// }
|
||||
fn alpha_mode(&self) -> AlphaMode {
|
||||
AlphaMode::Blend
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user