Fixes in more shaders

This commit is contained in:
Deve 2016-06-28 21:55:51 +02:00
parent 51d3b71ec6
commit 0fb119068b
6 changed files with 27 additions and 26 deletions

View File

@ -3,12 +3,13 @@
uniform sampler2D tex;
uniform sampler2D depth;
uniform vec2 pixel;
uniform float sigma = 5.;
out vec4 FragColor;
void main()
{
float sigma = 5.;
vec2 uv = gl_FragCoord.xy * pixel;
float X = uv.x;
float Y = uv.y;
@ -23,11 +24,11 @@ void main()
g1 *= g2;
float tmp_weight, total_weight = g0;
for (int i = 1; i < 9; i++) {
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X - i * pixel.x, Y)).x - pixel_depth));
sum += texture(tex, vec2(X - i * pixel.x, Y)) * g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X - float(i) * pixel.x, Y)).x - pixel_depth));
sum += texture(tex, vec2(X - float(i) * pixel.x, Y)) * g0 * tmp_weight;
total_weight += g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X + i * pixel.x, Y)).x - pixel_depth));
sum += texture(tex, vec2(X + i * pixel.x, Y)) * g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X + float(i) * pixel.x, Y)).x - pixel_depth));
sum += texture(tex, vec2(X + float(i) * pixel.x, Y)) * g0 * tmp_weight;
total_weight += g0 * tmp_weight;
g0 *= g1;
g1 *= g2;

View File

@ -3,12 +3,13 @@
uniform sampler2D tex;
uniform sampler2D depth;
uniform vec2 pixel;
uniform float sigma = 5.;
out vec4 FragColor;
void main()
{
float sigma = 5.;
vec2 uv = gl_FragCoord.xy * pixel;
float X = uv.x;
float Y = uv.y;
@ -23,11 +24,11 @@ void main()
g1 *= g2;
float tmp_weight, total_weight = g0;
for (int i = 1; i < 9; i++) {
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X, Y - i * pixel.y)).x - pixel_depth));
sum += texture(tex, vec2(X, Y - i * pixel.y)) * g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X, Y - float(i) * pixel.y)).x - pixel_depth));
sum += texture(tex, vec2(X, Y - float(i) * pixel.y)) * g0 * tmp_weight;
total_weight += g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X, Y + i * pixel.y)).x - pixel_depth));
sum += texture(tex, vec2(X, Y + i * pixel.y)) * g0 * tmp_weight;
tmp_weight = max(0.0, 1.0 - .001 * abs(texture(depth, vec2(X, Y + float(i) * pixel.y)).x - pixel_depth));
sum += texture(tex, vec2(X, Y + float(i) * pixel.y)) * g0 * tmp_weight;
total_weight += g0 * tmp_weight;
g0 *= g1;
g1 *= g2;

View File

@ -7,12 +7,12 @@ out vec4 FragColor;
void main()
{
vec2 uv = gl_FragCoord.xy / 512;
vec2 uv = gl_FragCoord.xy / 512.;
vec3 col = texture(tex, uv).xyz;
vec3 Yxy = getCIEYxy(col);
vec3 WhiteYxy = getCIEYxy(vec3(1.));
Yxy.x = smoothstep(WhiteYxy.x, WhiteYxy.x * 4, Yxy.x);
Yxy.x = smoothstep(WhiteYxy.x, WhiteYxy.x * 4., Yxy.x);
FragColor = vec4(max(vec3(0.), getRGBFromCIEXxy(Yxy)), 1.0);
}

View File

@ -11,7 +11,7 @@ void main()
{
vec2 uv = gl_FragCoord.xy / screen;
float curdepth = texture(dtex, uv).x;
vec4 FragPos = InverseProjectionMatrix * (2.0f * vec4(uv, curdepth, 1.0f) - 1.0f);
vec4 FragPos = InverseProjectionMatrix * (2.0 * vec4(uv, curdepth, 1.0) - 1.0);
FragPos /= FragPos.w;
float depth = FragPos.z;
@ -70,7 +70,7 @@ void main()
col = vec4(col.rgb / 41.0, col.a);
depth = clamp(max(1.1666 - (FragPos.z/240.0), FragPos.z - 2000.0), 0., 1.);
vec3 final = colOriginal.rgb * depth + col.rgb * (1 - depth);
vec3 final = colOriginal.rgb * depth + col.rgb * (1. - depth);
FragColor = vec4(final, colOriginal.a);
}

