X-Git-Url: https://gitweb.ps.run/subsurface_scattering/blobdiff_plain/7a181bdf261b620adb266a4f6b485a0afd1ed306..c99ecda7bed596922125f6b1ef1ef2ae8f27703e:/shaders/frag_irradiance.glsl diff --git a/shaders/frag_irradiance.glsl b/shaders/frag_irradiance.glsl index 9e14ebe..b985acf 100644 --- a/shaders/frag_irradiance.glsl +++ b/shaders/frag_irradiance.glsl @@ -1,19 +1,25 @@ #version 330 core in vec3 FragPos; +in vec3 LocalPos; +in vec3 Backside; +in float BacksideIrradiance; in vec3 Normal; out vec4 FragColor; -uniform sampler2D shadowmapTexture; - uniform vec3 objectColor; uniform vec3 lightColor; uniform vec3 lightPos; uniform vec3 viewPos; +uniform float transmittanceScale; +uniform int renderState; +uniform float powBase; +uniform float powFactor; void main() { + // phong lighting vec3 norm = normalize(Normal); vec3 lightDir = normalize(lightPos - FragPos); @@ -30,5 +36,19 @@ void main() vec3 specular = specularStrength * spec * lightColor; vec3 result = (ambient + diffuse + specular) * objectColor; + + // thickness + float distanceToBackside = length(FragPos - Backside); + + if (renderState == 2) { + if (distanceToBackside != 0) { + // add translucency by amplifying color inverse to the thickness + // (1 - diff) is part of the irradiance term, + // if the light hits the object straight at 90° + // most light is received + result += objectColor * pow(powBase, powFactor / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff); + } + } + FragColor = vec4(result, 1.0f); }