From 655978efc2adb1df66610d8642a936a0a70d002d Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Sat, 22 Oct 2022 19:47:40 +0200 Subject: [PATCH] Pass directly `normal` to the fragment shader --- src/main.rs | 8 ++------ src/support/mod.rs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 38d7ad4..0ac99e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,16 +71,12 @@ fn main() { uniform mat4 persp_matrix; uniform mat4 view_matrix; - // can't skip directly to fragment shader an unmodified variable? - in vec3 normal; in uint index; in float altitude; - out vec3 v_normal; out vec2 v_tex_coords; void main() { - v_normal = normal; uint index_mod = index % 6u; uint index_div = index / 6u; uint z = index_div / 250u; @@ -110,7 +106,7 @@ fn main() { fragment: " #version 140 - in vec3 v_normal; + flat in vec3 normal; in vec2 v_tex_coords; out vec4 f_color; flat in uint biome; @@ -120,7 +116,7 @@ fn main() { const vec3 LIGHT = vec3(0.0, -1.0, 0.0); void main() { - float lum = max(dot(normalize(v_normal), normalize(LIGHT)), 0.0); + float lum = max(dot(normalize(normal), normalize(LIGHT)), 0.0); if(biome == 0u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex0, v_tex_coords); else if(biome == 1u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex1, v_tex_coords); diff --git a/src/support/mod.rs b/src/support/mod.rs index 38d9e46..05d5bb0 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -83,7 +83,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { biome: u32, } - implement_vertex!(Vertex, altitude, normal, index); + implement_vertex!(Vertex, altitude, normal, index, biome); let mut vertex_data: Vec = Vec::new();