grk464933/cw 8/shaders/shader_8_1.frag
2024-02-02 11:19:35 +01:00

44 lines
901 B
GLSL

#version 430 core
float AMBIENT = 0.2;
uniform vec3 color;
uniform float metalness;
uniform float roughness;
in vec3 worldPos;
in vec2 vecTex;
in vec3 viewDirTS;
in vec3 lightDirTS;
out vec4 outColor;
void main()
{
vec3 normal = vec3(0,0,1);
vec3 L = (lightDirTS);
vec3 V = (viewDirTS);
vec3 H = normalize(L + V);
float k = pow((roughness +1),2.0)/8.0;
float D = (roughness * roughness) / (3.14159 * pow(pow(dot(normal, H), 2.0) * (roughness * roughness - 1.0) + 1.0, 2.0));
float G = dot(normal,L) / (dot(normal,L) * (1.0 - k) + k);
vec3 F0 = mix(vec3(0.04), color, metalness);
vec3 F = F0 + (1.0 - F0)* pow(1 - dot(V,H), 5.0);
vec3 specular = (D*G*F)/(4 * dot(normal,L)* dot(normal,V) + 0.00001);
vec3 kD = vec3(1.0) - F;
vec3 BRDF = kD * (color/3.1458493) + specular;
float diffuse=max(0.0001,dot(normal,L));
outColor = vec4(BRDF*min(1.0,AMBIENT + diffuse), 1.0);
}