31 lines
705 B
GLSL
31 lines
705 B
GLSL
#version 430 core
|
|
|
|
float AMBIENT = 0.1;
|
|
|
|
uniform vec3 color;
|
|
uniform vec3 lightPos;
|
|
uniform sampler2D colorTexture;
|
|
|
|
in vec3 f_vecNormal;
|
|
in vec3 f_worldPos;
|
|
in vec2 f_vertTexCoord;
|
|
|
|
out vec4 outColor;
|
|
void main()
|
|
{
|
|
vec4 textureColor = texture2D(colorTexture, vec2(f_vertTexCoord.x, -f_vertTexCoord.y));
|
|
|
|
vec3 lightDir = normalize(lightPos-f_worldPos);
|
|
vec3 normal = normalize(f_vecNormal);
|
|
float diffuse=max(0,dot(normal,lightDir));
|
|
|
|
//fog
|
|
float n = 0.05;
|
|
float f = 20.0;
|
|
vec4 bgColor = {0.0, 0.3, 0.3, 1.0};
|
|
float z = (-2 * n * f) / (gl_FragCoord.z * (n - f) + n + f);
|
|
|
|
outColor = vec4(textureColor.xyz*min(1,AMBIENT+diffuse), 1.0);
|
|
|
|
outColor = mix(outColor, bgColor, z/f * -1);
|
|
} |