summaryrefslogtreecommitdiff
path: root/shaders
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
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')
-rw-r--r--shaders/fragment.glsl9
-rw-r--r--shaders/vertex.glsl3
2 files changed, 9 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;
};
diff --git a/shaders/vertex.glsl b/shaders/vertex.glsl
index 2af2c7e..9323f87 100644
--- a/shaders/vertex.glsl
+++ b/shaders/vertex.glsl
@@ -2,14 +2,17 @@
layout(location=0) in vec3 pos;
layout(location=1) in vec3 v_normal;
+layout(location=2) in vec2 i_text_coord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 perspective;
out vec3 normal;
out vec3 frag_pos;
+out vec2 text_coord;
void main() {
gl_Position = perspective*view*model*vec4(pos, 1.0);
normal = v_normal;
+ text_coord = i_text_coord;
frag_pos = vec3(model*vec4(pos, 1.0));
};