grafika-projekt/cw 9/shaders/shader_5_1_tex.frag
Szymon Bartanowicz 27aa9b51ea init
2023-02-14 22:54:46 +01:00

32 lines
692 B
GLSL

#version 430 core
float AMBIENT = 0.1;
uniform vec3 color;
uniform vec3 lightPos;
uniform sampler2D colorTexture;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 vertTexCoord;
out vec4 outColor;
void main()
{
vec4 textureColor = texture2D(colorTexture, vec2(vertTexCoord.x, -vertTexCoord.y));
vec3 lightDir = normalize(lightPos-worldPos);
vec3 normal = normalize(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);
}