2024-01-11 17:57:31 +01:00
|
|
|
#version 430 core
|
|
|
|
|
2024-02-07 15:31:46 +01:00
|
|
|
float AMBIENT = 0.2;
|
2024-01-11 17:57:31 +01:00
|
|
|
|
|
|
|
uniform vec3 lightPos;
|
2024-02-07 15:22:05 +01:00
|
|
|
uniform vec3 viewPos;
|
|
|
|
|
|
|
|
in vec3 FragPos; // Pozycja fragmentu
|
|
|
|
in vec3 Normal; // Normalna fragmentu
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
// Obliczenie faktora odbicia ?wietlnego dla modelu PBR
|
|
|
|
float DistributionGGX(vec3 N, vec3 H, float roughness);
|
|
|
|
float GeometrySchlickGGX(float NdotV, float roughness);
|
|
|
|
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
|
2024-01-11 17:57:31 +01:00
|
|
|
|
2024-02-07 15:31:46 +01:00
|
|
|
const float PI = 3.14159265359;
|
|
|
|
|
2024-01-11 17:57:31 +01:00
|
|
|
in vec3 vecNormal;
|
|
|
|
in vec3 worldPos;
|
|
|
|
in vec2 texCoord;
|
|
|
|
out vec4 outColor;
|
2024-02-07 15:31:46 +01:00
|
|
|
|
2024-01-11 17:57:31 +01:00
|
|
|
void main()
|
|
|
|
{
|
2024-02-07 15:31:46 +01:00
|
|
|
|
|
|
|
vec3 lightDir = normalize(lightPos - worldPos);
|
|
|
|
vec3 normal = normalize(vecNormal);
|
|
|
|
|
|
|
|
|
|
|
|
float diffuse = max(0.0, dot(normal, lightDir));
|
|
|
|
diffuse = clamp(diffuse + 0.2, 0.0, 1.0);
|
|
|
|
|
|
|
|
|
|
|
|
vec3 viewDir = normalize(-worldPos);
|
|
|
|
vec3 halfwayDir = normalize(lightDir + viewDir);
|
|
|
|
float specularStrength = 0.7; // Increase specular strength
|
|
|
|
float specular = pow(max(0.0, dot(normal, halfwayDir)), 32);
|
|
|
|
|
|
|
|
vec4 textureColor = texture(colorTexture, texCoord);
|
|
|
|
vec3 finalColor = textureColor.rgb * (AMBIENT + diffuse) + specularStrength * specular;
|
|
|
|
|
|
|
|
outColor = vec4(finalColor, textureColor.a);
|
2024-01-11 17:57:31 +01:00
|
|
|
}
|