2019-08-06 02:50:49 +00:00
|
|
|
use super::{
|
2020-04-04 19:36:55 +00:00
|
|
|
super::{Pipeline, TerrainLocals, TgtColorFmt, TgtDepthStencilFmt},
|
2019-09-25 12:00:00 +00:00
|
|
|
Globals, Light, Shadow,
|
2019-08-06 02:50:49 +00:00
|
|
|
};
|
|
|
|
use gfx::{
|
2020-02-01 20:39:39 +00:00
|
|
|
self, gfx_defines, gfx_impl_struct_meta, gfx_pipeline, gfx_pipeline_inner,
|
2020-04-04 19:36:55 +00:00
|
|
|
gfx_vertex_struct_meta,
|
|
|
|
state::{ColorMask, Comparison, Stencil, StencilOp},
|
2019-08-06 02:50:49 +00:00
|
|
|
};
|
|
|
|
use std::ops::Mul;
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
gfx_defines! {
|
|
|
|
vertex Vertex {
|
|
|
|
pos_norm: u32 = "v_pos_norm",
|
|
|
|
col_light: u32 = "v_col_light",
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline pipe {
|
|
|
|
vbuf: gfx::VertexBuffer<Vertex> = (),
|
|
|
|
|
2019-08-14 21:28:37 +00:00
|
|
|
locals: gfx::ConstantBuffer<TerrainLocals> = "u_locals",
|
2019-08-06 02:50:49 +00:00
|
|
|
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
|
|
|
lights: gfx::ConstantBuffer<Light> = "u_lights",
|
2019-09-25 12:00:00 +00:00
|
|
|
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
|
2019-08-06 02:50:49 +00:00
|
|
|
|
2019-11-17 22:41:00 +00:00
|
|
|
noise: gfx::TextureSampler<f32> = "t_noise",
|
2019-10-17 16:11:55 +00:00
|
|
|
waves: gfx::TextureSampler<[f32; 4]> = "t_waves",
|
|
|
|
|
2019-08-14 21:28:37 +00:00
|
|
|
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA),
|
2020-04-04 19:36:55 +00:00
|
|
|
tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_TEST,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))),
|
2019-08-06 02:50:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Vertex {
|
2019-08-15 01:35:56 +00:00
|
|
|
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>, light: f32, _opac: f32) -> Self {
|
2019-08-06 02:50:49 +00:00
|
|
|
let (norm_axis, norm_dir) = norm
|
|
|
|
.as_slice()
|
|
|
|
.into_iter()
|
|
|
|
.enumerate()
|
|
|
|
.find(|(_i, e)| **e != 0.0)
|
|
|
|
.unwrap_or((0, &1.0));
|
2020-04-14 23:02:15 +00:00
|
|
|
let norm_bits = ((norm_axis << 1) | if *norm_dir > 0.0 { 1 } else { 0 }) as u32;
|
|
|
|
|
|
|
|
const EXTRA_NEG_Z: f32 = 65536.0;
|
2019-08-06 02:50:49 +00:00
|
|
|
|
|
|
|
Self {
|
|
|
|
pos_norm: 0
|
2020-04-14 23:02:15 +00:00
|
|
|
| ((pos.x as u32) & 0x003F) << 0
|
|
|
|
| ((pos.y as u32) & 0x003F) << 6
|
|
|
|
| (((pos.z + EXTRA_NEG_Z).max(0.0).min((1 << 17) as f32) as u32) & 0x1FFFF) << 12
|
|
|
|
| (norm_bits & 0x7) << 29,
|
2019-08-06 02:50:49 +00:00
|
|
|
col_light: 0
|
|
|
|
| ((col.r.mul(200.0) as u32) & 0xFF) << 8
|
|
|
|
| ((col.g.mul(200.0) as u32) & 0xFF) << 16
|
|
|
|
| ((col.b.mul(200.0) as u32) & 0xFF) << 24
|
2019-08-14 21:28:37 +00:00
|
|
|
| ((light.mul(255.0) as u32) & 0xFF) << 0,
|
|
|
|
//| ((opac.mul(0.4) as u32) & 0xFF) << 0,
|
2019-08-06 02:50:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct FluidPipeline;
|
|
|
|
|
|
|
|
impl Pipeline for FluidPipeline {
|
|
|
|
type Vertex = Vertex;
|
|
|
|
}
|