Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 420
- uniform vec4 meshColor;
- struct light {
- vec3 position;
- vec3 diffuse;
- vec3 specular;
- vec3 ambient;
- float attenuation;
- };
- uniform light[5] lights;
- uniform mat4 modelViewMatrix;
- // Textures
- uniform sampler2D diffuseTexture;
- uniform sampler2D depthTexture;
- uniform sampler2D normalTexture;
- uniform sampler2D specularTexture;
- // Colors
- uniform vec3 diffuseColor;
- uniform bool textured;
- uniform float shininess;
- uniform float glossiness;
- uniform float repeatx;
- uniform float repeaty;
- // Ouput data
- out vec4 fragColor;
- // Input data
- in vec4 Position;
- in vec4 ShadowCoordinates;
- in vec2 UV;
- in vec3 Normal;
- in vec3 LightDir;
- in vec3 ViewDir;
- vec3 ads( int lightIndex, vec3 norm, vec3 Color, vec3 specMap ) {
- vec3 lightDir = normalize(LightDir);
- vec3 viewDir = normalize(ViewDir);
- float visibility = 1.0;
- float bias = 0.0005;
- if ( texture( depthTexture, ShadowCoordinates.xy ).r < ShadowCoordinates.z - bias) {
- //visibility = 0.65;
- }
- vec3 r = reflect( -lightDir, norm );
- vec3 ambient = lights[0].ambient * Color;
- float sDotN = max( dot(lightDir, norm), 0.0 );
- vec3 diffuse = lights[0].diffuse * Color * sDotN;
- vec3 spec = vec3(0.0);
- if( sDotN > 0.0 && visibility == 1.0 )
- spec = shininess * (lights[0].specular * specMap * pow( max( dot(r,viewDir), 0.0 ), max(1.0, glossiness) ));
- return visibility * (ambient + diffuse + spec);
- }
- void main()
- {
- vec4 Color = vec4(diffuseColor, 1.0);
- vec3 normalMap = normalize(texture( normalTexture, vec2(UV.x*repeatx, UV.y*repeaty) ).rgb*2.0 - 1.0);
- vec4 specularMap = texture( specularTexture, vec2(UV.x*repeatx, UV.y*repeaty) );
- //if (textured)
- //Color = texture( diffuseTexture, vec2(UV.x*repeatx, UV.y*repeaty) );
- vec3 rcol = vec3(0.0);
- for (int i = 0; i < 1; i++)
- rcol += ads (i, normalMap, Color.rgb, specularMap.rbg);
- fragColor = vec4(rcol, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement