Skip to content

Commit

Permalink
Finally got a quad on screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeReV committed Jan 13, 2020
1 parent 8dcccf7 commit 319a44c
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 267 deletions.
40 changes: 38 additions & 2 deletions assets/shaders/quad.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#version 330 core

uniform sampler2D Texture;
uniform vec2 Resolution;

in VS_OUTPUT {
vec3 Position;
Expand All @@ -10,9 +11,44 @@ in VS_OUTPUT {

out vec4 Color;

float normpdf(in float x, in float sigma)
{
return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
}

void main()
{
vec3 color = texture(Texture, IN.Uv).rgb;

Color = IN.Color * vec4(color, 1.0);
//declare stuff
const int mSize = 13;
const int kSize = (mSize-1) / 2;

float kernel[mSize];
vec3 final_color = vec3(0.0);

//create the 1-D kernel
float sigma = 7.0;
float Z = 0.0;

for (int j = 0; j <= kSize; ++j)
{
kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), sigma);
}

//get the normalization factor (as the gaussian has been clamped)
for (int j = 0; j < mSize; ++j)
{
Z += kernel[j];
}

//read out the texels
for (int i=-kSize; i <= kSize; ++i)
{
for (int j=-kSize; j <= kSize; ++j)
{
final_color += kernel[kSize+j] * kernel[kSize+i] * texture(Texture, IN.Uv + vec2(float(i), float(j)) / Resolution).rgb;
}
}

Color = vec4(final_color / (Z*Z), 1.0);
}
5 changes: 0 additions & 5 deletions src/camera/mod.rs

This file was deleted.

59 changes: 0 additions & 59 deletions src/camera/movement.rs

This file was deleted.

138 changes: 0 additions & 138 deletions src/camera/target_camera.rs

This file was deleted.

64 changes: 29 additions & 35 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate render_gl_derive;
extern crate nalgebra;
extern crate vec_2_10_10_10;

pub mod camera;
mod cube;
mod debug;
mod quad;
Expand Down Expand Up @@ -73,37 +72,31 @@ fn run() -> Result<(), failure::Error> {
let mut viewport =
render_gl::Viewport::for_window(initial_window_size.0, initial_window_size.1);

// let distance = 10.0;
//
// let rotation =
// na::UnitQuaternion::from_axis_angle(&na::Vector3::x_axis(), ::std::f32::consts::PI / 2.0);
//
// let view = (na::Translation3::<f32>::from(na::Point3::origin().coords)
// * rotation
// * na::Translation3::<f32>::from(na::Vector3::z() * 3.0))
// // .inverse()
// .to_homogeneous();
//
// let mut projection = na::Orthographic3::new(
// 0.0,
// initial_window_size.0 as f32,
// initial_window_size.1 as f32,
// 0.0,
// 0.01,
// 1000.0,
// );

let cube = cube::Cube::new(&res, &gl)?;

let mut camera = camera::TargetCamera::new(
initial_window_size.0 as f32 / initial_window_size.1 as f32,
3.14 / 2.0,
let distance = 10.0;

let view = (na::Translation3::<f32>::from(na::Point3::origin().coords)
* na::Translation3::<f32>::from(na::Vector3::z() * distance))
.inverse()
.to_homogeneous();

let mut projection = na::Orthographic3::new(
0.0,
initial_window_size.0 as f32,
0.0,
initial_window_size.1 as f32,
0.01,
1000.0,
3.14 / 4.0,
3.0,
);

let quad = quad::Quad::new_with_size(
&res,
&gl,
0.0,
0.0,
initial_window_size.0 as f32,
initial_window_size.1 as f32,
)?;

viewport.set_used(&gl);

let color_buffer = render_gl::ColorBuffer::from_color(na::Vector3::new(0.3, 0.3, 0.5));
Expand All @@ -124,10 +117,8 @@ fn run() -> Result<(), failure::Error> {
viewport.update_size(w, h);
viewport.set_used(&gl);

camera.update_aspect(w as f32 / h as f32);

// projection.set_left_and_right(0.0, w as f32);
// projection.set_bottom_and_top(h as f32, 0.0);
projection.set_left_and_right(0.0, w as f32);
projection.set_bottom_and_top(h as f32, 0.0);
}
_ => {}
}
Expand All @@ -141,9 +132,12 @@ fn run() -> Result<(), failure::Error> {

color_buffer.clear(&gl);

// quad.render(&gl, &view, &projection.into_inner());

cube.render(&gl, &camera.get_view_matrix(), &camera.get_p_matrix());
quad.render(
&gl,
&view,
&projection.into_inner(),
&na::Vector2::<f32>::new(viewport.w as f32, viewport.h as f32),
);

window.gl_swap_window();
}
Expand Down
Loading

0 comments on commit 319a44c

Please sign in to comment.