2019-05-22 18:49:06 +00:00
|
|
|
use super::{
|
|
|
|
super::{Pipeline, TgtColorFmt, TgtDepthFmt},
|
2019-07-21 15:04:36 +00:00
|
|
|
Globals, Light,
|
2019-05-22 18:49:06 +00:00
|
|
|
};
|
2019-01-14 23:13:58 +00:00
|
|
|
use gfx::{
|
|
|
|
self,
|
2019-04-29 20:37:19 +00:00
|
|
|
gfx_constant_struct_meta,
|
2019-01-14 23:13:58 +00:00
|
|
|
// Macros
|
|
|
|
gfx_defines,
|
|
|
|
gfx_impl_struct_meta,
|
|
|
|
gfx_pipeline,
|
|
|
|
gfx_pipeline_inner,
|
2019-04-29 20:37:19 +00:00
|
|
|
gfx_vertex_struct_meta,
|
2019-01-14 23:13:58 +00:00
|
|
|
};
|
2019-06-06 14:48:41 +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",
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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-05-31 20:37:11 +00:00
|
|
|
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>, light: f32) -> Self {
|
2019-06-03 21:35:03 +00:00
|
|
|
let (norm_axis, norm_dir) = norm
|
|
|
|
.as_slice()
|
|
|
|
.into_iter()
|
|
|
|
.enumerate()
|
2019-06-06 14:48:41 +00:00
|
|
|
.find(|(_i, e)| **e != 0.0)
|
2019-06-03 21:35:03 +00:00
|
|
|
.unwrap_or((0, &1.0));
|
|
|
|
let norm_bits = (norm_axis << 1) | if *norm_dir > 0.0 { 1 } else { 0 };
|
|
|
|
|
2019-01-14 23:13:58 +00:00
|
|
|
Self {
|
2019-06-03 21:35:03 +00:00
|
|
|
pos_norm: 0
|
2019-05-22 18:30:18 +00:00
|
|
|
| ((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-06-03 21:35:03 +00:00
|
|
|
| ((norm_bits as u32) & 0x7) << 29,
|
|
|
|
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-06-03 21:35:03 +00:00
|
|
|
| ((light.mul(255.0) as u32) & 0xFF) << 0,
|
2019-01-14 23:13:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Locals {
|
|
|
|
pub fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
model_offs: [0.0; 3],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TerrainPipeline;
|
|
|
|
|
|
|
|
impl Pipeline for TerrainPipeline {
|
|
|
|
type Vertex = Vertex;
|
|
|
|
}
|