veloren/voxygen/src/render/pipelines/terrain.rs

75 lines
1.9 KiB
Rust
Raw Normal View History

use super::{
super::{Pipeline, TgtColorFmt, TgtDepthFmt},
2019-09-25 12:00:00 +00:00
Globals, Light, Shadow,
};
2019-01-14 23:13:58 +00:00
use gfx::{
self,
gfx_constant_struct_meta,
2019-01-14 23:13:58 +00:00
// Macros
gfx_defines,
gfx_impl_struct_meta,
gfx_pipeline,
gfx_pipeline_inner,
gfx_vertex_struct_meta,
2019-01-14 23:13:58 +00:00
};
use std::ops::Mul;
2019-01-14 23:13:58 +00:00
use vek::*;
gfx_defines! {
vertex Vertex {
2019-06-03 21:35:03 +00:00
pos_norm: u32 = "v_pos_norm",
col_light: u32 = "v_col_light",
2019-01-14 23:13:58 +00:00
}
constant Locals {
model_offs: [f32; 3] = "model_offs",
2019-09-24 15:43:51 +00:00
load_time: f32 = "load_time",
2019-01-14 23:13:58 +00:00
}
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
2019-07-21 15:04:36 +00:00
lights: gfx::ConstantBuffer<Light> = "u_lights",
2019-09-25 12:00:00 +00:00
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
2019-01-14 23:13:58 +00:00
2019-11-17 22:41:00 +00:00
noise: gfx::TextureSampler<f32> = "t_noise",
2019-01-14 23:13:58 +00:00
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
}
}
impl Vertex {
2019-11-19 13:20:20 +00:00
pub fn new(norm_bits: u32, light: u32, pos: Vec3<f32>, col: Rgb<f32>) -> Self {
2019-01-14 23:13:58 +00:00
Self {
2019-06-03 21:35:03 +00:00
pos_norm: 0
| ((pos.x as u32) & 0x00FF) << 0
| ((pos.y as u32) & 0x00FF) << 8
2019-07-09 20:42:27 +00:00
| ((pos.z.max(0.0).min((1 << 13) as f32) as u32) & 0x1FFF) << 16
2019-11-19 13:20:20 +00:00
| (norm_bits & 0x7) << 29,
2019-06-03 21:35:03 +00:00
col_light: 0
2019-08-04 19:54:08 +00:00
| ((col.r.mul(255.0) as u32) & 0xFF) << 8
| ((col.g.mul(255.0) as u32) & 0xFF) << 16
| ((col.b.mul(255.0) as u32) & 0xFF) << 24
2019-11-19 13:20:20 +00:00
| (light & 0xFF) << 0,
2019-01-14 23:13:58 +00:00
}
}
}
impl Locals {
pub fn default() -> Self {
Self {
model_offs: [0.0; 3],
2019-09-24 15:43:51 +00:00
load_time: 0.0,
2019-01-14 23:13:58 +00:00
}
}
}
pub struct TerrainPipeline;
impl Pipeline for TerrainPipeline {
type Vertex = Vertex;
}