simple tile heights

This commit is contained in:
2016-10-05 14:15:16 -07:00
parent d69223ef13
commit 193e807b6a
4 changed files with 123 additions and 88 deletions

View File

@@ -0,0 +1,28 @@
#version 150
in vec2 v_uv;
flat in uint v_tileidx;
out vec4 pixcolor;
uniform sampler2D t_atlas;
uniform b_constants {
//uvec4 animdata;
uint animdata;
float R1;
float R2;
};
uniform b_locals {
mat4 camera;
uint millis;
float treadmill_x;
float treadmill_y;
};
void main() {
vec2 anim_uv = v_uv;
//if (v_tileidx < 128u && bool(animdata[0 /*v_tileidx / 32u*/] & 1u << v_tileidx % 32u)) {
if (v_tileidx < 32u && bool(animdata & 1u << v_tileidx)) {
anim_uv = vec2(v_uv.x, float((uint(v_uv.y * 1000.0) + millis / 4u) % 1000u) / 1000.0);
}
vec2 uv = vec2(anim_uv.x, float(v_tileidx) / 256.0 + (1.0 - anim_uv.y) / 256.0);
pixcolor = texture(t_atlas, uv);
}

View File

@@ -0,0 +1,50 @@
#version 150
#define PI 3.1415926538
#define PI_CIRC (PI / 256.0)
#define TWO_PI_CIRC (2.0 * PI / 256.0)
in vec3 a_pos;
in vec2 a_uv;
in uint a_tileidx;
out vec2 v_uv;
flat out uint v_tileidx;
uniform b_trans {
mat4 u_matrix;
};
uniform b_constants {
//uvec4 animdata;
uint animdata;
float R1;
float R2;
};
uniform b_locals {
mat4 camera;
uint millis;
float treadmill_x;
float treadmill_y;
};
vec3 toroid(vec2 src, float r1, float r2, float r3) {
return vec3(r3 * -1.0 * sin(src.x), // use r3 instead of r2 for "deflated" torus
(r1 + r2 * cos(src.x)) * cos(src.y),
(r1 + r2 * cos(src.x)) * sin(src.y));
}
void main() {
v_uv = a_uv;
v_tileidx = a_tileidx;
vec2 thetaphi = vec2(TWO_PI_CIRC * (a_pos.x + treadmill_x),
TWO_PI_CIRC * (a_pos.y + treadmill_y));
float height = R1 * TWO_PI_CIRC;
vec3 normal = vec3(toroid(thetaphi, 0, height, height));
gl_Position = u_matrix * camera *
vec4(toroid(thetaphi, R1, R2, R1) + a_pos.z * normal, 1.0);
/*
gl_Position = u_matrix * camera *
vec4(R2 * -1.0 * sin(TWO_PI_CIRC * (a_pos.x + treadmill_x)),
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * cos(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * sin(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
1.0);
*/
}

View File

