summaryrefslogtreecommitdiff
path: root/shaders/fragment.glsl
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2026-01-30 19:12:03 -0600
committerAaditya Dhruv <[email protected]>2026-01-30 19:12:03 -0600
commit1a721b98caf7559f4a18baa8d3b92269e8f1f6ce (patch)
tree32be8966361f8f8ae74c6c0af226e39fe9feb375 /shaders/fragment.glsl
parent4992ce0098cac8caef6c9315816b688d96259bce (diff)
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
Diffstat (limited to 'shaders/fragment.glsl')
-rw-r--r--shaders/fragment.glsl9
1 files changed, 6 insertions, 3 deletions
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;
};