Skip to content

Commit

Permalink
feat: initial plucker pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Jun 30, 2024
1 parent 2e2063f commit eead2c7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use bevy::prelude::*;

use material::ZeroverseMaterialPlugin;

pub mod manifold;
pub mod material;
pub mod plucker;


pub struct BevyZeroversePlugin;
Expand All @@ -12,6 +11,9 @@ impl Plugin for BevyZeroversePlugin {
fn build(&self, app: &mut App) {
info!("initializing BevyZeroversePlugin...");

app.add_plugins(ZeroverseMaterialPlugin);
app.add_plugins((
material::ZeroverseMaterialPlugin,
plucker::PluckerPlugin,
));
}
}
48 changes: 48 additions & 0 deletions src/plucker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use bevy::{
prelude::*,
asset::load_internal_asset,
render::{
extract_component::{
ExtractComponent,
ExtractComponentPlugin,
},
render_resource::AsBindGroup,
},
};


const PLUCKER_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(566172342);

pub struct PluckerPlugin;
impl Plugin for PluckerPlugin {
fn build(&self, app: &mut App) {
load_internal_asset!(
app,
PLUCKER_SHADER_HANDLE,
"plucker.wgsl",
Shader::from_wgsl
);

app.add_plugins(ExtractComponentPlugin::<PluckerOutput>::default());
app.register_type::<PluckerOutput>();

// let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
// return;
// };

// TODO: add plucker pipeline to core_3d graph
}
}


#[derive(AsBindGroup, Clone, Component, Debug, ExtractComponent, Reflect)]
pub struct PluckerOutput {
#[storage_texture(0, image_format = Bgra8Unorm, access = WriteOnly)]
pub plucker_u: Handle<Image>,

#[storage_texture(1, image_format = Bgra8Unorm, access = WriteOnly)]
pub plucker_v: Handle<Image>,

#[storage_texture(2, image_format = Bgra8Unorm, access = WriteOnly)]
pub visualization: Handle<Image>,
}
22 changes: 19 additions & 3 deletions src/plucker.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@


@group(0) @binding(0) var<uniform> view: View;
@group(1) @binding(0) var<storage, write> output_texture : texture_storage_2d<rgba32float, write>;

@group(1) @binding(0) var<storage, write> plucker_u_texture : texture_storage_2d<rgba32float, write>;
@group(1) @binding(1) var<storage, write> plucker_v_texture : texture_storage_2d<rgba32float, write>;
@group(1) @binding(2) var<storage, write> plucker_visual_texture : texture_storage_2d<rgba32float, write>;


fn get_st(global_invocation_id: vec3<u32>) -> vec2<f32> {
Expand Down Expand Up @@ -38,6 +41,19 @@ fn plucker_kernel(@builtin(global_invocation_id) gid : vec3<u32>) {
let plucker_u = cross(rays_o, normalized_rays_d);
let plucker_v = normalized_rays_d;

let output_color = vec4<f32>(plucker_u, 1.0);
textureStore(output_texture, gid.xy, output_color);
textureStore(
plucker_u_texture,
gid.xy,
vec4<f32>(plucker_u, 1.0),
);
textureStore(
plucker_v_texture,
gid.xy,
vec4<f32>(plucker_v, 1.0),
);
textureStore(
plucker_visual_texture,
gid.xy,
vec4<f32>(plucker_v * 0.5 + 0.5, 1.0),
);
}

0 comments on commit eead2c7

Please sign in to comment.