9 uniform vec3 lightPos;
\r
10 uniform vec3 lightColor;
\r
11 uniform vec3 objectColor;
\r
12 uniform vec3 viewPos;
\r
13 uniform sampler2D irradianceTexture;
\r
14 uniform int screenWidth;
\r
15 uniform int screenHeight;
\r
16 uniform int renderState;
\r
17 uniform vec2 samplePositions[13];
\r
18 uniform vec3 sampleWeights[13];
\r
19 uniform float transmittanceScale;
\r
23 if (renderState == 0) {
\r
24 FragColor = texture(irradianceTexture, UV);
\r
26 else if (renderState == 1) {
\r
27 vec3 norm = normalize(Normal);
\r
28 vec3 lightDir = normalize(lightPos - FragPos);
\r
30 float diff = max(dot(norm, lightDir), 0.0);
\r
31 vec3 diffuse = diff * lightColor;
\r
33 float ambientStrength = 0.1;
\r
34 vec3 ambient = ambientStrength * lightColor;
\r
36 float specularStrength = 0.5;
\r
37 vec3 viewDir = normalize(viewPos - FragPos);
\r
38 vec3 reflectDir = reflect(-lightDir, norm);
\r
39 float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
\r
40 vec3 specular = specularStrength * spec * lightColor;
\r
42 vec3 result = (ambient + diffuse + specular) * objectColor;
\r
44 FragColor = vec4(result, 1.0);
\r
46 else if (renderState == 2) {
\r
47 vec4 result = vec4(0, 0, 0, 1);
\r
48 for (int i = 0; i < 13; i++) {
\r
49 vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);
\r
50 //vec4 sample = texture(irradianceTexture, sampleCoords)
\r
51 // * texture(shadowmapTexture, sampleCoords);
\r
52 vec4 sample = texture(irradianceTexture, sampleCoords);
\r
53 vec4 weight = vec4(sampleWeights[i], 1);
\r
54 result += sample * weight;
\r
58 else if (renderState == 3) {
\r
59 vec3 norm = normalize(Normal);
\r
60 vec3 lightDir = normalize(lightPos - FragPos);
\r
62 float diff = max(dot(norm, lightDir), 0.0);
\r
63 vec3 diffuse = diff * lightColor;
\r
65 float ambientStrength = 0.1;
\r
66 vec3 ambient = ambientStrength * lightColor;
\r
68 float specularStrength = 0.5;
\r
69 vec3 viewDir = normalize(viewPos - FragPos);
\r
70 vec3 reflectDir = reflect(-lightDir, norm);
\r
71 float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
\r
72 vec3 specular = specularStrength * spec * lightColor;
\r
74 vec3 result = vec3((ambient + diffuse + specular) * objectColor);
\r
76 vec3 result2 = vec3(0, 0, 0);
\r
77 for (int i = 0; i < 13; i++) {
\r
78 vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);
\r
79 //vec4 sample = texture(irradianceTexture, sampleCoords)
\r
80 // * texture(shadowmapTexture, sampleCoords);
\r
81 vec3 sample = vec3(texture(irradianceTexture, sampleCoords));
\r
82 vec3 weight = sampleWeights[i];
\r
83 result2 += sample * weight;
\r
86 result = sqrt(result * result2);
\r
88 vec4 t = texture(irradianceTexture, UV);
\r
90 float BacksideIrradiance = t.r; //*100 + t.g + t.b/100;
\r
92 vec3 Backside = (lightPos + (normalize(FragPos - lightPos) * BacksideIrradiance));
\r
94 float distanceToBackside = length(FragPos - Backside);
\r
95 if (distanceToBackside != 0)
\r
96 result += objectColor * exp(2 / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff);
\r
98 FragColor = vec4(result, 1);
\r