\r
void main()\r
{\r
- if (renderState == 0) {\r
- FragColor = texture(irradianceTexture, UV);\r
- }\r
- else if (renderState == 1) {\r
- vec3 norm = normalize(Normal);\r
- vec3 lightDir = normalize(lightPos - FragPos);\r
-\r
- float diff = max(dot(norm, lightDir), 0.0);\r
- vec3 diffuse = diff * lightColor;\r
-\r
- float ambientStrength = 0.1;\r
- vec3 ambient = ambientStrength * lightColor;\r
-\r
- float specularStrength = 0.5;\r
- vec3 viewDir = normalize(viewPos - FragPos);\r
- vec3 reflectDir = reflect(-lightDir, norm);\r
- float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);\r
- vec3 specular = specularStrength * spec * lightColor;\r
-\r
- vec3 result = (ambient + diffuse + specular) * objectColor;\r
- \r
- FragColor = vec4(result, 1.0);\r
- }\r
- else if (renderState == 2) {\r
- vec4 result = vec4(0, 0, 0, 1);\r
- for (int i = 0; i < 13; i++) {\r
- vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);\r
- //vec4 sample = texture(irradianceTexture, sampleCoords)\r
- // * texture(shadowmapTexture, sampleCoords);\r
- vec4 sample = texture(irradianceTexture, sampleCoords);\r
- vec4 weight = vec4(sampleWeights[i], 1);\r
- result += sample * weight;\r
- }\r
- FragColor = result;\r
- }\r
- else if (renderState == 3) {\r
+ // light the model\r
vec3 norm = normalize(Normal);\r
vec3 lightDir = normalize(lightPos - FragPos);\r
\r
\r
vec3 result = vec3((ambient + diffuse + specular) * objectColor);\r
\r
+ // sample irradiance as distance to light combined with angle to the light\r
+ // with a Gaussian kernel\r
vec3 result2 = vec3(0, 0, 0);\r
for (int i = 0; i < 13; i++) {\r
vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);\r
//vec4 sample = texture(irradianceTexture, sampleCoords)\r
// * texture(shadowmapTexture, sampleCoords);\r
- vec3 sample = vec3(texture(irradianceTexture, sampleCoords));\r
+ vec3 sample = vec3(texture(irradianceTexture, sampleCoords)) * diff;\r
vec3 weight = sampleWeights[i];\r
result2 += sample * weight;\r
}\r
\r
+ // multiply to apply irradiance, sqrt to get values between 0 and 1\r
result = sqrt(result * result2);\r
\r
+ // sample texture to get distance from light\r
vec4 t = texture(irradianceTexture, UV);\r
-\r
float BacksideIrradiance = t.r; //*100 + t.g + t.b/100;\r
- \r
+ // and calculate world pos\r
vec3 Backside = (lightPos + (normalize(FragPos - lightPos) * BacksideIrradiance));\r
\r
+ // add translucency by amplifying color inverse to the thickness\r
+ // (1 - diff) is part of the irradiance term,\r
+ // if the light hits the object straight at 90°\r
+ // most light is received\r
float distanceToBackside = length(FragPos - Backside);\r
if (distanceToBackside != 0)\r
result += objectColor * exp(2 / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff);\r
\r
FragColor = vec4(result, 1);\r
- }\r
}\r