diff options
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/dummy.fsh | 36 | ||||
-rw-r--r-- | shaders/dummy.vsh | 4 |
2 files changed, 35 insertions, 5 deletions
diff --git a/shaders/dummy.fsh b/shaders/dummy.fsh index 472bb26..75c7ef2 100644 --- a/shaders/dummy.fsh +++ b/shaders/dummy.fsh @@ -1,17 +1,47 @@ #version 330 core - struct Material { vec3 ambient; vec3 diffuse; vec3 specular; + int illum; float Ns; }; -uniform Material mtl; +struct DirLight { + vec3 direction; + + vec3 ambient; + vec3 diffuse; + vec3 specular; +}; + out vec4 FragColor; +in vec3 FragPos; +in vec3 Normal; +in vec2 TexCoords; + +uniform vec3 viewPos; +uniform DirLight dirLight; +uniform Material mtl; + + + void main() { - FragColor = vec4(mtl.diffuse, 1.0); + vec3 norm = normalize(Normal); + vec3 viewDir = normalize(viewPos - FragPos); + + vec3 lightDir = normalize(-dirLight.direction); + float diff = max(dot(norm, lightDir), 0.0); + + vec3 reflectDir = normalize(reflect(-lightDir, norm)); + float spec = pow(max(dot(viewDir, reflectDir), 0.0), mtl.Ns); + + vec3 ambient = dirLight.ambient * mtl.ambient; + vec3 diffuse = diff * dirLight.diffuse * mtl.diffuse; + vec3 specular = spec * dirLight.specular * mtl.specular; + + FragColor = vec4(ambient + diffuse + specular, 1.0); } diff --git a/shaders/dummy.vsh b/shaders/dummy.vsh index bd540ab..d3a2082 100644 --- a/shaders/dummy.vsh +++ b/shaders/dummy.vsh @@ -15,6 +15,6 @@ void main() { gl_Position = proj * view * model * vec4(aPos, 1.0f); FragPos = vec3(model * vec4(aPos, 1.0)); - //Normal = vec3(rotNormals * vec4(aNormal, 1.0)); - //TexCoords = aTexCoords; + Normal = vec3(rotNormals * vec4(aNormal, 1.0)); + TexCoords = aTexCoords; } |