Split terrain rendering to avoid redrawing skybox

This commit is contained in:
Joshua Barretto 2019-11-19 09:17:39 +00:00
parent bca3817163
commit 28e625635f
5 changed files with 41 additions and 6 deletions

View File

@ -146,7 +146,8 @@ vec2 cloud_at(vec3 pos) {
}
vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
const float INCR = 0.07;
const float INCR = 0.06;
float mind = (CLOUD_HEIGHT_MIN - origin.z) / dir.z;
float maxd = (CLOUD_HEIGHT_MAX - origin.z) / dir.z;

View File

@ -18,5 +18,5 @@ void main() {
gl_Position =
proj_mat *
view_mat *
vec4(v_pos * 2000.0 + cam_pos.xyz, 1);
vec4(v_pos * 3000.0 + cam_pos.xyz, 1);
}

View File

@ -31,7 +31,7 @@ gfx_defines! {
noise: gfx::TextureSampler<f32> = "t_noise",
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::PASS_TEST,
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
}
}

View File

@ -293,9 +293,6 @@ impl Scene {
/// Render the scene using the provided `Renderer`.
pub fn render(&mut self, renderer: &mut Renderer, client: &mut Client) {
// Render the skybox.
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
// Render terrain and figures.
self.figure_mgr.render(
renderer,
@ -313,6 +310,17 @@ impl Scene {
self.camera.get_focus_pos(),
);
// Render the skybox.
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
self.terrain.render_translucent(
renderer,
&self.globals,
&self.lights,
&self.shadows,
self.camera.get_focus_pos(),
);
renderer.render_post_process(
&self.postprocess.model,
&self.globals,

View File

@ -1092,6 +1092,32 @@ impl<V: RectRasterableVol> Terrain<V> {
);
}
}
}
pub fn render_translucent(
&self,
renderer: &mut Renderer,
globals: &Consts<Globals>,
lights: &Consts<Light>,
shadows: &Consts<Shadow>,
focus_pos: Vec3<f32>,
) {
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
(e as i32).div_euclid(sz as i32)
});
let chunks = &self.chunks;
let chunk_iter = Spiral2d::new()
.scan(0, |n, rpos| {
if *n >= chunks.len() {
None
} else {
*n += 1;
let pos = focus_chunk + rpos;
Some(chunks.get(&pos).map(|c| (pos, c)))
}
})
.filter_map(|x| x);
// Terrain sprites
for (pos, chunk) in chunk_iter.clone() {