diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 369142cd90..ec371da2e8 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -18,6 +18,7 @@ pub use self::{ create_mesh as create_pp_mesh, Locals as PostProcessLocals, PostProcessPipeline, }, skybox::{create_mesh as create_skybox_mesh, Locals as SkyboxLocals, SkyboxPipeline}, + sprite::{Instance as SpriteInstance, SpritePipeline}, terrain::{Locals as TerrainLocals, TerrainPipeline}, ui::{ create_quad as create_ui_quad, create_tri as create_ui_tri, Locals as UiLocals, diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 08713bfc6b..14ac67169b 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -2,6 +2,7 @@ pub mod figure; pub mod fluid; pub mod postprocess; pub mod skybox; +pub mod sprite; pub mod terrain; pub mod ui; diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs new file mode 100644 index 0000000000..ab2540dc9a --- /dev/null +++ b/voxygen/src/render/pipelines/sprite.rs @@ -0,0 +1,69 @@ +use super::{ + super::{Pipeline, TgtColorFmt, TgtDepthFmt}, + Globals, Light, +}; +use gfx::{ + self, + // Macros + gfx_defines, + gfx_impl_struct_meta, + gfx_pipeline, + gfx_pipeline_inner, + gfx_vertex_struct_meta, +}; +use vek::*; + +gfx_defines! { + vertex Vertex { + pos: [f32; 3] = "v_pos", + norm: [f32; 3] = "v_norm", + col: [f32; 3] = "v_col", + } + + vertex Instance { + inst_pos: [f32; 3] = "inst_pos", + inst_col: [f32; 4] = "inst_col", + } + + pipeline pipe { + vbuf: gfx::VertexBuffer = (), + ibuf: gfx::InstanceBuffer = (), + + globals: gfx::ConstantBuffer = "u_globals", + lights: gfx::ConstantBuffer = "u_lights", + + tgt_color: gfx::RenderTarget = "tgt_color", + tgt_depth: gfx::DepthTarget = gfx::preset::depth::LESS_EQUAL_WRITE, + } +} + +impl Vertex { + pub fn new(pos: Vec3, norm: Vec3, col: Rgb) -> Self { + Self { + pos: pos.into_array(), + col: col.into_array(), + norm: norm.into_array(), + } + } +} + +impl Instance { + pub fn new(inst_pos: Vec3, col: Rgba) -> Self { + Self { + inst_pos: inst_pos.into_array(), + inst_col: col.into_array(), + } + } +} + +impl Default for Instance { + fn default() -> Self { + Self::new(Vec3::zero(), Rgba::broadcast(1.0)) + } +} + +pub struct SpritePipeline; + +impl Pipeline for SpritePipeline { + type Vertex = Vertex; +} diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index e862da5a29..0294364274 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -3,7 +3,7 @@ use super::{ gfx_backend, mesh::Mesh, model::{DynamicModel, Model}, - pipelines::{figure, fluid, postprocess, skybox, terrain, ui, Globals, Light}, + pipelines::{figure, fluid, postprocess, skybox, sprite, terrain, ui, Globals, Light}, texture::Texture, Pipeline, RenderError, }; @@ -65,6 +65,7 @@ pub struct Renderer { figure_pipeline: GfxPipeline>, terrain_pipeline: GfxPipeline>, fluid_pipeline: GfxPipeline>, + sprite_pipeline: GfxPipeline>, ui_pipeline: GfxPipeline>, postprocess_pipeline: GfxPipeline>, @@ -86,6 +87,7 @@ impl Renderer { figure_pipeline, terrain_pipeline, fluid_pipeline, + sprite_pipeline, ui_pipeline, postprocess_pipeline, ) = create_pipelines(&mut factory, &mut shader_reload_indicator)?; @@ -114,6 +116,7 @@ impl Renderer { figure_pipeline, terrain_pipeline, fluid_pipeline, + sprite_pipeline, ui_pipeline, postprocess_pipeline, @@ -201,6 +204,7 @@ impl Renderer { figure_pipeline, terrain_pipeline, fluid_pipeline, + sprite_pipeline, ui_pipeline, postprocess_pipeline, )) => { @@ -208,6 +212,7 @@ impl Renderer { self.figure_pipeline = figure_pipeline; self.terrain_pipeline = terrain_pipeline; self.fluid_pipeline = fluid_pipeline; + self.sprite_pipeline = sprite_pipeline; self.ui_pipeline = ui_pipeline; self.postprocess_pipeline = postprocess_pipeline; } @@ -495,6 +500,7 @@ fn create_pipelines( GfxPipeline>, GfxPipeline>, GfxPipeline>, + GfxPipeline>, GfxPipeline>, GfxPipeline>, ), @@ -571,6 +577,18 @@ fn create_pipelines( gfx::state::CullFace::Nothing, )?; + // Construct a pipeline for rendering sprites + let sprite_pipeline = create_pipeline( + factory, + sprite::pipe::new(), + &assets::load_watched::("voxygen.shaders.sprite-vert", shader_reload_indicator) + .unwrap(), + &assets::load_watched::("voxygen.shaders.sprite-frag", shader_reload_indicator) + .unwrap(), + &include_ctx, + gfx::state::CullFace::Back, + )?; + // Construct a pipeline for rendering UI elements let ui_pipeline = create_pipeline( factory, @@ -606,6 +624,7 @@ fn create_pipelines( figure_pipeline, terrain_pipeline, fluid_pipeline, + sprite_pipeline, ui_pipeline, postprocess_pipeline, ))