High-perf wireframe for planet.

This commit is contained in:
Joe Ardent 2022-02-21 13:08:49 -08:00
parent 212d9daac9
commit 373fc30d56
7 changed files with 70 additions and 52 deletions

46
Cargo.lock generated
View File

@ -73,9 +73,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.53" version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" checksum = "7a99269dff3bc004caa411f38845c20303f1e393ca2bd6581576fa3a7f59577d"
[[package]] [[package]]
name = "approx" name = "approx"
@ -152,9 +152,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]] [[package]]
name = "bevy" name = "bevy"
version = "0.6.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b77ad2987710ed960746c43813ad8c103db5c4c090f5cbc9c32c0a90a91bc599" checksum = "97342ea2f3bad36be2ded1d1fbd569ff83147b70697f12f1579e87a7480afa36"
dependencies = [ dependencies = [
"bevy_internal", "bevy_internal",
] ]
@ -523,7 +523,7 @@ dependencies = [
"downcast-rs", "downcast-rs",
"futures-lite", "futures-lite",
"hex", "hex",
"hexasphere", "hexasphere 6.1.0",
"image", "image",
"naga", "naga",
"once_cell", "once_cell",
@ -784,9 +784,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.72" version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -1066,7 +1066,7 @@ dependencies = [
"bevy", "bevy",
"bevy_polyline", "bevy_polyline",
"bevy_rapier3d", "bevy_rapier3d",
"hexasphere", "hexasphere 7.0.0",
"noise", "noise",
"rand 0.8.5", "rand 0.8.5",
"wgpu", "wgpu",
@ -1460,9 +1460,19 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]] [[package]]
name = "hexasphere" name = "hexasphere"
version = "6.0.0" version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dc62dcfd68ec810c4707804556f2e88655012b1a373b0e0bbbe88a9db366627" checksum = "2b219bdb56b14905fa5429636bfc4df0043626642d4586d069a82019130846f5"
dependencies = [
"glam",
"lazy_static",
]
[[package]]
name = "hexasphere"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04ab9d20ba513ff1582a7d885e91839f62cf28bef7c56b1b0428ca787315979b"
dependencies = [ dependencies = [
"glam", "glam",
"lazy_static", "lazy_static",
@ -1579,9 +1589,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.118" version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94" checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]] [[package]]
name = "libloading" name = "libloading"
@ -2130,9 +2140,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.1.0" version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" checksum = "9dada8c9981fcf32929c3c0f0cd796a9284aca335565227ed88c83babb1d43dc"
dependencies = [ dependencies = [
"thiserror", "thiserror",
"toml", "toml",
@ -2674,9 +2684,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.30" version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9" checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"pin-project-lite", "pin-project-lite",
@ -2718,9 +2728,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.8" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"lazy_static", "lazy_static",

View File

@ -7,7 +7,7 @@ edition = "2021"
rand = "0.8" rand = "0.8"
bevy_polyline = "0.1" bevy_polyline = "0.1"
noise = { git = "https://github.com/Razaekel/noise-rs" } noise = { git = "https://github.com/Razaekel/noise-rs" }
hexasphere = "6.0.0" hexasphere = "7"
wgpu = "0.12.0" wgpu = "0.12.0"
[dependencies.bevy] [dependencies.bevy]
@ -33,4 +33,3 @@ opt-level = 1
# Enable optimizations for dependencies (incl. Bevy), but not for our code: # Enable optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3

View File

@ -34,8 +34,8 @@ fn setup_colliders(
let pcollide = ColliderBundle { let pcollide = ColliderBundle {
shape: ColliderShape::ball(PLANET_RADIUS).into(), shape: ColliderShape::ball(PLANET_RADIUS).into(),
material: ColliderMaterial { material: ColliderMaterial {
friction: 0.1, friction: 0.05,
restitution: 0.05, restitution: 0.01,
..Default::default() ..Default::default()
} }
.into(), .into(),
@ -53,7 +53,7 @@ fn setup_colliders(
fn setup_bike(bike: Entity, xform: &Transform, commands: &mut Commands) { fn setup_bike(bike: Entity, xform: &Transform, commands: &mut Commands) {
let mut bbody = RigidBodyBundle::default(); let mut bbody = RigidBodyBundle::default();
bbody.damping.angular_damping = 0.5; bbody.damping.angular_damping = 0.7;
bbody.damping.linear_damping = 0.3; bbody.damping.linear_damping = 0.3;
bbody.forces = RigidBodyForces { bbody.forces = RigidBodyForces {
torque: Vec3::ZERO.into(), torque: Vec3::ZERO.into(),
@ -65,8 +65,8 @@ fn setup_bike(bike: Entity, xform: &Transform, commands: &mut Commands) {
..Default::default() ..Default::default()
} }
.into(); .into();
bbody.mass_properties = // bbody.mass_properties = MassProperties::new(Vec3::ZERO.into(), 0.5,
MassProperties::new(Vec3::ZERO.into(), 0.5, Vec3::new(0.0, 0.01, 0.0).into()).into(); // Vec3::new(0.0, 0.01, 0.0).into()).into();
let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into()); let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into());
bbody.position = isometry.into(); bbody.position = isometry.into();
// collider // collider
@ -77,7 +77,7 @@ fn setup_bike(bike: Entity, xform: &Transform, commands: &mut Commands) {
); );
let bcollide = ColliderBundle { let bcollide = ColliderBundle {
shape: shape.into(), shape: shape.into(),
mass_properties: ColliderMassProps::Density(0.3).into(), mass_properties: ColliderMassProps::Density(0.2).into(),
material: ColliderMaterial { material: ColliderMaterial {
friction: 0.0, friction: 0.0,
restitution: 0.05, restitution: 0.05,
@ -94,7 +94,7 @@ fn setup_bike(bike: Entity, xform: &Transform, commands: &mut Commands) {
} }
fn gravity(xform: Query<&Transform, With<CyberBike>>, mut config: ResMut<RapierConfiguration>) { fn gravity(xform: Query<&Transform, With<CyberBike>>, mut config: ResMut<RapierConfiguration>) {
let gravity = xform.single().translation.normalize() * -8.0; let gravity = xform.single().translation.normalize() * -6.0;
config.gravity = gravity.into(); config.gravity = gravity.into();
} }
@ -107,7 +107,7 @@ fn falling_cat(
let cos = up.dot(cam_up); let cos = up.dot(cam_up);
let theta = cos.acos(); let theta = cos.acos();
let force_mag = if !theta.is_normal() { 0.0 } else { theta * 5.0 }; let force_mag = if !theta.is_normal() { 0.0 } else { theta * 2.0 };
let torque = cam_up.cross(up).normalize() * force_mag; let torque = cam_up.cross(up).normalize() * force_mag;
forces.torque = torque.into(); forces.torque = torque.into();

View File

@ -22,9 +22,7 @@ fn spawn_giant_sphere(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let mut color = Color::DARK_GRAY; let color = Color::DARK_GRAY;
color.set_a(0.92);
let isphere = shape::Icosphere { let isphere = shape::Icosphere {
radius: PLANET_RADIUS, radius: PLANET_RADIUS,
subdivisions: 26, subdivisions: 26,
@ -37,7 +35,7 @@ fn spawn_giant_sphere(
mesh: meshes.add(pmesh), mesh: meshes.add(pmesh),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: color, base_color: color,
metallic: 0.65, metallic: 0.1,
perceptual_roughness: 0.3, perceptual_roughness: 0.3,
alpha_mode: AlphaMode::Blend, alpha_mode: AlphaMode::Blend,
..Default::default() ..Default::default()
@ -92,17 +90,20 @@ fn gen_planet(sphere: Icosphere) -> Mesh {
// TODO: use displaced points for normals by replacing raw_points with // TODO: use displaced points for normals by replacing raw_points with
// noise-displaced points. // noise-displaced points.
let noise = HybridMulti::<Perlin>::default(); let noise = HybridMulti::<Perlin>::default();
let raw_points = generated.raw_points();
let raw_points = generated
.raw_points()
.iter()
.map(|&p| {
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.07;
let pt = p + disp;
pt.into()
})
.collect::<Vec<[f32; 3]>>();
let points = raw_points let points = raw_points
.iter() .iter()
.map(|&p| { .map(|&p| (Vec3::from_slice(&p) * sphere.radius).into())
let pt = p * sphere.radius;
let disp = noise.get(pt.as_dvec3().into()) as f32;
let disp = p * disp * 20.0;
let pt = pt + disp;
pt.into()
})
.collect::<Vec<[f32; 3]>>(); .collect::<Vec<[f32; 3]>>();
let normals = raw_points let normals = raw_points

View File

@ -38,17 +38,23 @@ fn wireframe_planet(
} }
} }
if !pts.is_empty() { let mut verts = Vec::with_capacity((pts.len() as f32 * 1.4) as usize);
commands.spawn_bundle(PolylineBundle { for pts in pts.chunks(3) {
polyline: polylines.add(Polyline { vertices: pts }), if pts.len() > 1 {
material: polymats.add(PolylineMaterial { verts.extend_from_slice(pts);
width: 101.0, verts.push(Vec3::NAN);
color: BISEXY_COLOR, }
perspective: true,
}),
..Default::default()
});
} }
commands.spawn_bundle(PolylineBundle {
polyline: polylines.add(Polyline { vertices: verts }),
material: polymats.add(PolylineMaterial {
width: 101.0,
color: BISEXY_COLOR,
perspective: true,
}),
..Default::default()
});
} }
fn wireframify_lights( fn wireframify_lights(

View File

@ -113,7 +113,7 @@ fn spawn_static_lights(
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.1, brightness: 0.2,
}); });
// up light // up light

View File

@ -12,7 +12,7 @@ use cyber_rider::{
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
sensitivity: 10.0, // default: 1.0 sensitivity: 10.0, // default: 1.0
accel: 20.0, // default: 40.0 accel: 10.0, // default: 40.0
}; };
fn main() { fn main() {
@ -20,6 +20,8 @@ fn main() {
app.insert_resource(Msaa { samples: 4 }) app.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02))) .insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02)))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
//.add_plugin(LogDiagnosticsPlugin::default())
//.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(CyberGeomPlugin) .add_plugin(CyberGeomPlugin)
.add_plugin(CyberGlamorPlugin) .add_plugin(CyberGlamorPlugin)
.add_plugin(CyberInputPlugin) .add_plugin(CyberInputPlugin)