treesummaryrefslogcommitdiff
path: root/shaders
diff options
context:
space:
mode:
authorPatrick2021-03-26 19:11:29 +0100
committerPatrick2021-03-26 19:11:29 +0100
commit36fb27a899045de24d71d55b06648abda7547268 (patch)
treec5adeba0a8d9da11ed36f93a638e9904c83aca5e /shaders
parenta0fdc6d882a1755d0b0607ba3d9bb55e7f8ac006 (diff)
downloadsubsurface_scattering-36fb27a899045de24d71d55b06648abda7547268.tar.gz
subsurface_scattering-36fb27a899045de24d71d55b06648abda7547268.zip
pre cleanup
Diffstat (limited to 'shaders')
-rw-r--r--shaders/frag_irradiance.glsl17
-rw-r--r--shaders/frag_shadowmap.glsl6
-rw-r--r--shaders/ts_frag.glsl100
-rw-r--r--shaders/ts_frag_irradiance.glsl61
-rw-r--r--shaders/ts_vert.glsl21
-rw-r--r--shaders/ts_vert_irradiance.glsl19
-rw-r--r--shaders/vert_irradiance.glsl4
7 files changed, 220 insertions, 8 deletions
diff --git a/shaders/frag_irradiance.glsl b/shaders/frag_irradiance.glsl
index 497bdf0..1bcbc99 100644
--- a/shaders/frag_irradiance.glsl
+++ b/shaders/frag_irradiance.glsl
@@ -17,6 +17,9 @@ uniform int renderState;
uniform float powBase;
uniform float powFactor;
+uniform float translucencySampleVariances[6];
+uniform vec3 translucencySampleWeights[6];
+
void main()
{
vec3 norm = normalize(Normal);
@@ -39,10 +42,18 @@ void main()
//distanceToBackside = distance(Backside, LocalPos);
vec3 result = (ambient + diffuse + specular) * objectColor;
- if (renderState == 3)
- if (distanceToBackside != 0)
- //result += objectColor * pow(powBase, -pow(distanceToBackside, 2)) * transmittanceScale * (1 - diff);
+ if (renderState == 3) {
+ if (distanceToBackside != 0) {
result += objectColor * pow(powBase, powFactor / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff);
+ // vec3 translucency = vec3(0);
+ // for (int i = 0; i < 6; i++) {
+ // translucency += objectColor * translucencySampleWeights[i] * exp(-pow(distanceToBackside, 2.0) / translucencySampleVariances[i]);
+ // }
+
+ // result += translucency * transmittanceScale;
+ }
+ }
+ //result += objectColor * pow(powBase, -pow(distanceToBackside, 2)) * transmittanceScale * (1 - diff);
// if (renderState == 3) {
// //result = Backside;
// //result = LocalPos;
diff --git a/shaders/frag_shadowmap.glsl b/shaders/frag_shadowmap.glsl
index 9a15c7a..2011f82 100644
--- a/shaders/frag_shadowmap.glsl
+++ b/shaders/frag_shadowmap.glsl
@@ -11,9 +11,9 @@ uniform vec3 lightPos;
void main()
{
float lightDist = length(lightPos - FragPos);
- float c1 = mod(lightDist, 10);
- float c2 = mod(lightDist/10, 10);
- float c3 = mod(lightDist/100, 10);
+ float c1 = lightDist;
+ float c2 = lightDist;
+ float c3 = lightDist;
FragColor = vec4(c1, c2, c3, 1);
//FragColor = vec4(LocalPos/10, 1);
}
diff --git a/shaders/ts_frag.glsl b/shaders/ts_frag.glsl
new file mode 100644
index 0000000..a0a8457
--- /dev/null
+++ b/shaders/ts_frag.glsl
@@ -0,0 +1,100 @@
+#version 330 core
+
+in vec3 Normal;
+in vec3 FragPos;
+in vec2 UV;
+
+out vec4 FragColor;
+
+uniform vec3 lightPos;
+uniform vec3 lightColor;
+uniform vec3 objectColor;
+uniform vec3 viewPos;
+uniform sampler2D irradianceTexture;
+uniform int screenWidth;
+uniform int screenHeight;
+uniform int renderState;
+uniform vec2 samplePositions[13];
+uniform vec3 sampleWeights[13];
+uniform float transmittanceScale;
+
+void main()
+{
+ if (renderState == 0) {
+ FragColor = texture(irradianceTexture, UV);
+ }
+ else if (renderState == 1) {
+ vec3 norm = normalize(Normal);
+ vec3 lightDir = normalize(lightPos - FragPos);
+
+ float diff = max(dot(norm, lightDir), 0.0);
+ vec3 diffuse = diff * lightColor;
+
+ float ambientStrength = 0.1;
+ vec3 ambient = ambientStrength * lightColor;
+
+ float specularStrength = 0.5;
+ vec3 viewDir = normalize(viewPos - FragPos);
+ vec3 reflectDir = reflect(-lightDir, norm);
+ float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
+ vec3 specular = specularStrength * spec * lightColor;
+
+ vec3 result = (ambient + diffuse + specular) * objectColor;
+
+ FragColor = vec4(result, 1.0);
+ }
+ else if (renderState == 2) {
+ vec4 result = vec4(0, 0, 0, 1);
+ for (int i = 0; i < 13; i++) {
+ vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);
+ //vec4 sample = texture(irradianceTexture, sampleCoords)
+ // * texture(shadowmapTexture, sampleCoords);
+ vec4 sample = texture(irradianceTexture, sampleCoords);
+ vec4 weight = vec4(sampleWeights[i], 1);
+ result += sample * weight;
+ }
+ FragColor = result;
+ }
+ else if (renderState == 3) {
+ vec3 norm = normalize(Normal);
+ vec3 lightDir = normalize(lightPos - FragPos);
+
+ float diff = max(dot(norm, lightDir), 0.0);
+ vec3 diffuse = diff * lightColor;
+
+ float ambientStrength = 0.1;
+ vec3 ambient = ambientStrength * lightColor;
+
+ float specularStrength = 0.5;
+ vec3 viewDir = normalize(viewPos - FragPos);
+ vec3 reflectDir = reflect(-lightDir, norm);
+ float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
+ vec3 specular = specularStrength * spec * lightColor;
+
+ vec3 result = vec3((ambient + diffuse + specular) * objectColor);
+
+ vec3 result2 = vec3(0, 0, 0);
+ for (int i = 0; i < 13; i++) {
+ vec2 sampleCoords = UV + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);
+ //vec4 sample = texture(irradianceTexture, sampleCoords)
+ // * texture(shadowmapTexture, sampleCoords);
+ vec3 sample = vec3(texture(irradianceTexture, sampleCoords));
+ vec3 weight = sampleWeights[i];
+ result2 += sample * weight;
+ }
+
+ result = sqrt(result * result2);
+
+ vec4 t = texture(irradianceTexture, UV);
+
+ float BacksideIrradiance = t.r; //*100 + t.g + t.b/100;
+
+ vec3 Backside = (lightPos + (normalize(FragPos - lightPos) * BacksideIrradiance));
+
+ float distanceToBackside = length(FragPos - Backside);
+ if (distanceToBackside != 0)
+ result += objectColor * exp(2 / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff);
+
+ FragColor = vec4(result, 1);
+ }
+}
diff --git a/shaders/ts_frag_irradiance.glsl b/shaders/ts_frag_irradiance.glsl
new file mode 100644
index 0000000..b9e70ae
--- /dev/null
+++ b/shaders/ts_frag_irradiance.glsl
@@ -0,0 +1,61 @@
+#version 330 core
+
+in vec3 Normal;
+in vec3 FragPos;
+
+out vec4 FragColor;
+
+uniform vec3 lightPos;
+uniform vec3 lightColor;
+uniform vec3 objectColor;
+uniform vec3 viewPos;
+
+vec4 blur(sampler2D tex, vec2 uv, vec2 res) {
+ float Pi = 6.28318530718; // Pi*2
+
+ // GAUSSIAN BLUR SETTINGS {{{
+ float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
+ float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
+ float Size = 8.0; // BLUR SIZE (Radius)
+ // GAUSSIAN BLUR SETTINGS }}}
+
+ vec2 Radius = Size/res;
+
+ // Pixel colour
+ vec4 Color = texture(tex, uv);
+
+ // Blur calculations
+ for( float d=0.0; d<Pi; d+=Pi/Directions) {
+ for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {
+ Color += texture( tex, uv+vec2(cos(d),sin(d))*Radius*i);
+ }
+ }
+
+ // Output to screen
+ Color /= Quality * Directions - 15.0;
+ return Color;
+}
+
+void main()
+{
+ vec3 norm = normalize(Normal);
+ vec3 lightDir = normalize(lightPos - FragPos);
+
+ float diff = max(dot(norm, lightDir), 0.0);
+ vec3 diffuse = diff * lightColor;
+
+ float ambientStrength = 0.1;
+ vec3 ambient = ambientStrength * lightColor;
+
+ float specularStrength = 0.5;
+ vec3 viewDir = normalize(viewPos - FragPos);
+ vec3 reflectDir = reflect(-lightDir, norm);
+ float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
+ vec3 specular = specularStrength * spec * lightColor;
+
+ vec3 result = (ambient + diffuse) * objectColor;
+
+ result = vec3(length(FragPos - lightPos));
+
+ FragColor = vec4(result, 1.0f);
+}
diff --git a/shaders/ts_vert.glsl b/shaders/ts_vert.glsl
new file mode 100644
index 0000000..f8e790a
--- /dev/null
+++ b/shaders/ts_vert.glsl
@@ -0,0 +1,21 @@
+#version 330 core
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec3 normal;
+layout (location = 2) in vec2 uv;
+
+out vec3 Normal;
+out vec3 FragPos;
+out vec2 UV;
+
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+
+void main()
+{
+ gl_Position = projection * view * model * vec4(pos, 1.0);
+ FragPos = vec3(model * vec4(pos, 1.0));
+ Normal = normal;
+ UV = uv;
+}
diff --git a/shaders/ts_vert_irradiance.glsl b/shaders/ts_vert_irradiance.glsl
new file mode 100644
index 0000000..afe5645
--- /dev/null
+++ b/shaders/ts_vert_irradiance.glsl
@@ -0,0 +1,19 @@
+#version 330 core
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec3 normal;
+layout (location = 2) in vec2 uv;
+
+out vec3 Normal;
+out vec3 FragPos;
+
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+
+void main()
+{
+ FragPos = vec3(model * vec4(pos, 1.0));
+ gl_Position = vec4(uv * 2.0 - 1.0, 0.0, 1.0);
+ Normal = normal;
+}
diff --git a/shaders/vert_irradiance.glsl b/shaders/vert_irradiance.glsl
index 25770f6..6b54180 100644
--- a/shaders/vert_irradiance.glsl
+++ b/shaders/vert_irradiance.glsl
@@ -69,9 +69,9 @@ void main()
vec4 t = texture(shadowmapTexture, shadowmapCoords);
//vec4 t = blur(shadowmapTexture, shadowmapCoords, vec2(screenWidth, screenHeight));
- BacksideIrradiance = t.r + t.g*10 + t.b*100;
+ BacksideIrradiance = t.r; //*100 + t.g + t.b/100;
- vec3 lightDir = (vec3(0, 0, 0) - lightPos);
+ vec3 lightDir = normalize(FragPos - lightPos);
Backside = (lightPos + (lightDir * BacksideIrradiance));
//Backside = texture(shadowmapTexture, shadowmapCoords).xyz*10;
}