mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Almost make clouds/postproccess run
This commit is contained in:
parent
05bda00431
commit
a6e8a47ada
@ -65,6 +65,7 @@ vec3 wpos_at(vec2 uv) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
// TODO: precompute in the vertex shader?
|
||||
vec2 uv = (f_pos + 1.0) * 0.5;
|
||||
|
||||
vec4 color = texture(sampler2D(t_src_color, s_src_color), uv);
|
||||
|
@ -18,12 +18,16 @@
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
layout(location = 0) in vec2 v_pos;
|
||||
|
||||
layout(location = 0) out vec2 f_pos;
|
||||
|
||||
void main() {
|
||||
// Generate fullscreen triangle
|
||||
vec2 v_pos = vec2(
|
||||
float(gl_VertexIndex / 2) * 4.0 - 1.0,
|
||||
float(gl_VertexIndex % 2) * 4.0 - 1.0
|
||||
);
|
||||
|
||||
f_pos = v_pos;
|
||||
|
||||
gl_Position = vec4(v_pos, -1.0, 1.0);
|
||||
gl_Position = vec4(v_pos, 0.0, 1.0);
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ vec3 wpos_at(vec2 uv) {
|
||||
*/
|
||||
|
||||
void main() {
|
||||
// TODO: precompute in the vertex shader?
|
||||
vec2 uv = (f_pos + 1.0) * 0.5;
|
||||
|
||||
/* if (medium.x == 1u) {
|
||||
|
@ -23,7 +23,13 @@ layout(location = 0) in vec2 v_pos;
|
||||
layout(location = 0) out vec2 f_pos;
|
||||
|
||||
void main() {
|
||||
// Generate fullscreen triangle
|
||||
vec2 v_pos = vec2(
|
||||
float(gl_VertexIndex / 2) * 4.0 - 1.0,
|
||||
float(gl_VertexIndex % 2) * 4.0 - 1.0
|
||||
);
|
||||
|
||||
f_pos = v_pos;
|
||||
|
||||
gl_Position = vec4(v_pos, -1.0, 1.0);
|
||||
gl_Position = vec4(v_pos, 0.0, 1.0);
|
||||
}
|
||||
|
@ -241,8 +241,15 @@ impl PlayState for CharSelectionState {
|
||||
//self.scene
|
||||
// .render(renderer, client.get_tick(), humanoid_body, loadout);
|
||||
|
||||
// Render world
|
||||
/* let mut first_pass = */
|
||||
drawer.first_pass();
|
||||
// Clouds
|
||||
drawer.second_pass().draw_clouds();
|
||||
// PostProcess and UI
|
||||
let mut third_pass = drawer.third_pass();
|
||||
third_pass.draw_post_process();
|
||||
// Draw the UI to the screen.
|
||||
self.char_selection_ui
|
||||
.render(&mut drawer.third_pass().draw_ui());
|
||||
self.char_selection_ui.render(&mut third_pass.draw_ui());
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,7 @@ pub use self::{
|
||||
mesh::{Mesh, Quad, Tri},
|
||||
model::{DynamicModel, Model, SubModel},
|
||||
pipelines::{
|
||||
clouds::{
|
||||
create_mesh as create_clouds_mesh, Locals as CloudsLocals, Vertex as CloudsVertex,
|
||||
},
|
||||
clouds::Locals as CloudsLocals,
|
||||
figure::{
|
||||
BoneData as FigureBoneData, BoneMeshes, FigureLayout, FigureModel,
|
||||
Locals as FigureLocals,
|
||||
@ -29,9 +27,7 @@ pub use self::{
|
||||
fluid::Vertex as FluidVertex,
|
||||
lod_terrain::{LodData, Vertex as LodTerrainVertex},
|
||||
particle::{Instance as ParticleInstance, Vertex as ParticleVertex},
|
||||
postprocess::{
|
||||
create_mesh as create_pp_mesh, Locals as PostProcessLocals, Vertex as PostProcessVertex,
|
||||
},
|
||||
postprocess::Locals as PostProcessLocals,
|
||||
shadow::Locals as ShadowLocals,
|
||||
skybox::{create_mesh as create_skybox_mesh, Vertex as SkyboxVertex},
|
||||
sprite::{Instance as SpriteInstance, Locals as SpriteLocals, Vertex as SpriteVertex},
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
super::{AaMode, Mesh, Tri},
|
||||
super::{AaMode, Bound, Consts, Mesh, Tri},
|
||||
GlobalsLayouts,
|
||||
};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
@ -25,7 +25,7 @@ impl Locals {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/*#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
||||
pub struct Vertex {
|
||||
pos: [f32; 2],
|
||||
@ -62,6 +62,10 @@ pub fn create_mesh() -> Mesh<Vertex> {
|
||||
));
|
||||
|
||||
mesh
|
||||
}*/
|
||||
|
||||
pub struct BindGroup {
|
||||
pub(in super::super) bind_group: wgpu::BindGroup,
|
||||
}
|
||||
|
||||
pub struct CloudsLayout {
|
||||
@ -123,6 +127,44 @@ impl CloudsLayout {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bind(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
src_color: &wgpu::TextureView,
|
||||
src_depth: &wgpu::TextureView,
|
||||
sampler: &wgpu::Sampler,
|
||||
locals: &Consts<Locals>,
|
||||
) -> BindGroup {
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: None,
|
||||
layout: &self.layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(src_color),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::TextureView(src_depth),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 3,
|
||||
resource: wgpu::BindingResource::Sampler(sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 4,
|
||||
resource: locals.buf().as_entire_binding(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
BindGroup { bind_group }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CloudsPipeline {
|
||||
@ -134,7 +176,6 @@ impl CloudsPipeline {
|
||||
device: &wgpu::Device,
|
||||
vs_module: &wgpu::ShaderModule,
|
||||
fs_module: &wgpu::ShaderModule,
|
||||
sc_desc: &wgpu::SwapChainDescriptor,
|
||||
global_layout: &GlobalsLayouts,
|
||||
layout: &CloudsLayout,
|
||||
aa_mode: AaMode,
|
||||
@ -166,6 +207,7 @@ impl CloudsPipeline {
|
||||
module: fs_module,
|
||||
entry_point: "main",
|
||||
}),
|
||||
// TODO: this could be None?
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
@ -177,25 +219,15 @@ impl CloudsPipeline {
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
||||
format: wgpu::TextureFormat::Depth24Plus,
|
||||
depth_write_enabled: false,
|
||||
depth_compare: wgpu::CompareFunction::Always,
|
||||
stencil: wgpu::StencilStateDescriptor {
|
||||
front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
||||
back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
||||
read_mask: !0,
|
||||
write_mask: !0,
|
||||
},
|
||||
}),
|
||||
depth_stencil_state: None,
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: &[Vertex::desc()],
|
||||
vertex_buffers: &[/*Vertex::desc()*/],
|
||||
},
|
||||
sample_count: samples,
|
||||
sample_mask: !0,
|
||||
|
@ -290,7 +290,7 @@ impl GlobalsLayouts {
|
||||
binding: 5,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::SampledTexture {
|
||||
component_type: wgpu::TextureComponentType::Float,
|
||||
component_type: wgpu::TextureComponentType::Uint,
|
||||
dimension: wgpu::TextureViewDimension::D2,
|
||||
multisampled: false,
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::super::{AaMode, GlobalsLayouts, Mesh, Tri};
|
||||
use super::super::{AaMode, Bound, Consts, GlobalsLayouts, Mesh, Tri};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use vek::*;
|
||||
|
||||
@ -22,7 +22,7 @@ impl Locals {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/*#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
||||
pub struct Vertex {
|
||||
pub pos: [f32; 2],
|
||||
@ -59,16 +59,20 @@ pub fn create_mesh() -> Mesh<Vertex> {
|
||||
));
|
||||
|
||||
mesh
|
||||
}*/
|
||||
|
||||
pub struct BindGroup {
|
||||
pub(in super::super) bind_group: wgpu::BindGroup,
|
||||
}
|
||||
|
||||
pub struct PostProcessLayout {
|
||||
pub src_color: wgpu::BindGroupLayout,
|
||||
pub layout: wgpu::BindGroupLayout,
|
||||
}
|
||||
|
||||
impl PostProcessLayout {
|
||||
pub fn new(device: &wgpu::Device) -> Self {
|
||||
Self {
|
||||
src_color: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
layout: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: &[
|
||||
// src color
|
||||
@ -119,6 +123,44 @@ impl PostProcessLayout {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bind(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
src_color: &wgpu::TextureView,
|
||||
src_depth: &wgpu::TextureView,
|
||||
sampler: &wgpu::Sampler,
|
||||
locals: &Consts<Locals>,
|
||||
) -> BindGroup {
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: None,
|
||||
layout: &self.layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(src_color),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::TextureView(src_depth),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 3,
|
||||
resource: wgpu::BindingResource::Sampler(sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 4,
|
||||
resource: locals.buf().as_entire_binding(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
BindGroup { bind_group }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PostProcessPipeline {
|
||||
@ -140,7 +182,7 @@ impl PostProcessPipeline {
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Post process pipeline layout"),
|
||||
push_constant_ranges: &[],
|
||||
bind_group_layouts: &[&global_layout.globals, &layout.src_color],
|
||||
bind_group_layouts: &[&global_layout.globals, &layout.layout],
|
||||
});
|
||||
|
||||
let samples = match aa_mode {
|
||||
@ -191,7 +233,7 @@ impl PostProcessPipeline {
|
||||
}),
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: &[Vertex::desc()],
|
||||
vertex_buffers: &[/*Vertex::desc()*/],
|
||||
},
|
||||
sample_count: samples,
|
||||
sample_mask: !0,
|
||||
|
@ -133,18 +133,85 @@ pub struct ShadowMapRenderer {
|
||||
}
|
||||
|
||||
/// A type that stores all the layouts associated with this renderer.
|
||||
pub struct Layouts {
|
||||
// TODO: pub(self)??
|
||||
pub(self) global: GlobalsLayouts,
|
||||
struct Layouts {
|
||||
global: GlobalsLayouts,
|
||||
|
||||
pub(self) clouds: clouds::CloudsLayout,
|
||||
pub(self) figure: figure::FigureLayout,
|
||||
pub(self) fluid: fluid::FluidLayout,
|
||||
pub(self) postprocess: postprocess::PostProcessLayout,
|
||||
pub(self) shadow: shadow::ShadowLayout,
|
||||
pub(self) sprite: sprite::SpriteLayout,
|
||||
pub(self) terrain: terrain::TerrainLayout,
|
||||
pub(self) ui: ui::UiLayout,
|
||||
clouds: clouds::CloudsLayout,
|
||||
figure: figure::FigureLayout,
|
||||
fluid: fluid::FluidLayout,
|
||||
postprocess: postprocess::PostProcessLayout,
|
||||
shadow: shadow::ShadowLayout,
|
||||
sprite: sprite::SpriteLayout,
|
||||
terrain: terrain::TerrainLayout,
|
||||
ui: ui::UiLayout,
|
||||
}
|
||||
|
||||
struct Locals {
|
||||
clouds: Consts<clouds::Locals>,
|
||||
clouds_bind: clouds::BindGroup,
|
||||
|
||||
postprocess: Consts<postprocess::Locals>,
|
||||
postprocess_bind: postprocess::BindGroup,
|
||||
}
|
||||
|
||||
impl Locals {
|
||||
fn new(
|
||||
device: &wgpu::Device,
|
||||
layouts: &Layouts,
|
||||
clouds_locals: Consts<clouds::Locals>,
|
||||
postprocess_locals: Consts<postprocess::Locals>,
|
||||
tgt_color_view: &wgpu::TextureView,
|
||||
tgt_depth_view: &wgpu::TextureView,
|
||||
tgt_color_pp_view: &wgpu::TextureView,
|
||||
sampler: &wgpu::Sampler,
|
||||
) -> Self {
|
||||
let clouds_bind = layouts.clouds.bind(
|
||||
device,
|
||||
tgt_color_view,
|
||||
tgt_depth_view,
|
||||
sampler,
|
||||
&clouds_locals,
|
||||
);
|
||||
let postprocess_bind = layouts.postprocess.bind(
|
||||
device,
|
||||
tgt_color_pp_view,
|
||||
tgt_depth_view,
|
||||
sampler,
|
||||
&postprocess_locals,
|
||||
);
|
||||
|
||||
Self {
|
||||
clouds: clouds_locals,
|
||||
clouds_bind,
|
||||
postprocess: postprocess_locals,
|
||||
postprocess_bind,
|
||||
}
|
||||
}
|
||||
|
||||
fn rebind(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
layouts: &Layouts,
|
||||
tgt_color_view: &wgpu::TextureView,
|
||||
tgt_depth_view: &wgpu::TextureView,
|
||||
tgt_color_pp_view: &wgpu::TextureView,
|
||||
sampler: &wgpu::Sampler,
|
||||
) {
|
||||
self.clouds_bind = layouts.clouds.bind(
|
||||
device,
|
||||
tgt_color_view,
|
||||
tgt_depth_view,
|
||||
sampler,
|
||||
&self.clouds,
|
||||
);
|
||||
self.postprocess_bind = layouts.postprocess.bind(
|
||||
device,
|
||||
tgt_color_pp_view,
|
||||
tgt_depth_view,
|
||||
sampler,
|
||||
&self.postprocess,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A type that encapsulates rendering state. `Renderer` is central to Voxygen's
|
||||
@ -188,6 +255,12 @@ pub struct Renderer {
|
||||
|
||||
shaders: AssetHandle<Shaders>,
|
||||
|
||||
// Note: we keep these here since their bind groups need to be updated if we resize the
|
||||
// color/depth textures
|
||||
locals: Locals,
|
||||
|
||||
shader_reload_indicator: ReloadIndicator,
|
||||
|
||||
noise_tex: Texture,
|
||||
|
||||
mode: RenderMode,
|
||||
@ -375,6 +448,28 @@ impl Renderer {
|
||||
Some(wgpu::AddressMode::Repeat),
|
||||
)?;
|
||||
|
||||
let clouds_locals = {
|
||||
let mut consts = Consts::new(&device, 1);
|
||||
consts.update(&device, &queue, &[clouds::Locals::default()], 0);
|
||||
consts
|
||||
};
|
||||
let postprocess_locals = {
|
||||
let mut consts = Consts::new(&device, 1);
|
||||
consts.update(&device, &queue, &[postprocess::Locals::default()], 0);
|
||||
consts
|
||||
};
|
||||
|
||||
let locals = Locals::new(
|
||||
&device,
|
||||
&layouts,
|
||||
clouds_locals,
|
||||
postprocess_locals,
|
||||
&tgt_color_view,
|
||||
&tgt_depth_view,
|
||||
&tgt_color_pp_view,
|
||||
&sampler,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
device,
|
||||
queue,
|
||||
@ -406,6 +501,8 @@ impl Renderer {
|
||||
postprocess_pipeline,
|
||||
shaders,
|
||||
//player_shadow_pipeline,
|
||||
locals,
|
||||
|
||||
noise_tex,
|
||||
|
||||
mode,
|
||||
@ -459,6 +556,17 @@ impl Renderer {
|
||||
self.tgt_color_view = tgt_color_view;
|
||||
self.tgt_depth_view = tgt_depth_view;
|
||||
self.tgt_color_pp_view = tgt_color_pp_view;
|
||||
// Rebind views to clouds/postprocess bind groups
|
||||
self.locals.rebind(
|
||||
&self.device,
|
||||
&self.layouts,
|
||||
&self.tgt_color_view,
|
||||
&self.tgt_depth_view,
|
||||
&self.tgt_color_pp_view,
|
||||
&self.sampler,
|
||||
);
|
||||
|
||||
// TODO: rebind globals
|
||||
if let (Some(shadow_map), ShadowMode::Map(mode)) =
|
||||
(self.shadow_map.as_mut(), self.mode.shadow)
|
||||
{
|
||||
@ -823,6 +931,7 @@ impl Renderer {
|
||||
"Renderer::start_recording_frame"
|
||||
);
|
||||
|
||||
// TODO: does this make sense here?
|
||||
self.device.poll(wgpu::Maintain::Poll);
|
||||
|
||||
// If the shaders files were changed attempt to recreate the shaders
|
||||
@ -921,10 +1030,22 @@ impl Renderer {
|
||||
}
|
||||
|
||||
/// Update a set of constants with the provided values.
|
||||
pub fn update_consts<T: Copy + bytemuck::Pod>(&mut self, consts: &mut Consts<T>, vals: &[T]) {
|
||||
pub fn update_consts<T: Copy + bytemuck::Pod>(&self, consts: &mut Consts<T>, vals: &[T]) {
|
||||
consts.update(&self.device, &self.queue, vals, 0)
|
||||
}
|
||||
|
||||
pub fn update_clouds_locals(&mut self, new_val: clouds::Locals) {
|
||||
self.locals
|
||||
.clouds
|
||||
.update(&self.device, &self.queue, &[new_val], 0)
|
||||
}
|
||||
|
||||
pub fn update_postprocess_locals(&mut self, new_val: postprocess::Locals) {
|
||||
self.locals
|
||||
.postprocess
|
||||
.update(&self.device, &self.queue, &[new_val], 0)
|
||||
}
|
||||
|
||||
/// Create a new set of instances with the provided values.
|
||||
pub fn create_instances<T: Copy + bytemuck::Pod>(
|
||||
&mut self,
|
||||
@ -2048,7 +2169,7 @@ fn create_pipelines(
|
||||
device,
|
||||
&create_shader("clouds-vert", ShaderKind::Vertex)?,
|
||||
&create_shader("clouds-frag", ShaderKind::Fragment)?,
|
||||
sc_desc,
|
||||
// TODO: pass in format of intermediate color buffer
|
||||
&layouts.global,
|
||||
&layouts.clouds,
|
||||
mode.aa,
|
||||
|
@ -5,7 +5,8 @@ use super::{
|
||||
instances::Instances,
|
||||
model::{DynamicModel, Model},
|
||||
pipelines::{
|
||||
figure, fluid, postprocess, sprite, terrain, ui, GlobalsBindGroup, Light, Shadow,
|
||||
clouds, figure, fluid, postprocess, sprite, terrain, ui, GlobalsBindGroup, Light,
|
||||
Shadow,
|
||||
},
|
||||
},
|
||||
Renderer,
|
||||
@ -36,8 +37,8 @@ impl<'a> Drawer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/*pub fn first_pass(&mut self) -> FirstPassDrawer {
|
||||
let render_pass =
|
||||
pub fn first_pass(&mut self) -> FirstPassDrawer {
|
||||
let mut render_pass =
|
||||
self.encoder
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@ -45,19 +46,19 @@ impl<'a> Drawer<'a> {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &self.renderer.tgt_color_view,
|
||||
resolve_target: None,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_color: wgpu::Color::TRANSPARENT,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(
|
||||
wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.renderer.depth_stencil_texture.view,
|
||||
depth_load_op: wgpu::LoadOp::Clear,
|
||||
depth_store_op: wgpu::StoreOp::Store,
|
||||
clear_depth: 1.0,
|
||||
stencil_load_op: wgpu::LoadOp::Clear,
|
||||
stencil_store_op: wgpu::StoreOp::Store,
|
||||
clear_stencil: 0,
|
||||
attachment: &self.renderer.tgt_depth_view,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
},
|
||||
),
|
||||
});
|
||||
@ -71,7 +72,7 @@ impl<'a> Drawer<'a> {
|
||||
}
|
||||
|
||||
pub fn second_pass(&mut self) -> SecondPassDrawer {
|
||||
let render_pass =
|
||||
let mut render_pass =
|
||||
self.encoder
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@ -79,9 +80,10 @@ impl<'a> Drawer<'a> {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &self.renderer.tgt_color_pp_view,
|
||||
resolve_target: None,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_color: wgpu::Color::TRANSPARENT,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
@ -92,7 +94,7 @@ impl<'a> Drawer<'a> {
|
||||
render_pass,
|
||||
renderer: &self.renderer,
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub fn third_pass(&mut self) -> ThirdPassDrawer {
|
||||
let mut render_pass =
|
||||
@ -126,26 +128,27 @@ impl<'a> Drawer<'a> {
|
||||
ThirdPassDrawer {
|
||||
render_pass,
|
||||
renderer: &self.renderer,
|
||||
//postprocess_locals: &self.postprocess_locals,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for Drawer<'a> {
|
||||
fn drop(&mut self) {
|
||||
// TODO: submitting things to the queue can let the gpu start on them sooner
|
||||
// maybe we should submit each render pass to the queue as they are produced?
|
||||
self.renderer
|
||||
.queue
|
||||
.submit(std::iter::once(self.encoder.take().unwrap().finish()));
|
||||
}
|
||||
}
|
||||
|
||||
/*pub struct FirstPassDrawer<'a> {
|
||||
pub struct FirstPassDrawer<'a> {
|
||||
pub(super) render_pass: wgpu::RenderPass<'a>,
|
||||
pub renderer: &'a Renderer,
|
||||
}
|
||||
|
||||
impl<'a> FirstPassDrawer<'a> {
|
||||
pub fn draw_skybox<'b: 'a>(
|
||||
/*pub fn draw_skybox<'b: 'a>(
|
||||
&mut self,
|
||||
model: &'b Model,
|
||||
globals: &'b Consts<Globals>,
|
||||
@ -236,7 +239,7 @@ impl<'a> FirstPassDrawer<'a> {
|
||||
self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0);
|
||||
self.render_pass.set_vertex_buffer(1, &instances.ibuf, 0, 0);
|
||||
self.render_pass.draw(verts, 0..instances.count() as u32);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub struct SecondPassDrawer<'a> {
|
||||
@ -245,40 +248,27 @@ pub struct SecondPassDrawer<'a> {
|
||||
}
|
||||
|
||||
impl<'a> SecondPassDrawer<'a> {
|
||||
pub fn draw_post_process<'b: 'a>(
|
||||
&mut self,
|
||||
model: &'b Model,
|
||||
globals: &'b Consts<Globals>,
|
||||
verts: Range<u32>,
|
||||
) {
|
||||
pub fn draw_clouds<'b: 'a>(&mut self) {
|
||||
self.render_pass
|
||||
.set_pipeline(&self.renderer.postprocess_pipeline.pipeline);
|
||||
self.render_pass.set_bind_group(0, &globals.bind_group, &[]);
|
||||
.set_pipeline(&self.renderer.clouds_pipeline.pipeline);
|
||||
self.render_pass
|
||||
.set_bind_group(1, self.postprocess_locals, &[]);
|
||||
self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0);
|
||||
self.render_pass.draw(verts, 0..1);
|
||||
.set_bind_group(1, &self.renderer.locals.clouds_bind.bind_group, &[]);
|
||||
self.render_pass.draw(0..3, 0..1);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub struct ThirdPassDrawer<'a> {
|
||||
render_pass: wgpu::RenderPass<'a>,
|
||||
renderer: &'a Renderer,
|
||||
//postprocess_locals: &'a wgpu::BindGroup,
|
||||
}
|
||||
|
||||
impl<'a> ThirdPassDrawer<'a> {
|
||||
pub fn draw_post_process<'b: 'a>(
|
||||
&mut self,
|
||||
model: &'b Model<postprocess::Vertex>,
|
||||
verts: Range<u32>,
|
||||
) {
|
||||
pub fn draw_post_process<'b: 'a>(&mut self) {
|
||||
self.render_pass
|
||||
.set_pipeline(&self.renderer.postprocess_pipeline.pipeline);
|
||||
//self.render_pass
|
||||
// .set_bind_group(1, self.postprocess_locals, &[]);
|
||||
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||
self.render_pass.draw(verts, 0..1);
|
||||
self.render_pass
|
||||
.set_bind_group(1, &self.renderer.locals.postprocess_bind.bind_group, &[]);
|
||||
self.render_pass.draw(0..3, 0..1);
|
||||
}
|
||||
|
||||
pub fn draw_ui<'c>(&'c mut self) -> UiDrawer<'c, 'a> {
|
||||
|
@ -16,9 +16,8 @@ pub use self::{
|
||||
use crate::{
|
||||
audio::{ambient::AmbientMgr, music::MusicMgr, sfx::SfxMgr, AudioFrontend},
|
||||
render::{
|
||||
create_clouds_mesh, create_pp_mesh, create_skybox_mesh, CloudsLocals, CloudsVertex, Consts,
|
||||
GlobalModel, Globals, GlobalsBindGroup, Light, Model, PostProcessLocals, PostProcessVertex,
|
||||
Renderer, Shadow, ShadowLocals, SkyboxVertex,
|
||||
create_skybox_mesh, CloudsLocals, Consts, GlobalModel, Globals, GlobalsBindGroup, Light,
|
||||
Model, PostProcessLocals, Renderer, Shadow, ShadowLocals, SkyboxVertex,
|
||||
},
|
||||
settings::Settings,
|
||||
window::{AnalogGameInput, Event},
|
||||
@ -70,16 +69,6 @@ struct Skybox {
|
||||
model: Model<SkyboxVertex>,
|
||||
}
|
||||
|
||||
struct Clouds {
|
||||
model: Model<CloudsVertex>,
|
||||
locals: Consts<CloudsLocals>,
|
||||
}
|
||||
|
||||
struct PostProcess {
|
||||
model: Model<PostProcessVertex>,
|
||||
locals: Consts<PostProcessLocals>,
|
||||
}
|
||||
|
||||
pub struct Scene {
|
||||
data: GlobalModel,
|
||||
globals_bind_group: GlobalsBindGroup,
|
||||
@ -88,8 +77,6 @@ pub struct Scene {
|
||||
event_lights: Vec<EventLight>,
|
||||
|
||||
skybox: Skybox,
|
||||
clouds: Clouds,
|
||||
postprocess: PostProcess,
|
||||
terrain: Terrain<TerrainChunk>,
|
||||
pub lod: Lod,
|
||||
loaded_distance: f32,
|
||||
@ -298,14 +285,6 @@ impl Scene {
|
||||
skybox: Skybox {
|
||||
model: renderer.create_model(&create_skybox_mesh()).unwrap(),
|
||||
},
|
||||
clouds: Clouds {
|
||||
model: renderer.create_model(&create_clouds_mesh()).unwrap(),
|
||||
locals: renderer.create_consts(&[CloudsLocals::default()]),
|
||||
},
|
||||
postprocess: PostProcess {
|
||||
model: renderer.create_model(&create_pp_mesh()).unwrap(),
|
||||
locals: renderer.create_consts(&[PostProcessLocals::default()]),
|
||||
},
|
||||
terrain: Terrain::new(renderer, sprite_render_context),
|
||||
lod,
|
||||
loaded_distance: 0.0,
|
||||
@ -665,14 +644,8 @@ impl Scene {
|
||||
self.camera.get_mode(),
|
||||
scene_data.sprite_render_distance as f32 - 20.0,
|
||||
)]);
|
||||
renderer.update_consts(&mut self.clouds.locals, &[CloudsLocals::new(
|
||||
proj_mat_inv,
|
||||
view_mat_inv,
|
||||
)]);
|
||||
renderer.update_consts(&mut self.postprocess.locals, &[PostProcessLocals::new(
|
||||
proj_mat_inv,
|
||||
view_mat_inv,
|
||||
)]);
|
||||
renderer.update_clouds_locals(CloudsLocals::new(proj_mat_inv, view_mat_inv));
|
||||
renderer.update_postprocess_locals(PostProcessLocals::new(proj_mat_inv, view_mat_inv));
|
||||
|
||||
// Maintain LoD.
|
||||
self.lod.maintain(renderer);
|
||||
@ -1081,21 +1054,5 @@ impl Scene {
|
||||
|
||||
// Render particle effects.
|
||||
self.particle_mgr.render(renderer, scene_data, global, lod);
|
||||
|
||||
// TODO:
|
||||
// // Render clouds (a post-processing effect)
|
||||
// renderer.render_clouds(
|
||||
// &self.clouds.model,
|
||||
// &global.globals,
|
||||
// &self.clouds.locals,
|
||||
// self.lod.get_data(),
|
||||
// );
|
||||
|
||||
// renderer.render_post_process(
|
||||
// &self.postprocess.model,
|
||||
// &global.globals,
|
||||
// &self.postprocess.locals,
|
||||
// self.lod.get_data(),
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
use crate::{
|
||||
mesh::{greedy::GreedyMesh, segment::generate_mesh_base_vol_terrain},
|
||||
render::{
|
||||
create_clouds_mesh, create_pp_mesh, create_skybox_mesh, BoneMeshes, CloudsLocals,
|
||||
CloudsVertex, Consts, FigureModel, GlobalModel, Globals, GlobalsBindGroup, Light, LodData,
|
||||
Mesh, Model, PostProcessLocals, PostProcessVertex, Renderer, Shadow, ShadowLocals,
|
||||
create_skybox_mesh, BoneMeshes, Consts, FigureModel, GlobalModel, Globals,
|
||||
GlobalsBindGroup, Light, LodData, Mesh, Model, Renderer, Shadow, ShadowLocals,
|
||||
SkyboxVertex, TerrainVertex,
|
||||
},
|
||||
scene::{
|
||||
@ -57,24 +56,12 @@ struct Skybox {
|
||||
model: Model<SkyboxVertex>,
|
||||
}
|
||||
|
||||
struct PostProcess {
|
||||
model: Model<PostProcessVertex>,
|
||||
locals: Consts<PostProcessLocals>,
|
||||
}
|
||||
|
||||
struct Clouds {
|
||||
model: Model<CloudsVertex>,
|
||||
locals: Consts<CloudsLocals>,
|
||||
}
|
||||
|
||||
pub struct Scene {
|
||||
data: GlobalModel,
|
||||
globals_bind_group: GlobalsBindGroup,
|
||||
camera: Camera,
|
||||
|
||||
skybox: Skybox,
|
||||
clouds: Clouds,
|
||||
postprocess: PostProcess,
|
||||
lod: LodData,
|
||||
map_bounds: Vec2<f32>,
|
||||
|
||||
@ -134,14 +121,6 @@ impl Scene {
|
||||
skybox: Skybox {
|
||||
model: renderer.create_model(&create_skybox_mesh()).unwrap(),
|
||||
},
|
||||
clouds: Clouds {
|
||||
model: renderer.create_model(&create_clouds_mesh()).unwrap(),
|
||||
locals: renderer.create_consts(&[CloudsLocals::default()]),
|
||||
},
|
||||
postprocess: PostProcess {
|
||||
model: renderer.create_model(&create_pp_mesh()).unwrap(),
|
||||
locals: renderer.create_consts(&[PostProcessLocals::default()]),
|
||||
},
|
||||
lod,
|
||||
map_bounds,
|
||||
|
||||
|
@ -1427,8 +1427,16 @@ impl PlayState for SessionState {
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Render world
|
||||
/* let mut first_pass = */
|
||||
drawer.first_pass();
|
||||
// Clouds
|
||||
drawer.second_pass().draw_clouds();
|
||||
// PostProcess and UI
|
||||
let mut third_pass = drawer.third_pass();
|
||||
third_pass.draw_post_process();
|
||||
// Draw the UI to the screen
|
||||
self.hud.render(&mut drawer.third_pass().draw_ui());
|
||||
self.hud.render(&mut third_pass.draw_ui());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -764,7 +764,7 @@ impl IcedRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render<'pass, 'data: 'pass>(&'data self, drawer: &mut UiDrawer<'_, 'pass>) {
|
||||
pub fn render<'a>(&'a self, drawer: &mut UiDrawer<'_, 'a>) {
|
||||
span!(_guard, "render", "IcedRenderer::render");
|
||||
let mut drawer = drawer.prepare(&self.interface_locals, &self.model, self.window_scissor);
|
||||
for draw_command in self.draw_commands.iter() {
|
||||
|
Loading…
Reference in New Issue
Block a user