haze
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
in vec2 v_uv;
|
in vec2 v_uv;
|
||||||
flat in uint v_tileidx;
|
flat in uint v_tileidx;
|
||||||
|
in float v_fade;
|
||||||
out vec4 pixcolor;
|
out vec4 pixcolor;
|
||||||
uniform sampler2DArray t_tiles;
|
uniform sampler2DArray t_tiles;
|
||||||
uniform b_constants {
|
uniform b_constants {
|
||||||
@@ -11,6 +12,8 @@ uniform b_constants {
|
|||||||
float R1;
|
float R1;
|
||||||
float R2;
|
float R2;
|
||||||
float R3;
|
float R3;
|
||||||
|
float haze;
|
||||||
|
vec4 hazecolor;
|
||||||
};
|
};
|
||||||
uniform b_locals {
|
uniform b_locals {
|
||||||
uint millis;
|
uint millis;
|
||||||
@@ -24,5 +27,6 @@ void main() {
|
|||||||
anim_uv = vec2(v_uv.x, v_uv.y + float(millis % MILLIS_PER_TILE) / MILLIS_PER_TILE);
|
anim_uv = vec2(v_uv.x, v_uv.y + float(millis % MILLIS_PER_TILE) / MILLIS_PER_TILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixcolor = texture(t_tiles, vec3(anim_uv.x, 1.0 - anim_uv.y, v_tileidx));
|
vec4 texcolor = texture(t_tiles, vec3(anim_uv.x, 1.0 - anim_uv.y, v_tileidx));
|
||||||
|
pixcolor = mix(texcolor, hazecolor, v_fade);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ in vec2 a_uv;
|
|||||||
in uint a_tileidx;
|
in uint a_tileidx;
|
||||||
out vec2 v_uv;
|
out vec2 v_uv;
|
||||||
flat out uint v_tileidx;
|
flat out uint v_tileidx;
|
||||||
|
out float v_fade;
|
||||||
uniform b_trans {
|
uniform b_trans {
|
||||||
|
mat4 u_viewmodel;
|
||||||
mat4 u_matrix;
|
mat4 u_matrix;
|
||||||
};
|
};
|
||||||
uniform b_constants {
|
uniform b_constants {
|
||||||
@@ -16,6 +18,8 @@ uniform b_constants {
|
|||||||
float R1;
|
float R1;
|
||||||
float R2;
|
float R2;
|
||||||
float R3;
|
float R3;
|
||||||
|
float haze;
|
||||||
|
vec4 hazecolor;
|
||||||
};
|
};
|
||||||
uniform b_locals {
|
uniform b_locals {
|
||||||
uint millis;
|
uint millis;
|
||||||
@@ -38,5 +42,9 @@ void main() {
|
|||||||
float height = R2 * 4 * TWO_PI_CIRC;
|
float height = R2 * 4 * TWO_PI_CIRC;
|
||||||
vec3 normal = vec3(toroid(thetaphi, 0, height, height)) *
|
vec3 normal = vec3(toroid(thetaphi, 0, height, height)) *
|
||||||
vec3(R2 / R3, 1.0, 1.0);
|
vec3(R2 / R3, 1.0, 1.0);
|
||||||
gl_Position = u_matrix * vec4(toroid(thetaphi, R1, R2, R3) + a_pos.z * normal, 1.0);
|
vec4 model_pos = vec4(toroid(thetaphi, R1, R2, R3) + a_pos.z * normal, 1.0);
|
||||||
|
gl_Position = u_matrix * model_pos;
|
||||||
|
|
||||||
|
vec4 view_pos = u_viewmodel * model_pos;
|
||||||
|
v_fade = min(1.0, length(view_pos.xyz) / R1 / 2 * haze);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ const R1: f32 = 256.0;
|
|||||||
const R2: f32 = 64.0;
|
const R2: f32 = 64.0;
|
||||||
const R3: f32 = 128.0;
|
const R3: f32 = 128.0;
|
||||||
|
|
||||||
|
//const SKY_COLOR: [f32; 4] = [0.15, 0.15, 0.75, 1.0];
|
||||||
|
const SKY_COLOR: [f32; 4] = [0.005, 0.005, 0.01, 1.0];
|
||||||
|
|
||||||
gfx_defines! {
|
gfx_defines! {
|
||||||
vertex Vertex {
|
vertex Vertex {
|
||||||
pos: [f32; 3] = "a_pos",
|
pos: [f32; 3] = "a_pos",
|
||||||
@@ -41,6 +44,8 @@ gfx_defines! {
|
|||||||
r1: f32 = "R1",
|
r1: f32 = "R1",
|
||||||
r2: f32 = "R2",
|
r2: f32 = "R2",
|
||||||
r3: f32 = "R3",
|
r3: f32 = "R3",
|
||||||
|
haze: f32 = "haze",
|
||||||
|
hazecolor: [f32; 4] = "hazecolor",
|
||||||
}
|
}
|
||||||
|
|
||||||
constant Locals {
|
constant Locals {
|
||||||
@@ -157,7 +162,9 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
|||||||
pipe::new())
|
pipe::new())
|
||||||
.expect("create pipeline"),
|
.expect("create pipeline"),
|
||||||
camera: na::Matrix4::one(),
|
camera: na::Matrix4::one(),
|
||||||
constants: Constants { anim: ANIMDATA, r1: R1, r2: R2, r3: R3},
|
constants: Constants { anim: ANIMDATA,
|
||||||
|
r1: R1, r2: R2, r3: R3,
|
||||||
|
haze: 1.0/2.0f32.sqrt(), hazecolor: SKY_COLOR },
|
||||||
constants_buffer: factory.create_constant_buffer(1),
|
constants_buffer: factory.create_constant_buffer(1),
|
||||||
constants_dirty: true,
|
constants_dirty: true,
|
||||||
locals: factory.create_constant_buffer(1),
|
locals: factory.create_constant_buffer(1),
|
||||||
@@ -258,6 +265,17 @@ impl<D: gfx::Device,
|
|||||||
self.constants = Constants { r1: R1 * 16.0, r2: R2 * 16.0, r3: R3 * 16.0, ..self.constants };
|
self.constants = Constants { r1: R1 * 16.0, r2: R2 * 16.0, r3: R3 * 16.0, ..self.constants };
|
||||||
self.constants_dirty = true;
|
self.constants_dirty = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::H))) => {
|
||||||
|
self.constants = Constants { haze: self.constants.haze * 2.0f32.sqrt().sqrt(), ..self.constants };
|
||||||
|
println!("haze: {}", self.constants.haze);
|
||||||
|
self.constants_dirty = true;
|
||||||
|
},
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::N))) => {
|
||||||
|
self.constants = Constants { haze: self.constants.haze / 2.0f32.sqrt().sqrt(), ..self.constants };
|
||||||
|
println!("haze: {}", self.constants.haze);
|
||||||
|
self.constants_dirty = true;
|
||||||
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,6 +345,8 @@ impl<D: gfx::Device,
|
|||||||
target: &gfx::handle::RenderTargetView<D::Resources, view::ColorFormat>,
|
target: &gfx::handle::RenderTargetView<D::Resources, view::ColorFormat>,
|
||||||
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>) {
|
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>) {
|
||||||
|
|
||||||
|
encoder.clear(&target, SKY_COLOR);
|
||||||
|
encoder.clear_depth(&depth, 1.0);
|
||||||
let pipe = pipe::Data {
|
let pipe = pipe::Data {
|
||||||
vbuf: self.vbuf.clone(),
|
vbuf: self.vbuf.clone(),
|
||||||
trans: trans.clone(),
|
trans: trans.clone(),
|
||||||
|
|||||||
13
src/view.rs
13
src/view.rs
@@ -20,6 +20,7 @@ const FAR: f32 = 3072.0;
|
|||||||
|
|
||||||
gfx_constant_struct! {
|
gfx_constant_struct! {
|
||||||
Trans {
|
Trans {
|
||||||
|
viewmodel: [[f32; 4]; 4] = "u_viewmodel",
|
||||||
matrix: [[f32; 4]; 4] = "u_matrix",
|
matrix: [[f32; 4]; 4] = "u_matrix",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,13 +82,13 @@ impl ViewRoot<gfx_device_gl::Device, ColorFormat, DepthFormat> {
|
|||||||
(vr::Eye::Right, &self.right)].into_iter() {
|
(vr::Eye::Right, &self.right)].into_iter() {
|
||||||
let target = &buffers.as_ref().expect("vr color buffer").target;
|
let target = &buffers.as_ref().expect("vr color buffer").target;
|
||||||
let depth = &buffers.as_ref().expect("vr depth buffer").depth;
|
let depth = &buffers.as_ref().expect("vr depth buffer").depth;
|
||||||
window.encoder.clear(target, [0.005, 0.005, 0.01, 1.0]);
|
|
||||||
window.encoder.clear_depth(depth, 1.0);
|
|
||||||
|
|
||||||
let proj_mat = vr.projection_matrix(eye, NEAR, FAR);
|
let proj_mat = vr.projection_matrix(eye, NEAR, FAR);
|
||||||
let eye_mat = vr.head_to_eye_transform(eye);
|
let eye_mat = vr.head_to_eye_transform(eye);
|
||||||
let scene_mat = scene.origin();
|
let scene_mat = scene.origin();
|
||||||
let trans = Trans { matrix: *(proj_mat * eye_mat * hmd_mat * scene_mat).as_ref() };
|
let viewmodel_mat = eye_mat * hmd_mat * scene_mat;
|
||||||
|
let trans = Trans { viewmodel: *viewmodel_mat.as_ref(),
|
||||||
|
matrix: *(proj_mat * viewmodel_mat).as_ref() };
|
||||||
window.encoder.update_constant_buffer(&self.trans, &trans);
|
window.encoder.update_constant_buffer(&self.trans, &trans);
|
||||||
|
|
||||||
scene.render(&mut window.factory,
|
scene.render(&mut window.factory,
|
||||||
@@ -103,12 +104,12 @@ impl ViewRoot<gfx_device_gl::Device, ColorFormat, DepthFormat> {
|
|||||||
1.0).to_homogeneous();
|
1.0).to_homogeneous();
|
||||||
let proj_mat = na::PerspectiveMatrix3::new(1.0, 90.0, NEAR, FAR).to_matrix();
|
let proj_mat = na::PerspectiveMatrix3::new(1.0, 90.0, NEAR, FAR).to_matrix();
|
||||||
let scene_mat = scene.origin();
|
let scene_mat = scene.origin();
|
||||||
let trans = Trans { matrix: *(proj_mat * head_mat * scene_mat).as_ref() };
|
let viewmodel_mat = head_mat * scene_mat;
|
||||||
|
let trans = Trans { viewmodel: *viewmodel_mat.as_ref(),
|
||||||
|
matrix: *(proj_mat * viewmodel_mat).as_ref() };
|
||||||
window.encoder.update_constant_buffer(&self.trans, &trans);
|
window.encoder.update_constant_buffer(&self.trans, &trans);
|
||||||
}
|
}
|
||||||
// draw monitor window
|
// draw monitor window
|
||||||
window.encoder.clear(&window.output_color, [0.005, 0.005, 0.01, 1.0]);
|
|
||||||
window.encoder.clear_depth(&window.output_stencil, 1.0);
|
|
||||||
scene.render(&mut window.factory,
|
scene.render(&mut window.factory,
|
||||||
&mut window.encoder,
|
&mut window.encoder,
|
||||||
&self.trans,
|
&self.trans,
|
||||||
|
|||||||
Reference in New Issue
Block a user