From 3482c97d66930004d823462c19efb57a8fc1e5de Mon Sep 17 00:00:00 2001 From: Patrick Schönberger Date: Wed, 20 Jan 2021 12:30:16 +0100 Subject: Code Refactoring --- shaders/frag.glsl | 25 +++++++++++++++++++++++++ shaders/vert.glsl | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 shaders/frag.glsl create mode 100644 shaders/vert.glsl (limited to 'shaders') diff --git a/shaders/frag.glsl b/shaders/frag.glsl new file mode 100644 index 0000000..a92699c --- /dev/null +++ b/shaders/frag.glsl @@ -0,0 +1,25 @@ +#version 330 core + +in vec3 FragPos; +in vec3 Normal; + +out vec4 FragColor; + +uniform vec3 objectColor; +uniform vec3 lightColor; +uniform vec3 lightPos; + +void main() +{ + vec3 norm = normalize(Normal); + vec3 lightDir = normalize(lightPos - FragPos); + + float diff = max(dot(norm, lightDir), 0.0); + vec3 diffuse = diff * lightColor; + + float ambientStrength = 0.1; + vec3 ambient = ambientStrength * lightColor; + + vec3 result = (ambient + diffuse) * objectColor; + FragColor = vec4(result, 1.0f); +} \ No newline at end of file diff --git a/shaders/vert.glsl b/shaders/vert.glsl new file mode 100644 index 0000000..fc3721a --- /dev/null +++ b/shaders/vert.glsl @@ -0,0 +1,18 @@ +#version 330 core + +layout (location = 0) in vec3 pos; +layout (location = 1) in vec3 normal; + +out vec3 FragPos; +out vec3 Normal; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + +void main() +{ + gl_Position = projection * view * model * vec4(pos, 1.0); + FragPos = vec3(model * vec4(pos, 1)); + Normal = normal; +} \ No newline at end of file -- cgit v1.2.3