mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Draw water
This commit is contained in:
parent
2534e65d0e
commit
95cc5da1e4
@ -24,7 +24,7 @@ pub use self::{
|
|||||||
BoneData as FigureBoneData, BoneMeshes, FigureLayout, FigureModel,
|
BoneData as FigureBoneData, BoneMeshes, FigureLayout, FigureModel,
|
||||||
Locals as FigureLocals,
|
Locals as FigureLocals,
|
||||||
},
|
},
|
||||||
fluid::Vertex as FluidVertex,
|
fluid::{BindGroup as FluidWaves, Vertex as FluidVertex},
|
||||||
lod_terrain::{LodData, Vertex as LodTerrainVertex},
|
lod_terrain::{LodData, Vertex as LodTerrainVertex},
|
||||||
particle::{Instance as ParticleInstance, Vertex as ParticleVertex},
|
particle::{Instance as ParticleInstance, Vertex as ParticleVertex},
|
||||||
postprocess::Locals as PostProcessLocals,
|
postprocess::Locals as PostProcessLocals,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::super::{AaMode, GlobalsLayouts, TerrainLayout};
|
use super::super::{AaMode, GlobalsLayouts, TerrainLayout, Texture};
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -43,6 +43,11 @@ impl Vertex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct BindGroup {
|
||||||
|
pub(in super::super) bind_group: wgpu::BindGroup,
|
||||||
|
waves: Texture,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FluidLayout {
|
pub struct FluidLayout {
|
||||||
pub waves: wgpu::BindGroupLayout,
|
pub waves: wgpu::BindGroupLayout,
|
||||||
}
|
}
|
||||||
@ -76,6 +81,25 @@ impl FluidLayout {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bind(&self, device: &wgpu::Device, waves: Texture) -> BindGroup {
|
||||||
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
|
label: None,
|
||||||
|
layout: &self.waves,
|
||||||
|
entries: &[
|
||||||
|
wgpu::BindGroupEntry {
|
||||||
|
binding: 0,
|
||||||
|
resource: wgpu::BindingResource::TextureView(&waves.view),
|
||||||
|
},
|
||||||
|
wgpu::BindGroupEntry {
|
||||||
|
binding: 1,
|
||||||
|
resource: wgpu::BindingResource::Sampler(&waves.sampler),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
BindGroup { bind_group, waves }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FluidPipeline {
|
pub struct FluidPipeline {
|
||||||
|
@ -15,7 +15,6 @@ use crate::scene::camera::CameraMode;
|
|||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use common::terrain::BlockKind;
|
use common::terrain::BlockKind;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use wgpu::BindGroup;
|
|
||||||
|
|
||||||
pub const MAX_POINT_LIGHT_COUNT: usize = 31;
|
pub const MAX_POINT_LIGHT_COUNT: usize = 31;
|
||||||
pub const MAX_FIGURE_SHADOW_COUNT: usize = 24;
|
pub const MAX_FIGURE_SHADOW_COUNT: usize = 24;
|
||||||
@ -243,7 +242,7 @@ pub struct GlobalsLayouts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ColLights<Locals> {
|
pub struct ColLights<Locals> {
|
||||||
pub bind_group: BindGroup,
|
pub bind_group: wgpu::BindGroup,
|
||||||
pub texture: Texture,
|
pub texture: Texture,
|
||||||
phantom: std::marker::PhantomData<Locals>,
|
phantom: std::marker::PhantomData<Locals>,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use super::{
|
use super::{
|
||||||
super::{
|
super::{
|
||||||
consts::Consts,
|
consts::Consts,
|
||||||
pipelines::{figure, lod_terrain, terrain, ui, ColLights, GlobalModel, GlobalsBindGroup},
|
pipelines::{
|
||||||
|
figure, fluid, lod_terrain, terrain, ui, ColLights, GlobalModel, GlobalsBindGroup,
|
||||||
|
},
|
||||||
texture::Texture,
|
texture::Texture,
|
||||||
},
|
},
|
||||||
Renderer,
|
Renderer,
|
||||||
@ -64,4 +66,8 @@ impl Renderer {
|
|||||||
pub fn terrain_bind_col_light(&self, col_light: Texture) -> ColLights<terrain::Locals> {
|
pub fn terrain_bind_col_light(&self, col_light: Texture) -> ColLights<terrain::Locals> {
|
||||||
self.layouts.global.bind_col_light(&self.device, col_light)
|
self.layouts.global.bind_col_light(&self.device, col_light)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fluid_bind_waves(&self, texture: Texture) -> fluid::BindGroup {
|
||||||
|
self.layouts.fluid.bind(&self.device, texture)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,28 +181,16 @@ impl<'a> FirstPassDrawer<'a> {
|
|||||||
self.render_pass.draw(0..model.len() as u32, 0..1)
|
self.render_pass.draw(0..model.len() as u32, 0..1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn draw_fluid<'b: 'a>(
|
pub fn draw_particles(&mut self) -> ParticleDrawer<'_, 'a> {
|
||||||
&mut self,
|
|
||||||
model: &'b Model,
|
|
||||||
locals: &'b Consts<terrain::Locals>,
|
|
||||||
waves: &'b Consts<fluid::Locals>,
|
|
||||||
globals: &'b Consts<Globals>,
|
|
||||||
lights: &'b Consts<Light>,
|
|
||||||
shadows: &'b Consts<Shadow>,
|
|
||||||
verts: Range<u32>,
|
|
||||||
) {
|
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.set_pipeline(&self.renderer.fluid_pipeline.pipeline);
|
.set_pipeline(&self.renderer.particle_pipeline.pipeline);
|
||||||
self.render_pass.set_bind_group(0, &globals.bind_group, &[]);
|
|
||||||
self.render_pass.set_bind_group(1, &lights.bind_group, &[]);
|
ParticleDrawer {
|
||||||
self.render_pass.set_bind_group(2, &shadows.bind_group, &[]);
|
render_pass: &mut self.render_pass,
|
||||||
self.render_pass.set_bind_group(3, &locals.bind_group, &[]);
|
}
|
||||||
self.render_pass.set_bind_group(4, &waves.bind_group, &[]);
|
|
||||||
self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0);
|
|
||||||
self.render_pass.draw(verts, 0..1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_sprite<'b: 'a>(
|
/*pub fn draw_sprite<'b: 'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
model: &'b Model,
|
model: &'b Model,
|
||||||
instances: &'a Instances<sprite::Instance>,
|
instances: &'a Instances<sprite::Instance>,
|
||||||
@ -221,11 +209,12 @@ impl<'a> FirstPassDrawer<'a> {
|
|||||||
self.render_pass.draw(verts, 0..instances.count() as u32);
|
self.render_pass.draw(verts, 0..instances.count() as u32);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
pub fn draw_particles<'c>(&'c mut self) -> ParticleDrawer<'c, 'a> {
|
pub fn draw_fluid<'b: 'a>(&mut self, waves: &'b fluid::BindGroup) -> FluidDrawer<'_, 'a> {
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.set_pipeline(&self.renderer.particle_pipeline.pipeline);
|
.set_pipeline(&self.renderer.fluid_pipeline.pipeline);
|
||||||
|
self.render_pass.set_bind_group(1, &waves.bind_group, &[]);
|
||||||
|
|
||||||
ParticleDrawer {
|
FluidDrawer {
|
||||||
render_pass: &mut self.render_pass,
|
render_pass: &mut self.render_pass,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +225,7 @@ pub struct ParticleDrawer<'pass_ref, 'pass: 'pass_ref> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'pass_ref, 'pass: 'pass_ref> ParticleDrawer<'pass_ref, 'pass> {
|
impl<'pass_ref, 'pass: 'pass_ref> ParticleDrawer<'pass_ref, 'pass> {
|
||||||
// Note: if we ever need to draw less than the whole model, this api can be
|
// Note: if we ever need to draw less than the whole model, these APIs can be
|
||||||
// changed
|
// changed
|
||||||
pub fn draw<'data: 'pass>(
|
pub fn draw<'data: 'pass>(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -252,6 +241,22 @@ impl<'pass_ref, 'pass: 'pass_ref> ParticleDrawer<'pass_ref, 'pass> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FluidDrawer<'pass_ref, 'pass: 'pass_ref> {
|
||||||
|
render_pass: &'pass_ref mut wgpu::RenderPass<'pass>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'pass_ref, 'pass: 'pass_ref> FluidDrawer<'pass_ref, 'pass> {
|
||||||
|
pub fn draw<'data: 'pass>(
|
||||||
|
&mut self,
|
||||||
|
model: &'data Model<fluid::Vertex>,
|
||||||
|
locals: &'data terrain::BoundLocals,
|
||||||
|
) {
|
||||||
|
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||||
|
self.render_pass.set_bind_group(2, &locals.bind_group, &[]);
|
||||||
|
self.render_pass.draw(0..model.len() as u32, 0..1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SecondPassDrawer<'a> {
|
pub struct SecondPassDrawer<'a> {
|
||||||
pub(super) render_pass: wgpu::RenderPass<'a>,
|
pub(super) render_pass: wgpu::RenderPass<'a>,
|
||||||
pub renderer: &'a Renderer,
|
pub renderer: &'a Renderer,
|
||||||
|
@ -1020,7 +1020,7 @@ impl Scene {
|
|||||||
self.figure_mgr
|
self.figure_mgr
|
||||||
.render_player(drawer, state, player_entity, tick, global, lod, camera_data);
|
.render_player(drawer, state, player_entity, tick, global, lod, camera_data);
|
||||||
|
|
||||||
self.terrain.render(drawer, global, lod, focus_pos);
|
self.terrain.render(drawer, focus_pos);
|
||||||
|
|
||||||
/* self.figure_mgr.render(
|
/* self.figure_mgr.render(
|
||||||
renderer,
|
renderer,
|
||||||
@ -1037,14 +1037,12 @@ impl Scene {
|
|||||||
// Render the skybox.
|
// Render the skybox.
|
||||||
drawer.draw_skybox(&self.skybox.model);
|
drawer.draw_skybox(&self.skybox.model);
|
||||||
|
|
||||||
/*self.terrain.render_translucent(
|
self.terrain.render_translucent(
|
||||||
renderer,
|
drawer,
|
||||||
global,
|
|
||||||
lod,
|
|
||||||
focus_pos,
|
focus_pos,
|
||||||
cam_pos,
|
cam_pos,
|
||||||
scene_data.sprite_render_distance,
|
scene_data.sprite_render_distance,
|
||||||
);*/
|
);
|
||||||
|
|
||||||
// Render particle effects.
|
// Render particle effects.
|
||||||
self.particle_mgr
|
self.particle_mgr
|
||||||
|
@ -9,9 +9,9 @@ use crate::{
|
|||||||
},
|
},
|
||||||
render::{
|
render::{
|
||||||
pipelines::{self, ColLights},
|
pipelines::{self, ColLights},
|
||||||
ColLightInfo, Consts, FirstPassDrawer, FluidVertex, GlobalModel, Instances, LodData, Mesh,
|
ColLightInfo, Consts, FirstPassDrawer, FluidVertex, FluidWaves, GlobalModel, Instances,
|
||||||
Model, RenderError, Renderer, SpriteInstance, SpriteLocals, SpriteVertex, TerrainLocals,
|
LodData, Mesh, Model, RenderError, Renderer, SpriteInstance, SpriteLocals, SpriteVertex,
|
||||||
TerrainVertex, Texture,
|
TerrainLocals, TerrainVertex, Texture,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ pub struct Terrain<V: RectRasterableVol = TerrainChunk> {
|
|||||||
/// for any particular chunk; look at the `texture` field in
|
/// for any particular chunk; look at the `texture` field in
|
||||||
/// `TerrainChunkData` for that.
|
/// `TerrainChunkData` for that.
|
||||||
col_lights: ColLights<pipelines::terrain::Locals>,
|
col_lights: ColLights<pipelines::terrain::Locals>,
|
||||||
waves: Texture,
|
waves: FluidWaves,
|
||||||
|
|
||||||
phantom: PhantomData<V>,
|
phantom: PhantomData<V>,
|
||||||
}
|
}
|
||||||
@ -564,13 +564,17 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
mesh_recv_overflow: 0.0,
|
mesh_recv_overflow: 0.0,
|
||||||
sprite_data: sprite_render_context.sprite_data,
|
sprite_data: sprite_render_context.sprite_data,
|
||||||
sprite_col_lights: sprite_render_context.sprite_col_lights,
|
sprite_col_lights: sprite_render_context.sprite_col_lights,
|
||||||
waves: renderer
|
waves: {
|
||||||
.create_texture(
|
let waves_tex = renderer
|
||||||
&assets::Image::load_expect("voxygen.texture.waves").read().0,
|
.create_texture(
|
||||||
Some(wgpu::FilterMode::Linear),
|
&assets::Image::load_expect("voxygen.texture.waves").read().0,
|
||||||
Some(wgpu::AddressMode::Repeat),
|
Some(wgpu::FilterMode::Linear),
|
||||||
)
|
Some(wgpu::AddressMode::Repeat),
|
||||||
.expect("Failed to create wave texture"),
|
)
|
||||||
|
.expect("Failed to create wave texture");
|
||||||
|
|
||||||
|
renderer.fluid_bind_waves(waves_tex)
|
||||||
|
},
|
||||||
col_lights,
|
col_lights,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -1454,13 +1458,7 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<'a>(
|
pub fn render<'a>(&'a self, drawer: &mut FirstPassDrawer<'a>, focus_pos: Vec3<f32>) {
|
||||||
&'a self,
|
|
||||||
drawer: &mut FirstPassDrawer<'a>,
|
|
||||||
global: &GlobalModel,
|
|
||||||
lod: &LodData,
|
|
||||||
focus_pos: Vec3<f32>,
|
|
||||||
) {
|
|
||||||
span!(_guard, "render", "Terrain::render");
|
span!(_guard, "render", "Terrain::render");
|
||||||
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
|
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
|
||||||
(e as i32).div_euclid(sz as i32)
|
(e as i32).div_euclid(sz as i32)
|
||||||
@ -1480,11 +1478,9 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_translucent(
|
pub fn render_translucent<'a>(
|
||||||
&self,
|
&'a self,
|
||||||
renderer: &mut Renderer,
|
drawer: &mut FirstPassDrawer<'a>,
|
||||||
global: &GlobalModel,
|
|
||||||
lod: &LodData,
|
|
||||||
focus_pos: Vec3<f32>,
|
focus_pos: Vec3<f32>,
|
||||||
cam_pos: Vec3<f32>,
|
cam_pos: Vec3<f32>,
|
||||||
sprite_render_distance: f32,
|
sprite_render_distance: f32,
|
||||||
@ -1566,6 +1562,8 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
drop(guard);
|
drop(guard);
|
||||||
|
|
||||||
// Translucent
|
// Translucent
|
||||||
|
span!(guard, "Fluid chunks");
|
||||||
|
let mut fluid_drawer = drawer.draw_fluid(&self.waves);
|
||||||
chunk_iter
|
chunk_iter
|
||||||
.clone()
|
.clone()
|
||||||
.filter(|(_, chunk)| chunk.visible.is_visible())
|
.filter(|(_, chunk)| chunk.visible.is_visible())
|
||||||
@ -1579,13 +1577,12 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.rev() // Render back-to-front
|
.rev() // Render back-to-front
|
||||||
.for_each(|(model, locals)| {
|
.for_each(|(model, locals)| {
|
||||||
/*renderer.render_fluid_chunk(
|
fluid_drawer.draw(
|
||||||
model,
|
model,
|
||||||
global,
|
|
||||||
locals,
|
locals,
|
||||||
lod,
|
)
|
||||||
&self.waves,
|
|
||||||
)*/
|
|
||||||
});
|
});
|
||||||
|
drop(fluid_drawer);
|
||||||
|
drop(guard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user