Skip to content

Commit

Permalink
Remove custom 3d pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Weasy666 committed Apr 10, 2023
1 parent 5d1b95b commit 92e6a69
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 301 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update bevy to `0.10`
- because `GlobalTransform.translation_mut()` was made private we now replace the `GlobalTransform` of an `Svg` when its `Origin` changes.

### Removed
- custom pipelines for 2D and 3D

## [0.9.0] - 2023-01-17
### Added
- add new examples
Expand Down
5 changes: 0 additions & 5 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ pub enum Stage {
SVG,
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum SvgSystem {
ExtractSvgs,
}

/// A plugin that provides resources and a system to draw [`Svg`]s.
pub struct SvgPlugin;

Expand Down
13 changes: 4 additions & 9 deletions src/render/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::resources::{FillTessellator, StrokeTessellator};
use crate::{resources::{FillTessellator, StrokeTessellator}, prelude::Svg};
use bevy::{
app::{App, Plugin},
asset::Assets,
render::render_resource::Shader,
render::RenderApp,
asset::{Assets, Handle},
};

#[cfg(feature = "2d")]
Expand All @@ -27,10 +25,7 @@ impl Plugin for SvgPlugin {
#[cfg(feature = "2d")]
app.add_plugin(svg2d::RenderPlugin);

// Register our custom draw function and pipeline, and add our render systems
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
#[cfg(feature = "3d")]
render_app.add_plugin(svg3d::RenderPlugin);
}
#[cfg(feature = "3d")]
app.add_plugin(svg3d::RenderPlugin);
}
}
1 change: 0 additions & 1 deletion src/render/svg3d/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::{asset::HandleUntyped, reflect::TypeUuid, render::render_resource::Shader};

mod bundle;
mod pipeline_3d;
mod plugin;

/// Handle to the custom shader with a unique random ID
Expand Down
226 changes: 0 additions & 226 deletions src/render/svg3d/pipeline_3d.rs

This file was deleted.

42 changes: 22 additions & 20 deletions src/render/svg3d/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
use bevy::{
app::{App, IntoSystemAppConfig, Plugin},
core_pipeline::core_3d::Transparent3d,
ecs::schedule::IntoSystemConfig,
render::{
ExtractSchedule,
render_phase::AddRenderCommand, render_resource::SpecializedRenderPipelines, RenderSet,
},
app::{App, Plugin},
asset::{AddAsset, load_internal_asset},
pbr::{Material, MaterialPlugin},
render::render_resource::{Shader, ShaderRef},
};

use crate::{render::svg3d::pipeline_3d, plugin::SvgSystem};
use crate::svg::Svg;

use super::SVG_3D_SHADER_HANDLE;

/// Plugin that renders [`Svg`](crate::svg::Svg)s in 2D
pub struct RenderPlugin;

impl Plugin for RenderPlugin {
fn build(&self, app: &mut App) {
// Register our custom draw function and pipeline, and add our render systems
app.init_resource::<pipeline_3d::Svg3dPipeline>()
.init_resource::<SpecializedRenderPipelines<pipeline_3d::Svg3dPipeline>>()
.add_render_command::<Transparent3d, pipeline_3d::DrawSvg3d>()
.add_system(
pipeline_3d::extract_svg_3d
.in_set(SvgSystem::ExtractSvgs)
.in_schedule(ExtractSchedule),
)
.add_system(
pipeline_3d::queue_svg_3d.in_set(RenderSet::Queue)
);
load_internal_asset!(
app,
SVG_3D_SHADER_HANDLE,
"svg_3d.wgsl",
Shader::from_wgsl
);

app.add_plugin(MaterialPlugin::<Svg>::default())
.register_asset_reflect::<Svg>();
}
}

impl Material for Svg {
fn fragment_shader() -> ShaderRef {
SVG_3D_SHADER_HANDLE.typed().into()
}
}
45 changes: 5 additions & 40 deletions src/render/svg3d/svg_3d.wgsl
Original file line number Diff line number Diff line change
@@ -1,49 +1,14 @@
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::mesh_types
@group(1) @binding(0)
var<uniform> mesh: Mesh;

// struct SvgMaterial {
// color: vec4<u32>,
// };
// @group(1) @binding(0)
// var<uniform> material: SvgMaterial;

// NOTE: Bindings must come before functions that use them!
#import bevy_pbr::mesh_functions

// The structure of the SVG vertex buffer as specified in our `SpecializedPipeline`.
struct Vertex {
@location(0) position: vec3<f32>,
@location(1) blend_color: vec4<f32>,
};

struct VertexOutput {
// The vertex shader must set the on-screen position of the vertex.
@builtin(position) clip_position: vec4<f32>,
// Vertex color passed to the framgent shader in location(0).
@location(0) color: vec4<f32>,
};
#import bevy_pbr::mesh_view_bindings

/// Entry point for the vertex shader.
@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
// Project the world position into screen position
out.clip_position = mesh_position_local_to_clip(mesh.model, vec4<f32>(vertex.position, 1.0));
// Unpack the `u32` from the vertex buffer into the `vec4<f32>` used by the fragment shader
out.color = vertex.blend_color;
return out;
}
@group(2) @binding(0)
var<uniform> mesh: Mesh;

// The input of the fragment shader must correspond to the output of the vertex shader for all `location`s
struct FragmentInput {
// The color is interpolated between vertices by default
@location(0) blend_color: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
};

/// Entry point for the fragment shader.
@fragment
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
return in.blend_color;
return in.color;
}

0 comments on commit 92e6a69

Please sign in to comment.