haze
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
in vec2 v_uv;
|
||||
flat in uint v_tileidx;
|
||||
in float v_fade;
|
||||
out vec4 pixcolor;
|
||||
uniform sampler2DArray t_tiles;
|
||||
uniform b_constants {
|
||||
@@ -11,6 +12,8 @@ uniform b_constants {
|
||||
float R1;
|
||||
float R2;
|
||||
float R3;
|
||||
float haze;
|
||||
vec4 hazecolor;
|
||||
};
|
||||
uniform b_locals {
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
out vec2 v_uv;
|
||||
flat out uint v_tileidx;
|
||||
out float v_fade;
|
||||
uniform b_trans {
|
||||
mat4 u_viewmodel;
|
||||
mat4 u_matrix;
|
||||
};
|
||||
uniform b_constants {
|
||||
@@ -16,6 +18,8 @@ uniform b_constants {
|
||||
float R1;
|
||||
float R2;
|
||||
float R3;
|
||||
float haze;
|
||||
vec4 hazecolor;
|
||||
};
|
||||
uniform b_locals {
|
||||
uint millis;
|
||||
@@ -38,5 +42,9 @@ void main() {
|
||||
float height = R2 * 4 * TWO_PI_CIRC;
|
||||
vec3 normal = vec3(toroid(thetaphi, 0, height, height)) *
|
||||
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 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! {
|
||||
vertex Vertex {
|
||||
pos: [f32; 3] = "a_pos",
|
||||
@@ -41,6 +44,8 @@ gfx_defines! {
|
||||
r1: f32 = "R1",
|
||||
r2: f32 = "R2",
|
||||
r3: f32 = "R3",
|
||||
haze: f32 = "haze",
|
||||
hazecolor: [f32; 4] = "hazecolor",
|
||||
}
|
||||
|
||||
constant Locals {
|
||||
@@ -157,7 +162,9 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
||||
pipe::new())
|
||||
.expect("create pipeline"),
|
||||
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_dirty: true,
|
||||
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_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>,
|
||||
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>) {
|
||||
|
||||
encoder.clear(&target, SKY_COLOR);
|
||||
encoder.clear_depth(&depth, 1.0);
|
||||
let pipe = pipe::Data {
|
||||
vbuf: self.vbuf.clone(),
|
||||
trans: trans.clone(),
|
||||
|
||||
Reference in New Issue
Block a user