Created
April 23, 2018 03:54
-
-
Save dotxnc/5d609a6feb08ff5f706cd90ef2e8f6f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 | |
in vec2 fragTexCoord; | |
in vec4 fragColor; | |
in vec3 fragNormal; | |
in vec3 fragPos; | |
uniform sampler2D texture0; | |
uniform vec3 lightDirection = vec3(1.f, -0.3f, -0.5f); | |
uniform vec4 diffuseLightColor = vec4(1.f, 1.f, 1.f, 1.f); | |
uniform vec4 ambientLight = vec4(0.3f, 0.3f, 0.3f, 1.f); | |
uniform vec3 viewPos; | |
out vec4 finalColor; | |
float fog(const float dist, const float density) | |
{ | |
const float l2 = -1.442695; | |
float d = density*dist; | |
return 1.0 - clamp(exp2(d*d*l2), 0.0, 1.0); | |
} | |
void main() | |
{ | |
vec4 textureColor; | |
vec4 color; | |
vec3 lightDir; | |
float lightIntensity; | |
textureColor = texture(texture0, fragTexCoord); | |
color = ambientLight; | |
lightDir = -lightDirection; | |
lightIntensity = clamp(dot(fragNormal, lightDir), 0.0f, 1.0f); | |
if (lightIntensity > 0.0f) { | |
color += (diffuseLightColor * lightIntensity); | |
} | |
vec3 viewDir = normalize(viewPos - fragPos); | |
vec3 reflectdir = reflect(-lightDir, fragNormal); | |
float spec = pow(max(dot(viewDir, reflectdir), 0.0), 1); | |
vec3 specular = 0.1*spec*diffuseLightColor.rgb; | |
color = clamp(color+vec4(specular, 1.0), 0.0f, 1.0f); | |
vec4 c = color*textureColor; | |
float fogDistance = gl_FragCoord.z/gl_FragCoord.w; | |
float fogAmount = fog(fogDistance, 0.05f); | |
const vec4 fogColor = vec4(0.0); | |
finalColor = vec4(mix(c, fogColor, fogAmount).rgb, 1.0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 | |
// Input vertex attributes | |
in vec3 vertexPosition; | |
in vec2 vertexTexCoord; | |
in vec3 vertexNormal; | |
in vec4 vertexColor; | |
// Input uniform values | |
uniform mat4 mvp; | |
uniform mat4 modelMatrix; | |
// uniform vec3 vertexNormal; | |
// Output vertex attributes (to fragment shader) | |
out vec2 fragTexCoord; | |
out vec4 fragColor; | |
out vec3 fragNormal; | |
out vec3 fragPos; | |
// NOTE: Add here your custom variables | |
void main() | |
{ | |
// Send vertex attributes to fragment shader | |
fragTexCoord = vertexTexCoord; | |
fragColor = vertexColor; | |
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); | |
fragNormal = normalize(normalMatrix*vertexNormal); | |
// fragNormal =vertexNormal; | |
fragPos = vec3(modelMatrix*vec4(vertexPosition, 1.0)); | |
gl_Position = mvp*vec4(vertexPosition, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment