Pass directly normal to the fragment shader

This commit is contained in:
2022-10-22 19:47:40 +02:00
parent 33628ef7bc
commit 655978efc2
2 changed files with 3 additions and 7 deletions
+2 -6
View File
@@ -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);
+1 -1
View File
@@ -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<Vertex> = Vec::new();