Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
322AdvancedGraphics/fragmentShader.glsl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
46 lines (37 sloc)
1.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 420 core | |
in vec3 FragPos; | |
in vec2 texCoordsExport; | |
in vec3 normalExport; | |
out vec4 colorsOut; | |
struct Light | |
{ | |
vec4 ambCols; | |
vec4 difCols; | |
vec4 specCols; | |
vec4 direction; | |
}; | |
struct Material | |
{ | |
vec4 ambRefl; | |
vec4 difRefl; | |
vec4 specRefl; | |
vec4 emitCols; | |
float shininess; | |
}; | |
uniform sampler2D texture2D; | |
uniform Light light0; | |
uniform Material material; | |
uniform vec3 viewPos; | |
void main(void) | |
{ | |
vec3 normal = normalize(normalExport); | |
vec3 lightDirection = vec3(light0.direction); | |
vec4 diffuse = max(dot(normal, lightDirection), 0.0f) * (light0.difCols * material.difRefl); | |
vec3 viewDir = normalize(viewPos - FragPos); | |
vec3 reflectDir = reflect(-lightDirection, normal); | |
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); | |
vec4 specular = light0.specCols * spec * material.specRefl; | |
//colorsOut = specular; | |
//((vec4(vec3(min(diffuse, vec4(1.0))), 1.0) + light0.ambCols + material.emitCols) | |
colorsOut = (diffuse + light0.ambCols + material.emitCols) * texture(texture2D, texCoordsExport); | |
} |