]> gitweb.ps.run Git - subsurface_scattering/commitdiff
comments TS SSS
authorPatrick <patrick.schoenberger@posteo.de>
Fri, 26 Mar 2021 19:12:25 +0000 (20:12 +0100)
committerPatrick <patrick.schoenberger@posteo.de>
Fri, 26 Mar 2021 19:12:25 +0000 (20:12 +0100)
shaders/ts_frag.glsl
shaders/ts_frag_irradiance.glsl
shaders/ts_vert.glsl
shaders/ts_vert_irradiance.glsl
src/main.cpp
src/main2.cpp

index a0a8457c7bbfc2990209f2152d71d25d956c666e..9362e2a36867c7c6fa347826ffdd0c5bf56649f0 100644 (file)
@@ -20,42 +20,7 @@ uniform float transmittanceScale;
 \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
@@ -73,28 +38,34 @@ void main()
 \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
index b9e70ae50f5e5d0c2aaa5c2debce1915e3cd48d4..37d28f12a9ca109adcdce3e56be169842f5b962d 100644 (file)
@@ -10,52 +10,11 @@ uniform vec3 lightColor;
 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
index f8e790a372b686c318c0899fe1ffe2ff5aa75768..3ee202ff743e6fcb1010480bc4e8370ecdfec431 100644 (file)
@@ -14,6 +14,7 @@ uniform mat4 projection;
 \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
index afe5645a64298937bf91d3d413e71a830d0fdc49..f0d77b9f8a840c49b5bf56bbffa06c511c0bf40e 100644 (file)
@@ -13,7 +13,9 @@ uniform mat4 projection;
 \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
index 8b48e70a6fddb7c3c9e8abdc3fbbce64ba9d0b9b..168d01d3b42fc66280504c93cf42de742c155fb8 100644 (file)
 #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
index 206466d1dee3ee75253982c9b2931b58e7a5566b..5d717e66990821c981347cb5f5ea152c19cffa57 100644 (file)
 #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
@@ -383,7 +387,6 @@ int main() {
   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
@@ -470,7 +473,7 @@ int main() {
 \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
@@ -514,9 +517,7 @@ int main() {
 \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
@@ -569,16 +570,9 @@ int main() {
     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