diff options
Diffstat (limited to 'src/render/shaders/gl3/normaldiffusespecularmap.frag')
-rw-r--r-- | src/render/shaders/gl3/normaldiffusespecularmap.frag | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/src/render/shaders/gl3/normaldiffusespecularmap.frag b/src/render/shaders/gl3/normaldiffusespecularmap.frag index 2d9d9e4f1..d6a5f44ae 100644 --- a/src/render/shaders/gl3/normaldiffusespecularmap.frag +++ b/src/render/shaders/gl3/normaldiffusespecularmap.frag @@ -1,58 +1,34 @@ #version 150 core -in vec3 lightDir; -in vec3 viewDir; +in vec3 position; in vec2 texCoord; +in mat3 tangentMatrix; uniform sampler2D diffuseTexture; uniform sampler2D specularTexture; uniform sampler2D normalTexture; -// TODO: Replace with a uniform block -uniform vec4 lightPosition; -uniform vec3 lightIntensity; - // TODO: Replace with a struct uniform vec3 ka; // Ambient reflectivity uniform float shininess; // Specular shininess factor -out vec4 fragColor; - -void adsModel( const in vec3 norm, const in vec3 diffuseReflect, out vec3 ambientAndDiff, out vec3 spec ) -{ - // Reflection of light direction about normal - vec3 r = reflect( -lightDir, norm ); - - // Calculate the ambient contribution - vec3 ambient = lightIntensity * ka; +uniform vec3 eyePosition; - // Calculate the diffuse contribution - float sDotN = max( dot( lightDir, norm ), 0.0 ); - vec3 diffuse = lightIntensity * diffuseReflect * sDotN; - - // Sum the ambient and diffuse contributions - ambientAndDiff = ambient + diffuse; +out vec4 fragColor; - // Calculate the specular highlight contribution - spec = vec3( 0.0 ); - if ( sDotN > 0.0 ) - spec = lightIntensity * ( shininess / ( 8.0 * 3.14 ) ) * pow( max( dot( r, viewDir ), 0.0 ), shininess ); -} +#pragma include light.inc.frag void main() { // Sample the textures at the interpolated texCoords vec4 diffuseTextureColor = texture( diffuseTexture, texCoord ); vec4 specularTextureColor = texture( specularTexture, texCoord ); - vec4 normal = 2.0 * texture( normalTexture, texCoord ) - vec4( 1.0 ); + vec3 normal = 2.0 * texture( normalTexture, texCoord ).rgb - vec3( 1.0 ); // Calculate the lighting model, keeping the specular component separate - vec3 ambientAndDiff, spec; - adsModel( normalize( normal.xyz ), diffuseTextureColor.xyz, ambientAndDiff, spec ); - - // Multiply specular factor by specular texture sample - vec3 specularColor = spec * specularTextureColor.rgb; + vec3 diffuseColor, specularColor; + adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor); // Combine spec with ambient+diffuse for final fragment color - fragColor = vec4( ambientAndDiff + specularColor, 1.0 ); + fragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + specularTextureColor.rgb * specularColor, 1.0 ); } |