GRK-Projekt/grafika_projekt/shaders/shader_tex.frag

28 lines
835 B
GLSL
Raw Normal View History

2021-12-27 15:25:54 +01:00
#version 410 core
uniform sampler2D textureSampler;
//uniform vec3 lightDir;
uniform vec3 lightPos;
uniform vec3 cameraPos;
uniform vec3 objectColor;
2021-12-27 15:25:54 +01:00
in vec3 fragPos;
2021-12-27 15:25:54 +01:00
in vec3 interpNormal;
in vec2 interpTexCoord;
2022-01-01 14:05:58 +01:00
2021-12-27 15:25:54 +01:00
void main()
{
vec3 lightDir = normalize(lightPos-fragPos);
vec3 V = normalize(cameraPos-fragPos);
2021-12-27 15:25:54 +01:00
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
vec3 normal = normalize(interpNormal);
float diffuse = max(0,dot(normal,normalize(lightDir)));
vec3 R = reflect(-normalize(lightDir),normal);
2021-12-30 14:42:41 +01:00
float ambient = 0.2;
float specular = pow(max(0,dot(R,V)),1000);
gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0);
2021-12-27 15:25:54 +01:00
}