\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
uniform vec3 objectColor;\r
uniform vec3 viewPos;\r
\r
-vec4 blur(sampler2D tex, vec2 uv, vec2 res) {\r
- float Pi = 6.28318530718; // Pi*2\r
- \r
- // GAUSSIAN BLUR SETTINGS {{{\r
- float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)\r
- float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)\r
- float Size = 8.0; // BLUR SIZE (Radius)\r
- // GAUSSIAN BLUR SETTINGS }}}\r
- \r
- vec2 Radius = Size/res;\r
- \r
- // Pixel colour\r
- vec4 Color = texture(tex, uv);\r
- \r
- // Blur calculations\r
- for( float d=0.0; d<Pi; d+=Pi/Directions) {\r
- for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {\r
- Color += texture( tex, uv+vec2(cos(d),sin(d))*Radius*i); \r
- }\r
- }\r
- \r
- // Output to screen\r
- Color /= Quality * Directions - 15.0;\r
- return Color;\r
-}\r
-\r
void main()\r
{\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) * objectColor;\r
-\r
- result = vec3(length(FragPos - lightPos));\r
+ // color the XY-plane according to the distance\r
+ // of the fragment in world space\r
+ vec3 result = vec3(length(FragPos - lightPos));\r
\r
FragColor = vec4(result, 1.0f);\r
}\r
\r
void main()\r
{\r
+ // regular mvp\r
gl_Position = projection * view * model * vec4(pos, 1.0);\r
FragPos = vec3(model * vec4(pos, 1.0));\r
Normal = normal;\r
\r
void main()\r
{\r
- FragPos = vec3(model * vec4(pos, 1.0));\r
+ // lay out the model in the XY-plane according to it's UV coordinates\r
gl_Position = vec4(uv * 2.0 - 1.0, 0.0, 1.0);\r
+ // pass fragment position in world coordinates\r
+ FragPos = vec3(model * vec4(pos, 1.0));\r
Normal = normal;\r
}\r
#include <assimp/postprocess.h>\r
#include <assimp/scene.h>\r
\r
-/*\r
-\r
-TODO:\r
-- Save Depth to fbo\r
-- Stencil Buffer\r
-- LightDist > 1\r
- - 1 - distanceToBackside in frag_irradiance\r
-- ShadowMap Perspective (no projection?)\r
-- (Implement Gaussian Blur)\r
-- LightDir nicht immer zu 0 0 0\r
-\r
-*/\r
+\r
+// sample positions and weights for a Gaussian kernel from \r
+// Hable, John ; Borshukov, George ; Hejl, Jim: Fast Skin Shading. In: ShaderX7, ShaderX : Charles River Media, 2009, S. 161–173\r
\r
float samplePositions[] = {\r
0.000000f, 0.000000f,\r
#include <assimp/postprocess.h>\r
#include <assimp/scene.h>\r
\r
+\r
+// sample positions and weights for a Gaussian kernel from \r
+// Hable, John ; Borshukov, George ; Hejl, Jim: Fast Skin Shading. In: ShaderX7, ShaderX : Charles River Media, 2009, S. 161–173\r
+\r
float samplePositions[] = {\r
0.000000f, 0.000000f,\r
1.633992f, 0.036795f,\r
GLuint shaderProgramIrradiance = compileShaders("shaders/ts_vert_irradiance.glsl", "shaders/ts_frag_irradiance.glsl");\r
GLuint shaderProgramCombine = compileShaders("shaders/ts_vert.glsl", "shaders/ts_frag.glsl");\r
\r
- //model m = loadModel("models/Isotrop-upperjaw.ply");\r
model m = loadModel("models/african_head/african_head.obj");\r
\r
arccam arcCam;\r
\r
prevMouse = sf::Mouse::isButtonPressed(sf::Mouse::Right);\r
\r
- // Render Shadowmap\r
+ // Render Shadowmap to fbo\r
\r
glBindFramebuffer(GL_FRAMEBUFFER, fb_irradiance.fbo);\r
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);\r
\r
m.draw();\r
\r
- \r
-\r
- // Render fbo to screen\r
+ // Render model and calculate light spread and translucency in shader\r
\r
glBindFramebuffer(GL_FRAMEBUFFER, 0);\r
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);\r
glActiveTexture(GL_TEXTURE0 + 0);\r
glBindTexture(GL_TEXTURE_2D, fb_irradiance.renderTexture);\r
\r
- // glBindVertexArray(fb_irradiance.screenVAO);\r
- // glUniform1i(glGetUniformLocation(fb_irradiance.screenShaderProgram, "shadowmapTexture"), 0);\r
- // glActiveTexture(GL_TEXTURE0 + 0);\r
- // glBindTexture(GL_TEXTURE_2D, fb_irradiance.renderTexture);\r
- // glDrawArrays(GL_TRIANGLES, 0, 6);\r
- // glBindVertexArray(0);\r
-\r
m.draw();\r
\r
-\r
+ // menu\r
\r
ImGui::SFML::Update(window, deltaClock.restart());\r
\r