View File

@ -74,7 +74,7 @@ void main()
// Compute the blur
vec2 inc_vec = blur_dir / vec2(NB_SAMPLES);
vec2 blur_texcoords = texcoords - inc_vec * NB_SAMPLES / 2;
vec2 blur_texcoords = texcoords - inc_vec * float(NB_SAMPLES) / 2.;
for(int i=1 ; i < NB_SAMPLES ; i++)
{
color += texture(color_buffer, blur_texcoords).rgb;

View File

@ -3,8 +3,8 @@
uniform sampler2D dtex;
uniform float radius;
uniform float k = 1.5;
uniform float sigma = 1.;
uniform float k;
uniform float sigma;
out float AO;
const float tau = 7.;
@ -12,14 +12,13 @@ const float beta = 0.002;
const float epsilon = .00001;
#define SAMPLES 16
const float invSamples = 1. / SAMPLES;
const float invSamples = 0.0625; // 1. / SAMPLES
vec3 getXcYcZc(int x, int y, float zC)
{
// We use perspective symetric projection matrix hence P(0,2) = P(1, 2) = 0
float xC= (2 * (float(x)) / screen.x - 1.) * zC / ProjectionMatrix[0][0];
float yC= (2 * (float(y)) / screen.y - 1.) * zC / ProjectionMatrix[1][1];
float xC= (2. * (float(x)) / screen.x - 1.) * zC / ProjectionMatrix[0][0];
float yC= (2. * (float(y)) / screen.y - 1.) * zC / ProjectionMatrix[1][1];
return vec3(xC, yC, zC);
}
@ -36,16 +35,16 @@ void main(void)
vec3 norm = normalize(cross(ddy, ddx));
float r = radius / FragPos.z;
float phi = 3. * (x ^ y) + x * y;
float phi = 3. * float((x ^ y) + x * y);
float bl = 0.0;
float m = log2(r) + 6 + log2(invSamples);
float m = log2(r) + 6. + log2(invSamples);
float theta = 2. * 3.14 * tau * .5 * invSamples + phi;
vec2 rotations = vec2(cos(theta), sin(theta)) * screen;
vec2 offset = vec2(cos(invSamples), sin(invSamples));
for(int i = 0; i < SAMPLES; ++i) {
float alpha = (i + .5) * invSamples;
float alpha = (float(i) + .5) * invSamples;
rotations = vec2(rotations.x * offset.x - rotations.y * offset.y, rotations.x * offset.y + rotations.y * offset.x);
float h = r * alpha;
vec2 localoffset = h * rotations;
@ -53,13 +52,13 @@ void main(void)
m = m + .5;
ivec2 ioccluder_uv = ivec2(x, y) + ivec2(localoffset);
if (ioccluder_uv.x < 0 || ioccluder_uv.x > screen.x || ioccluder_uv.y < 0 || ioccluder_uv.y > screen.y) continue;
if (ioccluder_uv.x < 0 || ioccluder_uv.x > int(screen.x) || ioccluder_uv.y < 0 || ioccluder_uv.y > int(screen.y)) continue;
float LinearoccluderFragmentDepth = textureLod(dtex, vec2(ioccluder_uv) / screen, max(m, 0.)).x;
vec3 OccluderPos = getXcYcZc(ioccluder_uv.x, ioccluder_uv.y, LinearoccluderFragmentDepth);
vec3 vi = OccluderPos - FragPos;
bl += max(0, dot(vi, norm) - FragPos.z * beta) / (dot(vi, vi) + epsilon);
bl += max(0., dot(vi, norm) - FragPos.z * beta) / (dot(vi, vi) + epsilon);
}
AO = max(pow(1.0 - min(2. * sigma * bl * invSamples, 0.99), k), 0.);