2021-12-27 15:25:54 +01:00
|
|
|
#version 410 core
|
|
|
|
|
|
|
|
uniform sampler2D textureSampler;
|
2022-01-13 22:06:03 +01:00
|
|
|
uniform vec3 lightDir;
|
2021-12-30 18:06:40 +01:00
|
|
|
uniform vec3 lightPos;
|
|
|
|
uniform vec3 cameraPos;
|
|
|
|
uniform vec3 objectColor;
|
2021-12-27 15:25:54 +01:00
|
|
|
|
2021-12-30 18:06:40 +01:00
|
|
|
in vec3 fragPos;
|
2021-12-27 15:25:54 +01:00
|
|
|
in vec3 interpNormal;
|
|
|
|
in vec2 interpTexCoord;
|
|
|
|
|
2022-01-08 15:55:06 +01:00
|
|
|
float near = 0.02f;
|
|
|
|
float far = 100.0f;
|
|
|
|
|
|
|
|
float linearizeDepth(float depth)
|
|
|
|
{
|
|
|
|
return (2.0 * near * far) / (far + near - (depth * 2.0 - 1.0) * (far - near));
|
|
|
|
}
|
|
|
|
|
|
|
|
float logisticDepth(float depth, float steepness, float offset)
|
|
|
|
{
|
|
|
|
float zVal = linearizeDepth(depth);
|
|
|
|
return (1 / (1 + exp(-steepness * (zVal - offset))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-27 15:25:54 +01:00
|
|
|
void main()
|
|
|
|
{
|
2022-01-08 15:55:06 +01:00
|
|
|
float depth = logisticDepth(gl_FragCoord.z, 0.1f, 3.0f);
|
2021-12-30 18:06:40 +01:00
|
|
|
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);
|
2021-12-30 18:06:40 +01:00
|
|
|
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;
|
2021-12-30 18:06:40 +01:00
|
|
|
float specular = pow(max(0,dot(R,V)),1000);
|
2022-01-08 15:55:06 +01:00
|
|
|
gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0) * (1.0f - depth) + vec4(depth * vec3(0.0f, 0.109f, 0.447f), 1.0f);;
|
2021-12-30 18:06:40 +01:00
|
|
|
|
2021-12-27 15:25:54 +01:00
|
|
|
}
|