show tracked avatar tile
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
extern crate vrtue;
|
||||
use vrtue::*;
|
||||
use vrtue::{tile, vr};
|
||||
use vrtue::vr::AsMatrix4;
|
||||
|
||||
extern crate env_logger;
|
||||
@@ -10,7 +10,7 @@ extern crate nalgebra as na;
|
||||
extern crate num_traits;
|
||||
extern crate piston_window;
|
||||
|
||||
use gfx::Device;
|
||||
use gfx::{tex, Device, Factory};
|
||||
use gfx::traits::FactoryExt;
|
||||
use na::Inverse;
|
||||
use num_traits::identities::One;
|
||||
@@ -25,7 +25,7 @@ const FAR: f32 = 1000.0;
|
||||
gfx_defines!{
|
||||
vertex Vertex {
|
||||
pos: [f32; 3] = "a_pos",
|
||||
color: [f32; 3] = "a_color",
|
||||
uv: [f32; 2] = "a_uv",
|
||||
}
|
||||
|
||||
constant Trans {
|
||||
@@ -35,18 +35,20 @@ gfx_defines!{
|
||||
pipeline pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
trans: gfx::ConstantBuffer<Trans> = "b_trans",
|
||||
tiles: gfx::TextureSampler<[f32; 4]> = "t_tiles",
|
||||
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
|
||||
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
}
|
||||
}
|
||||
|
||||
const POLYGON: [Vertex; 4] = [
|
||||
Vertex { pos: [ -0.25, -0.25, 0. ], color: [1.0, 0.0, 0.0] },
|
||||
Vertex { pos: [ 0.25, -0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
||||
Vertex { pos: [ 0.25, 0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
||||
Vertex { pos: [ -0.25, 0.25, 0. ], color: [0.0, 0.0, 1.0] }
|
||||
Vertex { pos: [ -0.25, -0.25, 0. ], uv: [0., 0.] },
|
||||
Vertex { pos: [ 0.25, -0.25, 0. ], uv: [1., 0.] },
|
||||
Vertex { pos: [ 0.25, 0.25, 0. ], uv: [1., 1.] },
|
||||
Vertex { pos: [ -0.25, 0.25, 0. ], uv: [0., 1.] }
|
||||
];
|
||||
const POLYGON_IDX: &'static [u16] = &[ 0, 1, 2, 2, 3, 0 ];
|
||||
const POLYGON_IDX: &'static [u16] = &[ 0, 1, 2,
|
||||
2, 3, 0 ];
|
||||
|
||||
fn main() {
|
||||
env_logger::init().expect("env logger");
|
||||
@@ -70,21 +72,29 @@ fn main() {
|
||||
.expect("create right renderbuffer");
|
||||
let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX);
|
||||
|
||||
let tiles = tile::get_tiles::<_, _, ColorFormat>(&mut window.factory);
|
||||
let nn_sampler = window.factory.create_sampler(
|
||||
tex::SamplerInfo::new(tex::FilterMethod::Scale,
|
||||
tex::WrapMode::Clamp));
|
||||
|
||||
let pipe_monitor = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: window.output_color.clone(),
|
||||
depth: window.output_stencil.clone(),
|
||||
};
|
||||
let pipe_left = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: tgt_left,
|
||||
depth: depth_left,
|
||||
};
|
||||
let pipe_right = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: tgt_right,
|
||||
depth: depth_right,
|
||||
};
|
||||
@@ -180,14 +190,15 @@ const VERTEX_SHADER_SRC: &'static [u8] = br#"
|
||||
#version 140
|
||||
|
||||
in vec3 a_pos;
|
||||
in vec3 a_color;
|
||||
in vec2 a_uv;
|
||||
out vec3 v_color;
|
||||
out vec2 v_uv;
|
||||
uniform b_trans {
|
||||
mat4 u_matrix;
|
||||
};
|
||||
|
||||
void main() {
|
||||
v_color = a_color;
|
||||
v_uv = a_uv;
|
||||
gl_Position = u_matrix * vec4(a_pos, 1.0);
|
||||
}
|
||||
"#;
|
||||
@@ -196,9 +207,12 @@ const FRAGMENT_SHADER_SRC: &'static [u8] = br#"
|
||||
#version 140
|
||||
|
||||
in vec3 v_color;
|
||||
in vec2 v_uv;
|
||||
out vec4 pixcolor;
|
||||
uniform sampler2D t_tiles;
|
||||
|
||||
void main() {
|
||||
pixcolor = vec4(v_color, 1.0);
|
||||
vec2 uv = vec2(v_uv.x, 31.0 / 256 + (1.0 - v_uv.y) / 256.0);
|
||||
pixcolor = texture(t_tiles, uv);
|
||||
}
|
||||
"#;
|
||||
|
||||
Reference in New Issue
Block a user