treesummaryrefslogcommitdiff
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/fbo_frag.glsl39
-rw-r--r--shaders/frag_irradiance.glsl25
-rw-r--r--shaders/frag_shadowmap.glsl9
-rw-r--r--shaders/vert_irradiance.glsl77
-rw-r--r--shaders/vert_shadowmap.glsl (renamed from shaders/vert.glsl)6
5 files changed, 144 insertions, 12 deletions
diff --git a/shaders/fbo_frag.glsl b/shaders/fbo_frag.glsl
index 7463fc8..1102992 100644
--- a/shaders/fbo_frag.glsl
+++ b/shaders/fbo_frag.glsl
@@ -11,24 +11,51 @@ uniform int renderState;
uniform vec2 samplePositions[13];
uniform vec3 sampleWeights[13];
+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()
{
if (renderState == 0) {
- FragColor = texture(shadowmapTexture, TexCoords);
+ FragColor = blur(shadowmapTexture, TexCoords, vec2(screenWidth, screenHeight));
}
- // stencil buffer
else if (renderState == 1) {
- FragColor = texture(irradianceTexture, TexCoords);
+ FragColor = texture(shadowmapTexture, TexCoords);
}
+ // stencil buffer
else if (renderState == 2) {
- FragColor = texture(shadowmapTexture, TexCoords) * texture(irradianceTexture, TexCoords);
+ FragColor = texture(irradianceTexture, TexCoords);
}
else if (renderState == 3) {
vec4 result = vec4(0, 0, 0, 1);
for (int i = 0; i < 13; i++) {
vec2 sampleCoords = TexCoords + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);
- vec4 sample = texture(irradianceTexture, sampleCoords)
- * texture(shadowmapTexture, sampleCoords);
+ //vec4 sample = texture(irradianceTexture, sampleCoords)
+ // * texture(shadowmapTexture, sampleCoords);
+ vec4 sample = texture(irradianceTexture, sampleCoords);
vec4 weight = vec4(sampleWeights[i], 1);
result += sample * weight;
}
diff --git a/shaders/frag_irradiance.glsl b/shaders/frag_irradiance.glsl
index 9e14ebe..497bdf0 100644
--- a/shaders/frag_irradiance.glsl
+++ b/shaders/frag_irradiance.glsl
@@ -1,16 +1,21 @@
#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()
{
@@ -29,6 +34,22 @@ void main()
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = specularStrength * spec * lightColor;
+ //float distanceToBackside = length(clamp(FragPos - Backside, vec3(0), vec3(1000)));
+ float distanceToBackside = length(FragPos - Backside);
+ //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);
+ result += objectColor * pow(powBase, powFactor / pow(distanceToBackside, 0.6)) * transmittanceScale * (1 - diff);
+ // if (renderState == 3) {
+ // //result = Backside;
+ // //result = LocalPos;
+ // result = vec3(distanceToBackside);
+ // }
+
+
FragColor = vec4(result, 1.0f);
+ //FragColor = vec4(vec3(distanceToBackside), 1);
}
diff --git a/shaders/frag_shadowmap.glsl b/shaders/frag_shadowmap.glsl
index 6d6dab6..9a15c7a 100644
--- a/shaders/frag_shadowmap.glsl
+++ b/shaders/frag_shadowmap.glsl
@@ -2,6 +2,7 @@
#version 330 core
in vec3 FragPos;
+in vec3 LocalPos;
out vec4 FragColor;
@@ -9,6 +10,10 @@ uniform vec3 lightPos;
void main()
{
- float lightDist = 1 - (length(lightPos - FragPos) - 5.5);
- FragColor = vec4(vec3(lightDist), 1);
+ float lightDist = length(lightPos - FragPos);
+ float c1 = mod(lightDist, 10);
+ float c2 = mod(lightDist/10, 10);
+ float c3 = mod(lightDist/100, 10);
+ FragColor = vec4(c1, c2, c3, 1);
+ //FragColor = vec4(LocalPos/10, 1);
}
diff --git a/shaders/vert_irradiance.glsl b/shaders/vert_irradiance.glsl
new file mode 100644
index 0000000..25770f6
--- /dev/null
+++ b/shaders/vert_irradiance.glsl
@@ -0,0 +1,77 @@
+#version 330 core
+
+layout (location = 0) in vec3 pos;
+layout (location = 1) in vec3 normal;
+
+out vec3 FragPos;
+out vec3 LocalPos;
+out vec3 Backside;
+out float BacksideIrradiance;
+out vec3 Normal;
+
+uniform sampler2D shadowmapTexture;
+uniform vec3 lightPos;
+uniform vec2 samplePositions[13];
+uniform vec3 sampleWeights[13];
+uniform int screenWidth;
+uniform int screenHeight;
+
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 lightView;
+uniform mat4 lightViewInv;
+uniform mat4 projection;
+uniform mat4 lightProjection;
+
+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()
+{
+ gl_Position = projection * view * model * vec4(pos, 1.0);
+ FragPos = vec3(model * vec4(pos, 1));
+ LocalPos = pos;
+ Normal = normal;
+
+ vec4 lightSpace = lightProjection * lightView * model * vec4(pos, 1.0);
+ lightSpace = lightSpace / lightSpace.w;
+ vec2 shadowmapCoords = lightSpace.xy;
+ shadowmapCoords = vec2(
+ (shadowmapCoords.x * 0.99 + 1) / 2,
+ (shadowmapCoords.y * 0.99 + 1) / 2
+ );
+
+
+ // blur
+ vec4 t = texture(shadowmapTexture, shadowmapCoords);
+ //vec4 t = blur(shadowmapTexture, shadowmapCoords, vec2(screenWidth, screenHeight));
+
+ BacksideIrradiance = t.r + t.g*10 + t.b*100;
+
+ vec3 lightDir = (vec3(0, 0, 0) - lightPos);
+ Backside = (lightPos + (lightDir * BacksideIrradiance));
+ //Backside = texture(shadowmapTexture, shadowmapCoords).xyz*10;
+}
diff --git a/shaders/vert.glsl b/shaders/vert_shadowmap.glsl
index 6f48573..50847bb 100644
--- a/shaders/vert.glsl
+++ b/shaders/vert_shadowmap.glsl
@@ -4,15 +4,17 @@ layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 normal;
out vec3 FragPos;
+out vec3 LocalPos;
out vec3 Normal;
uniform mat4 model;
-uniform mat4 view;
+uniform mat4 lightView;
uniform mat4 projection;
void main()
{
- gl_Position = projection * view * model * vec4(pos, 1.0);
+ gl_Position = projection * lightView * model * vec4(pos, 1.0);
FragPos = vec3(model * vec4(pos, 1));
+ LocalPos = pos;
Normal = normal;
}