mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Sprite distance fading, grass
This commit is contained in:
parent
b31cca4bb3
commit
7960e6ea6d
@ -12,6 +12,9 @@ out vec4 tgt_color;
|
|||||||
#include <sky.glsl>
|
#include <sky.glsl>
|
||||||
#include <light.glsl>
|
#include <light.glsl>
|
||||||
|
|
||||||
|
const float RENDER_DIST = 128.0;
|
||||||
|
const float FADE_DIST = 32.0;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) * f_light + light_at(f_pos, f_norm);
|
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) * f_light + light_at(f_pos, f_norm);
|
||||||
vec3 surf_color = f_col * light;
|
vec3 surf_color = f_col * light;
|
||||||
@ -20,5 +23,5 @@ void main() {
|
|||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x);
|
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x);
|
||||||
vec3 color = mix(surf_color, fog_color, fog_level);
|
vec3 color = mix(surf_color, fog_color, fog_level);
|
||||||
|
|
||||||
tgt_color = vec4(color, 1.0);
|
tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (RENDER_DIST - FADE_DIST)) / FADE_DIST, 0, 1));
|
||||||
}
|
}
|
||||||
|
BIN
assets/voxygen/voxel/sprite/grass-0.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-0.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/voxel/sprite/grass-1.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-1.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/voxel/sprite/grass-2.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-2.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/voxel/sprite/grass-3.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-3.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/voxel/sprite/grass-4.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-4.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/voxel/sprite/grass-5.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/sprite/grass-5.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -20,6 +20,10 @@ impl<T: Copy + gfx::traits::Pod> Instances<T> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn count(&self) -> usize {
|
||||||
|
self.ibuf.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
|
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
|
||||||
|
@ -10,22 +10,20 @@ use std::ops::Range;
|
|||||||
/// Represents a mesh that has been sent to the GPU.
|
/// Represents a mesh that has been sent to the GPU.
|
||||||
pub struct Model<P: Pipeline> {
|
pub struct Model<P: Pipeline> {
|
||||||
pub vbuf: gfx::handle::Buffer<gfx_backend::Resources, P::Vertex>,
|
pub vbuf: gfx::handle::Buffer<gfx_backend::Resources, P::Vertex>,
|
||||||
pub slice: gfx::Slice<gfx_backend::Resources>,
|
pub vertex_range: Range<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: Pipeline> Model<P> {
|
impl<P: Pipeline> Model<P> {
|
||||||
pub fn new(factory: &mut gfx_backend::Factory, mesh: &Mesh<P>) -> Self {
|
pub fn new(factory: &mut gfx_backend::Factory, mesh: &Mesh<P>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
vbuf: factory.create_vertex_buffer(mesh.vertices()),
|
vbuf: factory.create_vertex_buffer(mesh.vertices()),
|
||||||
slice: gfx::Slice {
|
vertex_range: 0..mesh.vertices().len() as u32,
|
||||||
start: 0,
|
|
||||||
end: mesh.vertices().len() as u32,
|
|
||||||
base_vertex: 0,
|
|
||||||
instances: None,
|
|
||||||
buffer: gfx::IndexBuffer::Auto,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vertex_range(&self) -> Range<u32> {
|
||||||
|
self.vertex_range.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a mesh on the GPU which can be updated dynamically.
|
/// Represents a mesh on the GPU which can be updated dynamically.
|
||||||
@ -46,13 +44,7 @@ impl<P: Pipeline> DynamicModel<P> {
|
|||||||
pub fn submodel(&self, range: Range<usize>) -> Model<P> {
|
pub fn submodel(&self, range: Range<usize>) -> Model<P> {
|
||||||
Model {
|
Model {
|
||||||
vbuf: self.vbuf.clone(),
|
vbuf: self.vbuf.clone(),
|
||||||
slice: gfx::Slice {
|
vertex_range: range.start as u32..range.end as u32,
|
||||||
start: range.start as u32,
|
|
||||||
end: range.end as u32,
|
|
||||||
base_vertex: 0,
|
|
||||||
instances: None,
|
|
||||||
buffer: gfx::IndexBuffer::Auto,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ use gfx::{
|
|||||||
gfx_pipeline,
|
gfx_pipeline,
|
||||||
gfx_pipeline_inner,
|
gfx_pipeline_inner,
|
||||||
gfx_vertex_struct_meta,
|
gfx_vertex_struct_meta,
|
||||||
|
state::ColorMask,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ gfx_defines! {
|
|||||||
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
||||||
lights: gfx::ConstantBuffer<Light> = "u_lights",
|
lights: gfx::ConstantBuffer<Light> = "u_lights",
|
||||||
|
|
||||||
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
|
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA),
|
||||||
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,13 @@ impl Renderer {
|
|||||||
locals: &Consts<skybox::Locals>,
|
locals: &Consts<skybox::Locals>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.skybox_pipeline.pso,
|
&self.skybox_pipeline.pso,
|
||||||
&skybox::pipe::Data {
|
&skybox::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -388,7 +394,13 @@ impl Renderer {
|
|||||||
lights: &Consts<Light>,
|
lights: &Consts<Light>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.figure_pipeline.pso,
|
&self.figure_pipeline.pso,
|
||||||
&figure::pipe::Data {
|
&figure::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -411,7 +423,13 @@ impl Renderer {
|
|||||||
lights: &Consts<Light>,
|
lights: &Consts<Light>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.terrain_pipeline.pso,
|
&self.terrain_pipeline.pso,
|
||||||
&terrain::pipe::Data {
|
&terrain::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -433,7 +451,13 @@ impl Renderer {
|
|||||||
lights: &Consts<Light>,
|
lights: &Consts<Light>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.fluid_pipeline.pso,
|
&self.fluid_pipeline.pso,
|
||||||
&fluid::pipe::Data {
|
&fluid::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -455,7 +479,13 @@ impl Renderer {
|
|||||||
lights: &Consts<Light>,
|
lights: &Consts<Light>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: Some((instances.count() as u32, 0)),
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.sprite_pipeline.pso,
|
&self.sprite_pipeline.pso,
|
||||||
&sprite::pipe::Data {
|
&sprite::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -479,7 +509,13 @@ impl Renderer {
|
|||||||
) {
|
) {
|
||||||
let Aabr { min, max } = scissor;
|
let Aabr { min, max } = scissor;
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.ui_pipeline.pso,
|
&self.ui_pipeline.pso,
|
||||||
&ui::pipe::Data {
|
&ui::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
@ -505,7 +541,13 @@ impl Renderer {
|
|||||||
locals: &Consts<postprocess::Locals>,
|
locals: &Consts<postprocess::Locals>,
|
||||||
) {
|
) {
|
||||||
self.encoder.draw(
|
self.encoder.draw(
|
||||||
&model.slice,
|
&gfx::Slice {
|
||||||
|
start: model.vertex_range().start,
|
||||||
|
end: model.vertex_range().end,
|
||||||
|
base_vertex: 0,
|
||||||
|
instances: None,
|
||||||
|
buffer: gfx::IndexBuffer::Auto,
|
||||||
|
},
|
||||||
&self.postprocess_pipeline.pso,
|
&self.postprocess_pipeline.pso,
|
||||||
&postprocess::pipe::Data {
|
&postprocess::pipe::Data {
|
||||||
vbuf: model.vbuf.clone(),
|
vbuf: model.vbuf.clone(),
|
||||||
|
@ -229,7 +229,12 @@ impl Scene {
|
|||||||
// Render terrain and figures.
|
// Render terrain and figures.
|
||||||
self.figure_mgr
|
self.figure_mgr
|
||||||
.render(renderer, client, &self.globals, &self.lights, &self.camera);
|
.render(renderer, client, &self.globals, &self.lights, &self.camera);
|
||||||
self.terrain.render(renderer, &self.globals, &self.lights);
|
self.terrain.render(
|
||||||
|
renderer,
|
||||||
|
&self.globals,
|
||||||
|
&self.lights,
|
||||||
|
self.camera.get_focus_pos(),
|
||||||
|
);
|
||||||
|
|
||||||
renderer.render_post_process(
|
renderer.render_post_process(
|
||||||
&self.postprocess.model,
|
&self.postprocess.model,
|
||||||
|
@ -74,7 +74,7 @@ fn mesh_worker(
|
|||||||
|
|
||||||
match volume.get(wpos).unwrap_or(&Block::empty()).kind() {
|
match volume.get(wpos).unwrap_or(&Block::empty()).kind() {
|
||||||
BlockKind::Wheat => instances.push(SpriteInstance::new(
|
BlockKind::Wheat => instances.push(SpriteInstance::new(
|
||||||
wpos.map(|e| e as f32),
|
wpos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0),
|
||||||
Rgb::broadcast(1.0),
|
Rgb::broadcast(1.0),
|
||||||
)),
|
)),
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -110,7 +110,7 @@ impl Terrain {
|
|||||||
|
|
||||||
let wheat_mesh = Meshable::<SpritePipeline, SpritePipeline>::generate_mesh(
|
let wheat_mesh = Meshable::<SpritePipeline, SpritePipeline>::generate_mesh(
|
||||||
&Segment::from(
|
&Segment::from(
|
||||||
assets::load_expect::<DotVoxData>("voxygen.voxel.sprite.wheat").as_ref(),
|
assets::load_expect::<DotVoxData>("voxygen.voxel.sprite.grass-0").as_ref(),
|
||||||
),
|
),
|
||||||
Vec3::new(6.0, 6.0, 0.0),
|
Vec3::new(6.0, 6.0, 0.0),
|
||||||
)
|
)
|
||||||
@ -388,11 +388,19 @@ impl Terrain {
|
|||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
globals: &Consts<Globals>,
|
globals: &Consts<Globals>,
|
||||||
lights: &Consts<Light>,
|
lights: &Consts<Light>,
|
||||||
|
focus_pos: Vec3<f32>,
|
||||||
) {
|
) {
|
||||||
// Opaque
|
// Opaque
|
||||||
for (_pos, chunk) in &self.chunks {
|
for (pos, chunk) in &self.chunks {
|
||||||
if chunk.visible {
|
if chunk.visible {
|
||||||
renderer.render_terrain_chunk(&chunk.opaque_model, globals, &chunk.locals, lights);
|
renderer.render_terrain_chunk(&chunk.opaque_model, globals, &chunk.locals, lights);
|
||||||
|
|
||||||
|
const SPRITE_RENDER_DISTANCE: f32 = 128.0;
|
||||||
|
|
||||||
|
let chunk_center = pos.map2(Vec2::from(TerrainChunkSize::SIZE), |e, sz: u32| {
|
||||||
|
(e as f32 + 0.5) * sz as f32
|
||||||
|
});
|
||||||
|
if Vec2::from(focus_pos).distance(chunk_center) < SPRITE_RENDER_DISTANCE {
|
||||||
renderer.render_sprites(
|
renderer.render_sprites(
|
||||||
&self.wheat_model,
|
&self.wheat_model,
|
||||||
globals,
|
globals,
|
||||||
@ -401,6 +409,7 @@ impl Terrain {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Translucent
|
// Translucent
|
||||||
for (_pos, chunk) in &self.chunks {
|
for (_pos, chunk) in &self.chunks {
|
||||||
|
@ -254,7 +254,10 @@ impl<'a> BlockGen<'a> {
|
|||||||
BlockKind::Normal,
|
BlockKind::Normal,
|
||||||
saturate_srgb(col, 0.45).map(|e| (e * 255.0) as u8),
|
saturate_srgb(col, 0.45).map(|e| (e * 255.0) as u8),
|
||||||
))
|
))
|
||||||
} else if (wposf.z as f32) < height + 0.02 {
|
} else if (wposf.z as f32) < height + 1.0
|
||||||
|
&& (wposf.z as f32 > water_height + 3.0)
|
||||||
|
&& (chaos * 4096.0).fract() < 0.025
|
||||||
|
{
|
||||||
Some(Block::new(BlockKind::Wheat, Rgb::broadcast(0)))
|
Some(Block::new(BlockKind::Wheat, Rgb::broadcast(0)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user