Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - /////////////////////////////////////////////////////
 - ////////////////////VERTEX SHADER////////////////////
 - /////////////////////////////////////////////////////
 - #version 330
 - layout(location = 0) in vec3 inPosition;
 - layout(location = 1) in vec3 inNormal;
 - layout(location = 2) in vec2 inTexCoord;
 - layout(location = 3) in vec3 inTangent;
 - layout(location = 4) in vec3 inBitangent;
 - out vec2 texCoord;
 - out vec3 camDir;
 - out vec3 lightDir;
 - out float attenuation;
 - uniform mat4 viewMatrix;
 - uniform mat4 modelMatrix;
 - uniform mat4 projectionMatrix;
 - uniform mat3 normalMatrix;
 - uniform vec3 camPosIn;
 - uniform vec3 lightPosIn;
 - void main()
 - {
 - vec3 N = normalize(normalMatrix * inNormal);
 - vec3 T = normalize(normalMatrix * inTangent);
 - T = normalize(T - (dot(N, T) * N));
 - vec3 B = normalize(normalMatrix * inBitangent);
 - if (dot(cross(N, T), B) < 0.0)
 - T = T * -1.0;
 - mat3 TBNMatrix = transpose(mat3(T, B, N));
 - vec3 position = vec3((viewMatrix * modelMatrix) * vec4(inPosition, 1.0)); //Vector is a position so W = 1.0. If it were a direction w = 0.0.
 - camDir = TBNMatrix * (normalize(camPosIn - position));
 - lightDir = TBNMatrix * (normalize(lightPosIn - position));
 - texCoord = inTexCoord;
 - float radius = 50.0;
 - float dist = length(vec3((viewMatrix * modelMatrix) * vec4(lightPosIn, 1.0)) - position);
 - attenuation = 1.0 / (1.0 + ((2.0 / radius) * dist) + ((1.0 / (radius * radius)) * (dist * dist)));
 - gl_Position = (projectionMatrix * (viewMatrix * modelMatrix)) * vec4(inPosition, 1.0);
 - }
 - ///////////////////////////////////////////////////////
 - ////////////////////FRAGMENT SHADER////////////////////
 - ///////////////////////////////////////////////////////
 - #version 330
 - precision mediump float;
 - in vec2 texCoord;
 - in vec3 camDir;
 - in vec3 lightDir;
 - in float attenuation;
 - layout (location = 0) out vec4 FragColour;
 - uniform sampler2D textureMap;
 - uniform sampler2D normalMap;
 - uniform sampler2D AOMap;
 - uniform sampler2D specMap;
 - uniform sampler2D roughMap;
 - uniform vec3 lightColour;
 - void main()
 - {
 - vec3 albedo = texture(textureMap, texCoord).rgb;
 - vec3 normals = normalize(texture(normalMap, texCoord).rgb * 2.0 - 1.0);
 - vec3 cel = vec3(0.0);
 - for (int i = 0; i < 1; i++)
 - {
 - float NdotL = clamp(dot(normals, lightDir), 0.0, 1.0);
 - vec3 D = vec3(0.0);
 - if (NdotL > 0.95)
 - D = lightColour * 1.0;
 - else if (NdotL > 0.5)
 - D = lightColour * 0.6;
 - else if (NdotL > 0.25)
 - D = lightColour * 0.4;
 - else
 - D = lightColour * 0.2;
 - cel += D;
 - }
 - cel = pow(cel, vec3(2.2));
 - vec3 final = albedo * cel;
 - final = pow(final, vec3(1.0 / 2.2));
 - FragColour = vec4(final, 1.0);
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment