summaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/shader.frag17
-rw-r--r--resources/shader.vert13
2 files changed, 22 insertions, 8 deletions
diff --git a/resources/shader.frag b/resources/shader.frag
index f81277d..0b81464 100644
--- a/resources/shader.frag
+++ b/resources/shader.frag
@@ -2,10 +2,25 @@
// Ouput data
in vec2 UV;
+in vec3 FragmentPos;
+in vec3 Normal;
out vec3 color;
uniform sampler2D textureSampler;
void main() {
- color = texture(textureSampler, UV).rgb;
+ vec3 light_color_ambient = vec3(0.4, 0.6, 0.9);
+ vec3 light_color_diffuse = vec3(0.8, 1.0, 1.0);
+
+ vec3 lightpos = vec3(16, 26, 32);
+
+ float ambient_strength = 0.3;
+ vec3 ambient = ambient_strength * light_color_ambient;
+
+ vec3 norm = normalize(Normal);
+ vec3 light_dir = normalize(lightpos - FragmentPos);
+
+ float diff = max(dot(norm, light_dir), 0.0);
+ vec3 diffuse = diff * light_color_diffuse;
+ color = (ambient + diffuse) * texture(textureSampler, UV).rgb;
}
diff --git a/resources/shader.vert b/resources/shader.vert
index e5aff9a..50e8218 100644
--- a/resources/shader.vert
+++ b/resources/shader.vert
@@ -3,21 +3,20 @@
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
+layout(location = 2) in vec3 vNorm;
out vec2 UV;
+out vec3 FragmentPos;
+out vec3 Normal;
uniform mat4 MVP;
+uniform mat4 modelPosition;
void main() {
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
UV = vertexUV;
-
- //fragmentcolor.x = vertexPosition_modelspace.x; //= vertexColor;
- //fragmentcolor.y = vertexPosition_modelspace.y; //= vertexColor;
- //fragmentcolor.z = vertexPosition_modelspace.z; //= vertexColor;
-
- //fragmentcolor += 1;
- //fragmentcolor /= 2;
+ FragmentPos = vec3(modelPosition * vec4(vertexPosition_modelspace,1));
+ Normal = vNorm;
}