From 1a721b98caf7559f4a18baa8d3b92269e8f1f6ce Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Fri, 30 Jan 2026 19:12:03 -0600 Subject: Add basic block textures - Remove the code that sent colors through uniform variables, instead send texture data - Each vertex now has a texture coordinate - struct texture is a easy way to represent textures, can be extended later - Shaders updated to use textures --- shaders/fragment.glsl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'shaders/fragment.glsl') diff --git a/shaders/fragment.glsl b/shaders/fragment.glsl index e3bd9db..6222c27 100644 --- a/shaders/fragment.glsl +++ b/shaders/fragment.glsl @@ -4,12 +4,15 @@ uniform vec3 face_colors[6]; uniform vec3 light_color; in vec3 normal; in vec3 frag_pos; +in vec2 text_coord; +uniform sampler2D block_texture; void main() { vec3 ambient_color = vec3(0.1); vec3 norm = normalize(normal); - vec3 light_dir = normalize(vec3(1.0f, 1.0f, 1.0f)); + vec3 light_dir = normalize(vec3(1.0f, 2.0f, 1.0f)); float diff = max(dot(norm, light_dir), 0.0); vec3 diffuse = diff * vec3(1.0); - - frag_colour = vec4((ambient_color + diffuse) * face_colors[gl_PrimitiveID/2], 1.0); + vec4 final_texture = texture(block_texture, text_coord); + vec4 lighting = vec4(ambient_color + diffuse, 1.0f); + frag_colour = lighting * final_texture; }; -- cgit