projekt_grafika/cw 2/shaders/shader_tex_new.frag

51 lines
1.4 KiB
GLSL
Raw Normal View History

2022-02-13 01:51:44 +01:00
#version 410 core
uniform sampler2D textureSampler;
uniform sampler2D normalSampler;
uniform vec3 lightPos;
uniform vec3 cameraPos;
in vec3 interpNormal;
in vec2 interpTexCoord;
in vec3 fragPos;
in vec3 viewDirTS;
in vec3 lightDirTS;
float near = 0.25f;
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 logisticDepth(float depth, float steepness, float offset)
{
float zVal = linearizeDepth(depth);
return (1 / (1 + exp(-steepness * (zVal - offset))));
}
void main()
{
float depth = logisticDepth(gl_FragCoord.z, 0.5f, 5.0f);
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 lightDir = normalize(lightDirTS);
vec3 V = normalize(viewDirTS);
vec3 normal = normalize(vec3(texture2D(normalSampler, modifiedTexCoord)) * 2 - 1);
vec3 R = reflect(-normalize(lightDir),normal);
float specular = pow(max(0,dot(R,V)),100);
float diffuse = max(0,dot(normal,normalize(lightDir)));
gl_FragColor = vec4(mix(color,color*diffuse+vec3(1)*specular,0.9), 1.0) * (1.0f - depth) + vec4(depth * vec3(5.0f/255.0f, 35.0f/255.0f, 95.0f/255.0f), 1.0f);
}