Shader Work

master
Able 2022-03-29 05:58:46 -05:00
parent bad9c5d872
commit f2ddde88a8
Signed by: able
GPG Key ID: D164AF5F5700BE51
8 changed files with 56 additions and 10 deletions

BIN
assets/GrassTop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

View File

@ -1,10 +1,18 @@
#version 140
in vec2 v_tex_coords;
in vec3 v_frag_color;
in float v_sun_intensity;
out vec4 color;
uniform sampler2D tex;
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;
}

View File

@ -2,11 +2,19 @@
in vec2 position;
in vec2 tex_coords;
in vec4 light_color;
out vec3 v_frag_color;
out vec2 v_tex_coords;
out float v_sun_intensity;
uniform mat4 matrix;
void main() {
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);
}

View File

@ -0,0 +1,4 @@
#version 140
void main() {
}

View File

@ -0,0 +1,4 @@
#version 140
void main() {
}

View File

@ -0,0 +1,4 @@
#version 140
void main() {
}

View File

@ -0,0 +1,4 @@
#version 140
void main() {
}

View File

@ -24,7 +24,7 @@ fn main() {
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
let image = image::load(
Cursor::new(&include_bytes!("../assets/opengl.png")),
Cursor::new(&include_bytes!("../assets/GrassTop.png")),
image::ImageFormat::Png,
)
.unwrap()
@ -38,16 +38,28 @@ fn main() {
struct Vertex {
position: [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 { position: [-0.5, -0.5], tex_coords: [0.0, 0.0] };
#[rustfmt::skip]
let vertex2 = Vertex { position: [ 0.0, 0.5], tex_coords: [0.0, 1.0] };
#[rustfmt::skip]
let vertex3 = Vertex { position: [ 0.5, -0.25], tex_coords: [1.0, 0.0] };
let vertex1 = Vertex {
position: [-0.5, -0.5],
tex_coords: [0.0, 0.0],
light_color: [1.0, 1.0, 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];
@ -122,7 +134,7 @@ fn main() {
}
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! {
matrix: [
@ -132,6 +144,8 @@ fn main() {
[ t , 0.0, 0.0, 1.0f32],
],
tex: &texture,
};
target