@@ -20,8 +20,12 @@ use gfx::traits::FactoryExt;
use self::na::ToHomogeneous; use self::na::ToHomogeneous;
use self::num_traits::identities::One; use self::num_traits::identities::One;
const R1: f32 = 4096.0; //const R1: f32 = 4096.0;
const R2: f32 = 1024.0; //const R2: f32 = 1024.0;
//const R1: f32 = 4.0;
//const R2: f32 = 1.0;
const R1: f32 = 256.0;
const R2: f32 = 64.0;
gfx_defines! { gfx_defines! {
vertex Vertex { vertex Vertex {
@@ -63,17 +67,44 @@ fn get_model(world: &model::World) -> (Vec<Vertex>, Vec<u32>) {
for (r, row) in world.map().rows().enumerate() { for (r, row) in world.map().rows().enumerate() {
for (c, tile) in row.into_iter().enumerate() { for (c, tile) in row.into_iter().enumerate() {
let tileidx = tile.val as u32; let tileidx = tile.val as u32;
let alt = match tileidx {
5 => 0.1,
6 => 0.8,
7 => 0.2,
8 => 1.5,
9 => 1.0,
10 | 11 | 12 => 1.0,
_ => 0.0,
};
let rf = (((r + 90) % 256) as i16 - 128) as f32; let rf = (((r + 90) % 256) as i16 - 128) as f32;
let cf = (((c + 144) % 256) as i16 - 128) as f32; let cf = (((c + 144) % 256) as i16 - 128) as f32;
verticies.extend_from_slice( if alt == 0.0 {
&[Vertex { pos: [ cf + 0., 0., -rf - 1. ], uv: [0., 0.], tileidx: tileidx }, verticies.extend_from_slice(
Vertex { pos: [ cf + 1., 0., -rf - 1. ], uv: [1., 0.], tileidx: tileidx }, &[Vertex { pos: [ cf + 0., -rf - 1., 0. ], uv: [0., 0.], tileidx: tileidx },
Vertex { pos: [ cf + 1., 0., -rf - 0. ], uv: [1., 1.], tileidx: tileidx }, Vertex { pos: [ cf + 1., -rf - 1., 0. ], uv: [1., 0.], tileidx: tileidx },
Vertex { pos: [ cf + 0., 0., -rf - 0. ], uv: [0., 1.], tileidx: tileidx },]); Vertex { pos: [ cf + 1., -rf - 0., 0. ], uv: [1., 1.], tileidx: tileidx },
indicies.extend_from_slice( Vertex { pos: [ cf + 0., -rf - 0., 0. ], uv: [0., 1.], tileidx: tileidx },]);
&[ v + 0, v + 1, v + 2, indicies.extend_from_slice(
v + 2, v + 3, v + 0 ]); &[ v + 0, v + 1, v + 2,
v += 4; v + 2, v + 3, v + 0 ]);
v += 4;
} else {
verticies.extend_from_slice(
&[Vertex { pos: [ cf + 0., -rf - 1., 0. ], uv: [0., 0.], tileidx: 126 },
Vertex { pos: [ cf + 1., -rf - 1., 0. ], uv: [1., 0.], tileidx: 126 },
Vertex { pos: [ cf + 1., -rf - 0., 0. ], uv: [1., 1.], tileidx: 126 },
Vertex { pos: [ cf + 0., -rf - 0., 0. ], uv: [0., 1.], tileidx: 126 },
Vertex { pos: [ cf + 0., -rf, 0. ], uv: [0., 0.], tileidx: tileidx },
Vertex { pos: [ cf + 1., -rf, 0. ], uv: [1., 0.], tileidx: tileidx },
Vertex { pos: [ cf + 1., -rf, alt ], uv: [1., 1.], tileidx: tileidx },
Vertex { pos: [ cf + 0., -rf, alt ], uv: [0., 1.], tileidx: tileidx },]);
indicies.extend_from_slice(
&[ v + 0, v + 1, v + 2,
v + 2, v + 3, v + 0,
v + 4, v + 5, v + 6,
v + 6, v + 7, v + 4 ]);
v += 8;
}
} }
} }
(verticies, indicies) (verticies, indicies)
@@ -264,79 +295,5 @@ fn get_data_model() -> model::World {
mmap_to_rows::<model::World>(&file_mmap).clone() mmap_to_rows::<model::World>(&file_mmap).clone()
} }
const VERTEX_SHADER_SRC: &'static [u8] = br#" const VERTEX_SHADER_SRC: &'static [u8] = include_bytes!("shader/torus_vertex.glsl");
#version 150 const FRAGMENT_SHADER_SRC: &'static [u8] = include_bytes!("shader/tile_frag.glsl");
#define PI 3.1415926538
in vec3 a_pos;
in vec2 a_uv;
in uint a_tileidx;
out vec2 v_uv;
flat out uint v_tileidx;
uniform b_trans {
mat4 u_matrix;
};
uniform b_constants {
//uvec4 animdata;
uint animdata;
float R1;
float R2;
};
uniform b_locals {
mat4 camera;
uint millis;
float treadmill_x;
float treadmill_y;
};
void main() {
v_uv = a_uv;
v_tileidx = a_tileidx;
float TWO_PI_CIRC = 2 * PI / 256.0;
gl_Position = u_matrix * camera * vec4(R2 * -1.0 * sin(TWO_PI_CIRC * (a_pos.x + treadmill_x)),
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * cos(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * sin(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
1.0);
/*
float which = (1.0 + sin(float(millis) / 5000.)) / 2.0;
gl_Position = u_matrix * camera * vec4(a_pos.x,
R1 * cos(TWO_PI_CIRC * a_pos.z),
which * a_pos.z +
((1.0-which) * R1 * sin(TWO_PI_CIRC * a_pos.z)),
1.0);
*/
}
"#;
const FRAGMENT_SHADER_SRC: &'static [u8] = br#"
#version 150
in vec2 v_uv;
flat in uint v_tileidx;
out vec4 pixcolor;
uniform sampler2D t_atlas;
uniform b_constants {
//uvec4 animdata;
uint animdata;
float R1;
float R2;
};
uniform b_locals {
mat4 camera;
uint millis;
float treadmill_x;
float treadmill_y;
};
void main() {
vec2 anim_uv = v_uv;
//if (v_tileidx < 128u && bool(animdata[0 /*v_tileidx / 32u*/] & 1u << v_tileidx % 32u)) {
if (v_tileidx < 32u && bool(animdata & 1u << v_tileidx)) {
anim_uv = vec2(v_uv.x, float((uint(v_uv.y * 1000.0) + millis / 4u) % 1000u) / 1000.0);
}
vec2 uv = vec2(anim_uv.x, float(v_tileidx) / 256.0 + (1.0 - anim_uv.y) / 256.0);
pixcolor = texture(t_atlas, uv);
}
"#;

View File

@@ -16,7 +16,7 @@ pub type ColorFormat = gfx::format::Srgba8;
pub type DepthFormat = gfx::format::DepthStencil; pub type DepthFormat = gfx::format::DepthStencil;
const NEAR: f32 = 0.01; const NEAR: f32 = 0.01;
const FAR: f32 = 10000.0; const FAR: f32 = 1000.0;
gfx_constant_struct! { gfx_constant_struct! {
Trans { Trans {