-
Notifications
You must be signed in to change notification settings - Fork 28
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
Showing
7 changed files
with
34 additions
and
301 deletions.
There are no files selected for viewing
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
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
This file was deleted.
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,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() | ||
} | ||
} |
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,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; | ||
} |