Shader Work
parent
bad9c5d872
commit
f2ddde88a8
Binary file not shown.
After Width: | Height: | Size: 123 B |
|
@ -1,10 +1,18 @@
|
||||||
#version 140
|
#version 140
|
||||||
|
|
||||||
in vec2 v_tex_coords;
|
in vec2 v_tex_coords;
|
||||||
|
in vec3 v_frag_color;
|
||||||
|
in float v_sun_intensity;
|
||||||
|
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = texture(tex, v_tex_coords);
|
vec4 sun_color = vec4(v_sun_intensity , v_sun_intensity , 0.0, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
color = texture(tex, v_tex_coords) * vec4(v_frag_color, 1.0) * sun_color;
|
||||||
}
|
}
|
|
@ -2,11 +2,19 @@
|
||||||
|
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
in vec2 tex_coords;
|
in vec2 tex_coords;
|
||||||
|
in vec4 light_color;
|
||||||
|
|
||||||
|
out vec3 v_frag_color;
|
||||||
out vec2 v_tex_coords;
|
out vec2 v_tex_coords;
|
||||||
|
out float v_sun_intensity;
|
||||||
|
|
||||||
uniform mat4 matrix;
|
uniform mat4 matrix;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_tex_coords = tex_coords;
|
v_tex_coords = tex_coords;
|
||||||
|
|
||||||
|
v_frag_color = vec3(light_color.rgb);
|
||||||
|
v_sun_intensity = light_color.a;
|
||||||
|
|
||||||
gl_Position = matrix * vec4(position, 0.0, 1.0);
|
gl_Position = matrix * vec4(position, 0.0, 1.0);
|
||||||
}
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
}
|
32
src/main.rs
32
src/main.rs
|
@ -24,7 +24,7 @@ fn main() {
|
||||||
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
|
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
|
||||||
|
|
||||||
let image = image::load(
|
let image = image::load(
|
||||||
Cursor::new(&include_bytes!("../assets/opengl.png")),
|
Cursor::new(&include_bytes!("../assets/GrassTop.png")),
|
||||||
image::ImageFormat::Png,
|
image::ImageFormat::Png,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -38,16 +38,28 @@ fn main() {
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
position: [f32; 2],
|
position: [f32; 2],
|
||||||
tex_coords: [f32; 2],
|
tex_coords: [f32; 2],
|
||||||
|
light_color: [f32; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
implement_vertex!(Vertex, position, tex_coords);
|
implement_vertex!(Vertex, position, tex_coords, light_color);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
let vertex1 = Vertex {
|
||||||
let vertex1 = Vertex { position: [-0.5, -0.5], tex_coords: [0.0, 0.0] };
|
position: [-0.5, -0.5],
|
||||||
#[rustfmt::skip]
|
tex_coords: [0.0, 0.0],
|
||||||
let vertex2 = Vertex { position: [ 0.0, 0.5], tex_coords: [0.0, 1.0] };
|
light_color: [1.0, 1.0, 1.0, 0.0],
|
||||||
#[rustfmt::skip]
|
};
|
||||||
let vertex3 = Vertex { position: [ 0.5, -0.25], tex_coords: [1.0, 0.0] };
|
|
||||||
|
let vertex2 = Vertex {
|
||||||
|
position: [0.0, 0.5],
|
||||||
|
tex_coords: [0.0, 1.0],
|
||||||
|
light_color: [1.0, 0.0, 0.0, 1.0],
|
||||||
|
};
|
||||||
|
|
||||||
|
let vertex3 = Vertex {
|
||||||
|
position: [0.5, -0.25],
|
||||||
|
tex_coords: [1.0, 0.0],
|
||||||
|
light_color: [0.0, 1.0, 0.0, 0.5],
|
||||||
|
};
|
||||||
|
|
||||||
let shape = vec![vertex1, vertex2, vertex3];
|
let shape = vec![vertex1, vertex2, vertex3];
|
||||||
|
|
||||||
|
@ -122,7 +134,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut target = display.draw();
|
let mut target = display.draw();
|
||||||
target.clear_color(0.0, 0.0, 1.0, 0.0);
|
target.clear_color(0.0, 0.0, 1.0, 1.0);
|
||||||
|
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
matrix: [
|
matrix: [
|
||||||
|
@ -132,6 +144,8 @@ fn main() {
|
||||||
[ t , 0.0, 0.0, 1.0f32],
|
[ t , 0.0, 0.0, 1.0f32],
|
||||||
],
|
],
|
||||||
tex: &texture,
|
tex: &texture,
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
target
|
target
|
||||||
|
|
Loading…
Reference in New Issue