forked from nannou-org/nannou
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d24220a
commit cb03fc8
Showing
26 changed files
with
5,457 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,50 @@ | ||
use bevy::prelude::*; | ||
use bevy_nannou_render::mesh::{Vertex, ViewMesh}; | ||
|
||
struct NannouPlugin; | ||
pub struct NannouPlugin; | ||
|
||
impl Plugin for NannouPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugins(( | ||
app.add_systems(Startup, setup).add_plugins(( | ||
bevy_nannou_render::NannouRenderPlugin, | ||
bevy_nannou_draw::NannouDrawPlugin, | ||
)); | ||
} | ||
} | ||
|
||
fn setup(mut commands: Commands) { | ||
let mut mesh = ViewMesh::default(); | ||
mesh.extend_from_slices( | ||
&[ | ||
Vec3::new(-512.0, -384.0, 0.0), | ||
Vec3::new(-512.0, 384.0, 0.0), | ||
Vec3::new(512.0, 384.0, 0.0), | ||
], | ||
&[0, 1, 2], | ||
&[Vec4::new(1.0, 0.0, 0.0, 1.0); 3], | ||
&[Vec2::new(0.0, 0.0); 3], | ||
); | ||
commands.spawn(( | ||
Camera3dBundle { | ||
transform: Transform::from_xyz(0.0, 0.0, -10.0).looking_at(Vec3::ZERO, Vec3::Z), | ||
projection: OrthographicProjection { | ||
..Default::default() | ||
} | ||
.into(), | ||
..Default::default() | ||
}, | ||
mesh, | ||
)); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use bevy::app::App; | ||
|
||
#[test] | ||
fn it_works() { | ||
let mut app = App::new(); | ||
app.add_plugins(super::NannouPlugin); | ||
app.add_plugins((bevy::DefaultPlugins, super::NannouPlugin)); | ||
app.update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use bevy_nannou::NannouPlugin; | ||
|
||
pub fn main() { | ||
let mut app = bevy::app::App::new(); | ||
app.add_plugins((bevy::DefaultPlugins, NannouPlugin)); | ||
app.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,130 @@ | ||
use bevy::asset::load_internal_asset; | ||
use bevy::core_pipeline::core_3d; | ||
use bevy::core_pipeline::core_3d::CORE_3D; | ||
use bevy::prelude::*; | ||
use bevy::render::{Extract, render_resource as wgpu, RenderSet}; | ||
use bevy::render::{Render, RenderApp}; | ||
use bevy::render::extract_component::ExtractComponentPlugin; | ||
use bevy::render::render_asset::RenderAsset; | ||
use bevy::render::render_graph::{RenderGraphApp, ViewNode, ViewNodeRunner}; | ||
use bevy::render::render_phase::{ | ||
AddRenderCommand, PhaseItem, RenderCommand, | ||
}; | ||
use bevy::render::render_resource::{ | ||
ShaderType, SpecializedRenderPipeline, | ||
SpecializedRenderPipelines, | ||
}; | ||
use bevy::render::renderer::RenderDevice; | ||
use bevy::render::view::ViewUniforms; | ||
|
||
use mesh::ViewMesh; | ||
use pipeline::queue_pipelines; | ||
|
||
use crate::pipeline::{NannouPipeline, NannouViewNode}; | ||
|
||
pub mod mesh; | ||
mod pipeline; | ||
mod text; | ||
// mod reshaper; | ||
|
||
pub struct NannouRenderPlugin; | ||
|
||
pub const NANNOU_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(43700360588854283521); | ||
|
||
impl Plugin for NannouRenderPlugin { | ||
fn build(&self, _app: &mut App) {} | ||
fn build(&self, app: &mut App) { | ||
load_internal_asset!( | ||
app, | ||
NANNOU_SHADER_HANDLE, | ||
"shaders/nannou.wgsl", | ||
Shader::from_wgsl | ||
); | ||
|
||
app | ||
.add_plugins(ExtractComponentPlugin::<ViewMesh>::default()); | ||
|
||
|
||
println!("NannouRenderPlugin::build"); | ||
app.get_sub_app_mut(RenderApp) | ||
.unwrap() | ||
.init_resource::<SpecializedRenderPipelines<NannouPipeline>>() | ||
.add_systems( | ||
Render, | ||
prepare_view_uniform.in_set(RenderSet::PrepareBindGroups), | ||
) | ||
.add_systems( | ||
Render, | ||
queue_pipelines | ||
.in_set(RenderSet::PrepareAssets) | ||
) | ||
.add_render_graph_node::<ViewNodeRunner<NannouViewNode>>( | ||
core_3d::graph::NAME, | ||
NannouViewNode::NAME, | ||
) | ||
.add_render_graph_edges( | ||
CORE_3D, | ||
&[ | ||
core_3d::graph::node::MAIN_TRANSPARENT_PASS, | ||
NannouViewNode::NAME, | ||
core_3d::graph::node::END_MAIN_PASS, | ||
], | ||
); | ||
|
||
bevy_mod_debugdump::print_render_graph(app); | ||
} | ||
|
||
fn finish(&self, app: &mut App) { | ||
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { | ||
return; | ||
}; | ||
|
||
render_app.init_resource::<NannouPipeline>(); | ||
} | ||
} | ||
|
||
fn prepare_view_uniform( | ||
mut commands: Commands, | ||
render_device: Res<RenderDevice>, | ||
pipline: Res<NannouPipeline>, | ||
view_uniforms: Res<ViewUniforms>, | ||
) { | ||
if let Some(binding) = view_uniforms.uniforms.binding() { | ||
commands.insert_resource(ViewUniformBindGroup::new( | ||
&render_device, | ||
&pipline.view_bind_group_layout, | ||
binding, | ||
)); | ||
} | ||
} | ||
#[derive(Resource)] | ||
struct ViewUniformBindGroup { | ||
bind_group: wgpu::BindGroup, | ||
} | ||
|
||
impl ViewUniformBindGroup { | ||
fn new( | ||
device: &RenderDevice, | ||
layout: &wgpu::BindGroupLayout, | ||
binding: wgpu::BindingResource, | ||
) -> ViewUniformBindGroup { | ||
let bind_group = bevy_nannou_wgpu::BindGroupBuilder::new() | ||
.binding(binding) | ||
.build(device, layout); | ||
|
||
ViewUniformBindGroup { bind_group } | ||
} | ||
} | ||
|
||
/// A top-level indicator of whether or not | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | ||
#[repr(u32)] | ||
pub enum VertexMode { | ||
/// Use the color values and ignore the texture coordinates. | ||
Color = 0, | ||
/// Use the texture color and ignore the color values. | ||
Texture = 1, | ||
/// A special mode used by the text primitive. | ||
/// | ||
/// Uses the color values, but multiplies the alpha by the glyph cache texture's red value. | ||
Text = 2, | ||
} |
Oops, something went wrong.