89 lines
1.8 KiB
GLSL
89 lines
1.8 KiB
GLSL
#version 330 core
|
|
|
|
uniform vec3 lightColor;
|
|
|
|
uniform float materialNs;
|
|
uniform int objectId;
|
|
|
|
#ifdef ALPHA_MASK
|
|
uniform sampler2D alphaMask;
|
|
#endif
|
|
|
|
#ifdef AMBIENT_TEXTURE
|
|
uniform sampler2D ambientTexture;
|
|
#else
|
|
uniform vec3 materialKa;
|
|
#endif
|
|
|
|
#ifdef DIFFUSE_TEXTURE
|
|
uniform sampler2D diffuseTexture;
|
|
#else
|
|
uniform vec3 materialKd;
|
|
#endif
|
|
|
|
#ifdef SPECULAR_TEXTURE
|
|
uniform sampler2D specularTexture;
|
|
#else
|
|
uniform vec3 materialKs;
|
|
#endif
|
|
|
|
#ifdef NORMAL_MAP
|
|
uniform sampler2D normalMap;
|
|
|
|
in mat3 tangentSpace;
|
|
#else
|
|
in vec3 varNormal;
|
|
#endif
|
|
|
|
in vec2 varTexCoord;
|
|
|
|
in vec3 lightDirInView;
|
|
in vec3 halfVecInView;
|
|
|
|
layout(location = 0)out vec4 outColor;
|
|
|
|
vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){
|
|
float diffuseComponent = max(dot(normal, lightDir), 0);
|
|
float specularComponent = max(dot(halfVec, normal), 0);
|
|
return color*diffuseComponent*(kd+ks*pow(specularComponent, ns));
|
|
}
|
|
|
|
void main(void) {
|
|
#ifdef
|
|
#ifdef ALPHA_MASK
|
|
if(texture(alphaMask, varTexCoord).r < 0.5)
|
|
discard;
|
|
#endif
|
|
|
|
#ifdef NORMAL_MAP
|
|
vec3 normal = normalize(texture(normalMap, varTexCoord).xyz * tangentSpace);
|
|
#else
|
|
vec3 normal = normalize(varNormal);
|
|
#endif
|
|
|
|
#ifdef AMBIENT_TEXTURE
|
|
vec3 ambient = texture(ambientTexture, varTexCoord).rgb;
|
|
#else
|
|
vec3 ambient = materialKa;
|
|
#endif
|
|
|
|
#ifdef DIFFUSE_TEXTURE
|
|
vec3 diffuse = texture(diffuseTexture, varTexCoord).rgb;
|
|
#else
|
|
vec3 diffuse = materialKd;
|
|
#endif
|
|
|
|
#ifdef SPECULAR_TEXTURE
|
|
vec3 specular = texture(specularTexture, varTexCoord).rgb;
|
|
#else
|
|
vec3 specular = materialKs;
|
|
#endif
|
|
|
|
#ifdef AMBIENT_LIGHT
|
|
outColor = vec4(ambient + lightColor*diffuse, 1);
|
|
#else
|
|
vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView);
|
|
outColor = vec4(light, 1);
|
|
#endif
|
|
}
|