Advertisement
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()
- {
- const float PI = 3.14159;
- vec3 albedo = texture(textureMap, texCoord).rgb;
- vec3 normals = normalize(texture(normalMap, texCoord).rgb * 2.0 - 1.0);
- float roughness = texture(roughMap, texCoord).r;
- float AO = texture(AOMap, texCoord).r;
- float NdotV = clamp(dot(normals, camDir), 0.0, 1.0);
- float angleVN = acos(NdotV);
- vec3 OrenNayar = vec3(0.0);
- vec3 ambientColour = vec3(0.0);
- for (int i = 0; i < 1; i++)
- {
- float radius = 50.0;
- float NdotL = clamp(dot(normals, lightDir), 0.0, 1.0);
- float angleLN = acos(NdotL);
- float alpha = max(angleVN, angleLN);
- float beta = min(angleVN, angleLN);
- float gamma = cos(angleVN - angleLN);
- float roughness2 = roughness * roughness;
- float A = 1.0 - 0.5 * (roughness2 / (roughness2 + 0.57));
- float B = 0.45 * (roughness2 / (roughness2 + 0.09));
- float C = sin(alpha) * tan(beta);
- vec3 diffuse = lightColour * (NdotL * (A + ((B * max(0.0, gamma)) * C)));
- OrenNayar += diffuse * attenuation;
- ambientColour += lightColour * attenuation;
- }
- vec3 ambience = (0.01 * ambientColour) * AO;
- vec3 final = albedo * (OrenNayar + ambience);
- final = pow(final, vec3(1.0 / 2.2));
- FragColour = vec4(final, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement