Grafika_Komputerowa_Interst.../cw 7/shaders/shader_5_tex.frag

67 lines
1.6 KiB
GLSL
Raw Normal View History

2024-01-12 20:37:53 +01:00
#version 430 core
2024-01-28 00:04:28 +01:00
float AMBIENT = 0.6;
float roughness = 0.2;
2024-01-20 00:28:55 +01:00
float metalic = 0.8;
2024-01-12 20:37:53 +01:00
uniform vec3 color;
uniform sampler2D colorTexture;
uniform sampler2D normalSampler;
2024-01-28 00:04:28 +01:00
uniform sampler2D metalnessTexture;
uniform sampler2D roughnessTexture;
2024-01-12 20:37:53 +01:00
in vec3 worldPos;
in vec2 vecTex;
in vec3 viewDirTS;
in vec3 lightDirTS;
out vec4 outColor;
void main()
{
vec3 normal = vec3(0,0,1);
2024-01-26 20:17:20 +01:00
vec3 L = (lightDirTS);
vec3 V = (viewDirTS);
2024-01-12 20:37:53 +01:00
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
2024-01-28 00:04:28 +01:00
float metalnessValue = texture2D(metalnessTexture, vecTex).r;
float roughnessValue = texture2D(roughnessTexture, vecTex).r;
2024-01-12 20:37:53 +01:00
vec3 N = texture2D(normalSampler, vecTex).xyz;
N = 2.0 * N - 1.0;
N = normalize(N);
2024-01-20 17:40:19 +01:00
vec3 H = normalize(L + V);
float NdotH = max(0.0, dot(N, H));
float NdotL = max(dot(N, L),0.0000001 );
2024-01-20 00:28:55 +01:00
float NdotV = max(0.0, dot(N, V));
2024-01-20 17:40:19 +01:00
float VdotH = max(0.00001, dot(V, H));
2024-01-20 00:28:55 +01:00
float k = pow((roughness +1),2.0)/8.0;
float D = (roughness * roughness) / (3.14159 * pow(pow(NdotH * NdotH,2.0) * (roughness * roughness - 1.0) + 1.0, 2.0));
float ggx1 = NdotV / (NdotV * (1.0 - k) + k);
float ggx2 = NdotL / (NdotL * (1.0 - k) + k);
vec3 F0 = vec3(0.04);
float G = ggx1 * ggx2;
2024-01-20 17:40:19 +01:00
vec3 F = F0 + (1.0-F0)*pow(1-dot(V,H),5.0);
2024-01-20 00:28:55 +01:00
2024-01-20 17:40:19 +01:00
vec3 specular = (D*G*F)/(4*NdotL*NdotV+0.00001);
2024-01-20 00:28:55 +01:00
vec3 kD = vec3(1.0) - F;
vec3 BRDF = kD*(textureColor/3.1458493) + specular;
2024-01-20 17:40:19 +01:00
float diffuse=max(0.0001,dot(N,L));
vec3 lambertian = max(0.00001, dot(N,L))*textureColor;
2024-01-20 00:28:55 +01:00
2024-01-20 17:40:19 +01:00
vec3 Final = (kD*textureColor/3.1458993) + specular;
outColor = vec4(Final*min(1.0,AMBIENT + diffuse), 1.0);
2024-01-12 20:37:53 +01:00
}