58 lines
1.9 KiB
Plaintext
58 lines
1.9 KiB
Plaintext
#version 400 core
|
|
|
|
in vec2 pass_textureCoordinates;
|
|
in vec3 surfaceNormal;
|
|
in vec3 toLightVector;
|
|
in vec3 toCameraVector;
|
|
// FOW: Fog Of War result calculation
|
|
in float visibility;
|
|
|
|
out vec4 out_Color;
|
|
|
|
uniform sampler2D backgroundTexture;
|
|
uniform sampler2D rTexture;
|
|
uniform sampler2D gTexture;
|
|
uniform sampler2D bTexture;
|
|
uniform sampler2D blendMap;
|
|
|
|
uniform vec3 lightColour;
|
|
uniform float reflectivity;
|
|
uniform float shineDamper;
|
|
uniform vec3 skyColor;
|
|
|
|
|
|
void main(void) {
|
|
|
|
vec4 blendMapColour = texture(blendMap, pass_textureCoordinates);
|
|
|
|
float backTextureAmount = 1 - (blendMapColour.r + blendMapColour.g + blendMapColour.b);
|
|
vec2 tiledCoords = pass_textureCoordinates * 40.0;
|
|
vec4 backgroundTextureColour = texture(backgroundTexture, tiledCoords) * backTextureAmount;
|
|
vec4 rTextureColour = texture(rTexture, tiledCoords) * blendMapColour.r;
|
|
vec4 gTextureColour = texture(gTexture, tiledCoords) * blendMapColour.g;
|
|
vec4 bTextureColour = texture(bTexture, tiledCoords) * blendMapColour.b;
|
|
|
|
vec4 totalColour = backgroundTextureColour + rTextureColour + gTextureColour + bTextureColour;
|
|
|
|
vec3 unitNormal = normalize(surfaceNormal);
|
|
vec3 unitLightVector = normalize(toLightVector);
|
|
|
|
float nDot1 = dot(unitNormal, unitLightVector);
|
|
// the 0.2 represent the anbiant lightning ==> maybe set an uniform for this
|
|
float brightness = max(nDot1, 0.2);
|
|
vec3 diffuse = brightness * lightColour;
|
|
|
|
vec3 unitVectorToCamera = normalize(toCameraVector);
|
|
vec3 lightDirection = -unitLightVector;
|
|
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
|
|
|
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
|
|
specularFactor = max(specularFactor, 0.0);
|
|
float damperFactor = pow(specularFactor, shineDamper);
|
|
vec3 finalSpecular = damperFactor * reflectivity * lightColour;
|
|
|
|
out_Color = vec4(diffuse,1.0) * totalColour + vec4(finalSpecular, 1.0);
|
|
out_Color = mix(vec4(skyColor,1.0), out_Color, visibility);
|
|
}
|
|
|