This commit is contained in:
luboslenco 2018-12-06 15:23:08 +01:00
parent 0cc0915e44
commit 93cc102bf5
44 changed files with 316 additions and 292 deletions

View File

@ -13,20 +13,20 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
float roughness = unpackFloat(texture(gbuffer0, texCoord).b).y;
float roughness = unpackFloat(textureLod(gbuffer0, texCoord, 0.0).b).y;
// if (roughness == 0.0) { // Always blur for now, non blured output can produce noise
// fragColor.rgb = texture(tex, texCoord).rgb;
// fragColor.rgb = textureLod(tex, texCoord).rgb;
// return;
// }
if (roughness >= 0.8) { // No reflections
fragColor.rgb = texture(tex, texCoord).rgb;
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
return;
}
fragColor.rgb = texture(tex, texCoord + dirInv * 2.5).rgb;
fragColor.rgb += texture(tex, texCoord + dirInv * 1.5).rgb;
fragColor.rgb += texture(tex, texCoord).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 1.5).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 2.5).rgb;
fragColor.rgb = textureLod(tex, texCoord + dirInv * 2.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord + dirInv * 1.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 1.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 2.5, 0.0).rgb;
fragColor.rgb /= vec3(5.0);
}

View File

@ -22,7 +22,7 @@ float normpdf3(vec3 v, float sigma) {
void main() {
vec2 step = (dir / screenSize.xy);
vec3 colf = texture(tex, texCoord).rgb * weight[0];
vec3 colf = textureLod(tex, texCoord, 0.0).rgb * weight[0];
float col;
float res = 0.0;
@ -34,13 +34,13 @@ void main() {
float fw = f * weight[i];
vec2 s = step * (float(i) + 0.5);
col = texture(tex, texCoord + s).r;
col = textureLod(tex, texCoord + s, 0.0).r;
factor = normpdf3(col - colf, 1.0) * fw;
sumfactor += factor;
res += factor * col;
col = texture(tex, texCoord - s).r;
factor = normpdf3(col - colf, 1.0) * fw;
col = textureLod(tex, texCoord - s).r;
factor = normpdf3(col - colf, 1.0, 0.0) * fw;
sumfactor += factor;
res += factor * col;
}

View File

@ -22,7 +22,7 @@ float normpdf3(vec3 v, float sigma) {
void main() {
vec2 step = (dir / screenSize.xy);
vec3 colf = texture(tex, texCoord).rgb * weight[0];
vec3 colf = textureLod(tex, texCoord, 0.0).rgb * weight[0];
float col;
float sumfactor = 0.0;
@ -34,12 +34,12 @@ void main() {
float fw = f * weight[i];
vec2 s = step * (float(i) + 0.5);
col = texture(tex, texCoord + s).r;
col = textureLod(tex, texCoord + s, 0.0).r;
factor = normpdf3(col - colf, 1.0) * fw;
sumfactor += factor;
fragColor += factor * col;
col = texture(tex, texCoord - s).r;
col = textureLod(tex, texCoord - s, 0.0).r;
factor = normpdf3(col - colf, 1.0) * fw;
sumfactor += factor;
fragColor += factor * col;

View File

@ -10,38 +10,35 @@ uniform sampler2D gbuffer0;
uniform vec2 dirInv; // texStep
in vec2 texCoord;
out vec4 fragColor;
out float fragColor;
const float blurWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
const float discardThreshold = 0.95;
float doBlur(const float blurWeight, const int pos, const vec3 nor, const vec2 texCoord) {
const float posadd = pos + 0.5;
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * dirInv).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
float col = texture(tex, texCoord + posadd * dirInv).r;
fragColor.r += col * blurWeight * influenceFactor;
float weight = blurWeight * influenceFactor;
nor2 = getNor(texture(gbuffer0, texCoord - pos * dirInv).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = texture(tex, texCoord - posadd * dirInv).r;
fragColor.r += col * blurWeight * influenceFactor;
weight += blurWeight * influenceFactor;
return weight;
}
void main() {
vec2 tc = texCoord * ssaoTextureScale;
vec3 nor = getNor(texture(gbuffer0, texCoord).rg);
vec2 tc = texCoord;
vec3 nor = getNor(textureLod(gbuffer0, texCoord, 0.0).rg);
fragColor.r = texture(tex, tc).r * blurWeights[0];
fragColor = textureLod(tex, tc, 0.0).r * blurWeights[0];
float weight = blurWeights[0];
for (int i = 1; i < 5; i++) {
weight += doBlur(blurWeights[i], i, nor, tc);
for (int i = 1; i < 5; ++i) {
float posadd = i + 0.5;
vec3 nor2 = getNor(textureLod(gbuffer0, tc + i * dirInv, 0.0).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
float col = textureLod(tex, tc + posadd * dirInv, 0.0).r;
float w = blurWeights[i] * influenceFactor;
fragColor += col * w;
weight += w;
nor2 = getNor(textureLod(gbuffer0, tc - i * dirInv, 0.0).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = textureLod(tex, tc - posadd * dirInv, 0.0).r;
w = blurWeights[i] * influenceFactor;
fragColor += col * w;
weight += w;
}
fragColor = vec4(fragColor.r / weight); // SSAO only
fragColor = fragColor / weight;
}

View File

@ -14,11 +14,11 @@ const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495
void main() {
vec2 step = (dir / screenSize.xy) * bloomRadius;
fragColor.rgb = texture(tex, texCoord).rgb * weight[0];
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb * weight[0];
for (int i = 1; i < 10; i++) {
vec2 s = step * (float(i) + 0.5);
fragColor.rgb += texture(tex, texCoord + s).rgb * weight[i];
fragColor.rgb += texture(tex, texCoord - s).rgb * weight[i];
fragColor.rgb += textureLod(tex, texCoord + s, 0.0).rgb * weight[i];
fragColor.rgb += textureLod(tex, texCoord - s, 0.0).rgb * weight[i];
}
fragColor.rgb *= bloomStrength / 5;

View File

@ -8,16 +8,16 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
fragColor.rgb = texture(tex, texCoord + dirInv * 5.5).rgb;
fragColor.rgb += texture(tex, texCoord + dirInv * 4.5).rgb;
fragColor.rgb += texture(tex, texCoord + dirInv * 3.5).rgb;
fragColor.rgb += texture(tex, texCoord + dirInv * 2.5).rgb;
fragColor.rgb += texture(tex, texCoord + dirInv * 1.5).rgb;
fragColor.rgb += texture(tex, texCoord).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 1.5).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 2.5).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 3.5).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 4.5).rgb;
fragColor.rgb += texture(tex, texCoord - dirInv * 5.5).rgb;
fragColor.rgb = textureLod(tex, texCoord + dirInv * 5.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord + dirInv * 4.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord + dirInv * 3.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord + dirInv * 2.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord + dirInv * 1.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 1.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 2.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 3.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 4.5, 0.0).rgb;
fragColor.rgb += textureLod(tex, texCoord - dirInv * 5.5, 0.0).rgb;
fragColor.rgb /= vec3(11.0);
}

View File

@ -18,17 +18,17 @@ const float discardThreshold = 0.95;
float doBlur(const float blurWeight, const int pos, const vec3 nor, const float depth, const vec2 texCoord) {
const float posadd = pos + 0.5;
vec4 g0 = texture(gbuffer0, texCoord + pos * dirInv);
vec4 g0 = textureLod(gbuffer0, texCoord + pos * dirInv, 0.0);
vec3 nor2 = getNor(g0.rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor)) * step(abs(depth - g0.a), 0.001);
float col = texture(tex, texCoord + posadd * dirInv).r;
float col = textureLod(tex, texCoord + posadd * dirInv, 0.0).r;
fragColor += col * blurWeight * influenceFactor;
float weight = blurWeight * influenceFactor;
g0 = texture(gbuffer0, texCoord - pos * dirInv);
g0 = textureLod(gbuffer0, texCoord - pos * dirInv, 0.0);
nor2 = getNor(g0.rg);
influenceFactor = step(discardThreshold, dot(nor2, nor)) * step(abs(depth - g0.a), 0.001);
col = texture(tex, texCoord - posadd * dirInv).r;
col = textureLod(tex, texCoord - posadd * dirInv, 0.0).r;
fragColor += col * blurWeight * influenceFactor;
weight += blurWeight * influenceFactor;
@ -36,19 +36,23 @@ float doBlur(const float blurWeight, const int pos, const vec3 nor, const float
}
void main() {
vec4 g0 = texture(gbuffer0, texCoord);
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0);
vec3 nor = getNor(g0.rg);
float depth = g0.a;
float sm = texture(tex, texCoord).r;
float sm = textureLod(tex, texCoord, 0.0).r;
fragColor = sm * blurWeights[0];
float weight = blurWeights[0];
float d = texture(dist, texCoord).r;
float d = textureLod(dist, texCoord, 0.0).r;
int numTaps = clamp(int(d * 10 * penumbraScale), 2, 10 * penumbraScale);
#ifdef _PenumbraScale
for (int i = 1; i < numTaps; ++i) weight += doBlur(blurWeights[int(i / penumbraScale)], i, nor, depth, texCoord);
for (int i = 1; i < numTaps; ++i) {
weight += doBlur(blurWeights[int(i / penumbraScale)], i, nor, depth, texCoord);
}
#else
for (int i = 1; i < numTaps; ++i) weight += doBlur(blurWeights[i - 1], i, nor, depth, texCoord);
for (int i = 1; i < numTaps; ++i){
weight += doBlur(blurWeights[i - 1], i, nor, depth, texCoord);
}
#endif
fragColor /= weight;
}

View File

@ -7,5 +7,5 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
fragColor.rgb = texture(tex, texCoord).rgb + texture(tex2, texCoord).rgb;
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb + textureLod(tex2, texCoord, 0.0).rgb;
}

View File

@ -100,8 +100,8 @@ vec4 LUTlookup(in vec4 textureColor, in sampler2D lookupTable) {
texelPosition2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);
texelPosition2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);
lowp vec4 newColor1 = texture(lookupTable, texelPosition1);
lowp vec4 newColor2 = texture(lookupTable, texelPosition2);
lowp vec4 newColor1 = textureLod(lookupTable, texelPosition1, 0.0);
lowp vec4 newColor2 = textureLod(lookupTable, texelPosition2, 0.0);
lowp vec4 colorGradedResult = mix(newColor1, newColor2, fract(blueColor));
@ -169,7 +169,7 @@ void main() {
#endif
#ifdef _CDepth
float depth = texture(gbufferD, texCo).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCo, 0.0).r * 2.0 - 1.0;
#endif
#ifdef _CFXAA
@ -183,11 +183,11 @@ void main() {
vec2 tcrgbSE = (texCo + vec2(1.0, 1.0) * texStep);
vec2 tcrgbM = vec2(texCo);
vec3 rgbNW = texture(tex, tcrgbNW).rgb;
vec3 rgbNE = texture(tex, tcrgbNE).rgb;
vec3 rgbSW = texture(tex, tcrgbSW).rgb;
vec3 rgbSE = texture(tex, tcrgbSE).rgb;
vec3 rgbM = texture(tex, tcrgbM).rgb;
vec3 rgbNW = textureLod(tex, tcrgbNW, 0.0).rgb;
vec3 rgbNE = textureLod(tex, tcrgbNE, 0.0).rgb;
vec3 rgbSW = textureLod(tex, tcrgbSW, 0.0).rgb;
vec3 rgbSE = textureLod(tex, tcrgbSE, 0.0).rgb;
vec3 rgbM = textureLod(tex, tcrgbM, 0.0).rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
@ -210,11 +210,11 @@ void main() {
dir * rcpDirMin)) * texStep;
vec3 rgbA = 0.5 * (
texture(tex, texCo + dir * (1.0 / 3.0 - 0.5)).rgb +
texture(tex, texCo + dir * (2.0 / 3.0 - 0.5)).rgb);
textureLod(tex, texCo + dir * (1.0 / 3.0 - 0.5), 0.0).rgb +
textureLod(tex, texCo + dir * (2.0 / 3.0 - 0.5), 0.0).rgb);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture(tex, texCo + dir * -0.5).rgb +
texture(tex, texCo + dir * 0.5).rgb);
textureLod(tex, texCo + dir * -0.5, 0.0).rgb +
textureLod(tex, texCo + dir * 0.5, 0.0).rgb);
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax)) fragColor.rgb = rgbA;
@ -225,16 +225,16 @@ void main() {
#ifdef _CDOF
fragColor.rgb = dof(texCo, depth, tex, gbufferD, texStep, cameraProj);
#else
fragColor.rgb = texture(tex, texCo).rgb;
fragColor.rgb = textureLod(tex, texCo, 0.0).rgb;
#endif
#endif
#ifdef _CSharpen
vec3 col1 = texture(tex, texCo + vec2(-texStep.x, -texStep.y) * 1.5).rgb;
vec3 col2 = texture(tex, texCo + vec2(texStep.x, -texStep.y) * 1.5).rgb;
vec3 col3 = texture(tex, texCo + vec2(-texStep.x, texStep.y) * 1.5).rgb;
vec3 col4 = texture(tex, texCo + vec2(texStep.x, texStep.y) * 1.5).rgb;
vec3 col1 = textureLod(tex, texCo + vec2(-texStep.x, -texStep.y) * 1.5, 0.0).rgb;
vec3 col2 = textureLod(tex, texCo + vec2(texStep.x, -texStep.y) * 1.5, 0.0).rgb;
vec3 col3 = textureLod(tex, texCo + vec2(-texStep.x, texStep.y) * 1.5, 0.0).rgb;
vec3 col4 = textureLod(tex, texCo + vec2(texStep.x, texStep.y) * 1.5, 0.0).rgb;
vec3 colavg = (col1 + col2 + col3 + col4) * 0.25;
fragColor.rgb += (fragColor.rgb - colavg) * compoSharpenStrength;
#endif
@ -255,7 +255,7 @@ void main() {
vec4 lndc = VP * vec4(light, 1.0);
lndc.xy /= lndc.w;
vec2 lss = lndc.xy * 0.5 + 0.5;
float lssdepth = linearize(texture(gbufferD, lss).r * 2.0 - 1.0, cameraProj);
float lssdepth = linearize(textureLod(gbufferD, lss, 0.0).r * 2.0 - 1.0, cameraProj);
float lightDistance = distance(eye, light);
if (lightDistance <= lssdepth) {
vec2 lensuv = texCo * 2.0 - 1.0;
@ -351,7 +351,7 @@ void main() {
// #endif
#ifdef _CLensTex
fragColor.rgb += texture(lensTexture, texCo).rgb;
fragColor.rgb += textureLod(lensTexture, texCo, 0.0).rgb;
#endif
#ifdef _CLetterbox

View File

@ -7,6 +7,6 @@ in vec2 texCoord;
out vec4 fragColor[2];
void main() {
fragColor[0] = texture(tex0, texCoord);
fragColor[1] = texture(tex1, texCoord);
fragColor[0] = textureLod(tex0, texCoord, 0.0);
fragColor[1] = textureLod(tex1, texCoord, 0.0);
}

View File

@ -8,7 +8,7 @@ in vec2 texCoord;
out vec4 fragColor[3];
void main() {
fragColor[0] = texture(tex0, texCoord);
fragColor[1] = texture(tex1, texCoord);
fragColor[2] = texture(tex2, texCoord);
fragColor[0] = textureLod(tex0, texCoord, 0.0);
fragColor[1] = textureLod(tex1, texCoord, 0.0);
fragColor[2] = textureLod(tex2, texCoord, 0.0);
}

View File

@ -9,8 +9,8 @@ in vec2 texCoord;
out vec4 fragColor[4];
void main() {
fragColor[0] = texture(tex0, texCoord);
fragColor[1] = texture(tex1, texCoord);
fragColor[2] = texture(tex2, texCoord);
fragColor[3] = texture(tex3, texCoord);
fragColor[0] = textureLod(tex0, texCoord, 0.0);
fragColor[1] = textureLod(tex1, texCoord, 0.0);
fragColor[2] = textureLod(tex2, texCoord, 0.0);
fragColor[3] = textureLod(tex3, texCoord, 0.0);
}

View File

@ -9,7 +9,7 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
vec4 col = texture(tex, texCoord);
vec4 col = textureLod(tex, texCoord, 0.0);
vec3 n = getNor(col.rg);
fragColor.rgb = n * 0.5 + 0.5;
}

View File

@ -8,6 +8,6 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
vec4 col = texture(tex, texCoord);
vec4 col = textureLod(tex, texCoord, 0.0);
fragColor.rgb = vec4(col.r * 10.0, col.g * 10.0, 0.0);
}

View File

@ -165,7 +165,7 @@ in vec3 viewRay;
out vec4 fragColor;
void main() {
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0); // Normal.xy, metallic/roughness, depth
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
@ -173,18 +173,18 @@ void main() {
n = normalize(n);
vec2 metrough = unpackFloat(g0.b);
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
vec4 g1 = textureLod(gbuffer1, texCoord, 0.0); // Basecolor.rgb, spec/occ
vec2 occspec = unpackFloat2(g1.a);
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 p = getPos(eye, eyeLook, normalize(viewRay), depth, cameraProj);
vec3 v = normalize(eye - p);
float dotNV = max(dot(n, v), 0.0);
#ifdef _Brdf
vec2 envBRDF = texture(senvmapBrdf, vec2(metrough.y, 1.0 - dotNV)).xy;
vec2 envBRDF = textureLod(senvmapBrdf, vec2(metrough.y, 1.0 - dotNV), 0.0).xy;
#endif
#ifdef _VoxelGI
@ -270,9 +270,9 @@ void main() {
#ifdef _SSAO
#ifdef _RTGI
fragColor.rgb *= texture(ssaotex, texCoord).rgb;
fragColor.rgb *= textureLod(ssaotex, texCoord, 0.0).rgb;
#else
fragColor.rgb *= texture(ssaotex, texCoord).r;
fragColor.rgb *= textureLod(ssaotex, texCoord, 0.0).r;
#endif
#endif
@ -299,7 +299,7 @@ void main() {
specularBRDF(f0, metrough.y, sdotNL, sdotNH, dotNV, sdotVH) * occspec.y;
// #ifdef _SoftShadows
// svisibility = texture(svisibility, texCoord).r;
// svisibility = textureLod(svisibility, texCoord, 0.0).r;
// #endif
#ifdef _ShadowMap
@ -335,7 +335,7 @@ void main() {
#endif
// #ifdef _Hair // Aniso
// if (texture(gbuffer2, texCoord).a == 2) {
// if (textureLod(gbuffer2, texCoord, 0.0).a == 2) {
// const float shinyParallel = metrough.y;
// const float shinyPerpendicular = 0.1;
// const vec3 v = vec3(0.99146, 0.11664, 0.05832);
@ -346,11 +346,11 @@ void main() {
// #endif
#ifdef _LightClouds
visibility *= texture(texClouds, vec2(p.xy / 100.0 + time / 80.0)).r * dot(n, vec3(0,0,1));
visibility *= textureLod(texClouds, vec2(p.xy / 100.0 + time / 80.0), 0.0).r * dot(n, vec3(0,0,1));
#endif
#ifdef _SSS
if (texture(gbuffer2, texCoord).a == 2) {
if (textureLod(gbuffer2, texCoord, 0.0).a == 2) {
#ifdef _CSM
int casi, casindex;
mat4 LWVP = getCascadeMat(distance(eye, p), casi, casindex);
@ -363,7 +363,7 @@ void main() {
float depthl = linearize(depth * 0.5 + 0.5, cameraProj);
#ifdef HLSL
depthl += texture(clustersData, vec2(0.0)).r * 1e-9; // TODO: krafix bug, needs to generate sampler
depthl += textureLod(clustersData, vec2(0.0), 0.0).r * 1e-9; // TODO: krafix bug, needs to generate sampler
#endif
int clusterI = getClusterI(texCoord, depthl, cameraPlane);
int numLights = int(texelFetch(clustersData, ivec2(clusterI, 0), 0).r * 255);
@ -414,14 +414,14 @@ void main() {
// float theta = acos(dotNV);
// vec2 tuv = vec2(metrough.y, theta / (0.5 * PI));
// tuv = tuv * LUT_SCALE + LUT_BIAS;
// vec4 t = texture(sltcMat, tuv);
// vec4 t = textureLod(sltcMat, tuv, 0.0);
// mat3 invM = mat3(
// vec3(1.0, 0.0, t.y),
// vec3(0.0, t.z, 0.0),
// vec3(t.w, 0.0, t.x));
// float ltcspec = ltcEvaluate(n, v, dotNV, p, invM, lightArea0, lightArea1, lightArea2, lightArea3);
// ltcspec *= texture(sltcMag, tuv).a;
// ltcspec *= textureLod(sltcMag, tuv, 0.0).a;
// float ltcdiff = ltcEvaluate(n, v, dotNV, p, mat3(1.0), lightArea0, lightArea1, lightArea2, lightArea3);
// fragColor.rgb = albedo * ltcdiff + ltcspec * spec;
// }

View File

@ -13,5 +13,5 @@ uniform vec2 step;
void main() {
fragColor = 1.0;
const vec2 smStep = 1.0 / shadowmapSize;
for (int i = -20 * penumbraScale; i < 20 * penumbraScale; i++) fragColor = min(fragColor, texture(shadowMap, texCoord.xy + step * smStep * i).r);
for (int i = -20 * penumbraScale; i < 20 * penumbraScale; i++) fragColor = min(fragColor, textureLod(shadowMap, texCoord.xy + step * smStep * i, 0.0).r);
}

View File

@ -3,11 +3,16 @@
#include "compiled.inc"
uniform sampler2D texdepth;
uniform vec2 screenSizeInv;
in vec2 texCoord;
out float fragColor;
void main() {
float d = textureLod(texdepth, texCoord, 0.0).r;
// Select max depth from 2x2 area..
gl_FragDepth = d;
float d0 = textureLod(texdepth, texCoord, 0.0).r;
float d1 = textureLod(texdepth, texCoord + vec2(1.0, 0.0) * screenSizeInv, 0.0).r;
float d2 = textureLod(texdepth, texCoord + vec2(0.0, 1.0) * screenSizeInv, 0.0).r;
float d3 = textureLod(texdepth, texCoord + vec2(1.0, 1.0) * screenSizeInv, 0.0).r;
fragColor = max(max(d0, d1), max(d2, d3));
}

View File

@ -2,10 +2,15 @@
"contexts": [
{
"name": "downsample_depth",
"depth_write": true,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [],
"links": [
{
"name": "screenSizeInv",
"link": "_screenSizeInv"
}
],
"texture_params": [],
"vertex_shader": "../include/pass.vert.glsl",
"fragment_shader": "downsample_depth.frag.glsl"

View File

@ -17,11 +17,11 @@ void main() {
vec2 tcrgbSE = (texCoord + vec2(1.0, 1.0) * screenSizeInv);
vec2 tcrgbM = vec2(texCoord);
vec3 rgbNW = texture(tex, tcrgbNW).rgb;
vec3 rgbNE = texture(tex, tcrgbNE).rgb;
vec3 rgbSW = texture(tex, tcrgbSW).rgb;
vec3 rgbSE = texture(tex, tcrgbSE).rgb;
vec4 texColor = texture(tex, tcrgbM);
vec3 rgbNW = textureLod(tex, tcrgbNW, 0.0).rgb;
vec3 rgbNE = textureLod(tex, tcrgbNE, 0.0).rgb;
vec3 rgbSW = textureLod(tex, tcrgbSW, 0.0).rgb;
vec3 rgbSE = textureLod(tex, tcrgbSE, 0.0).rgb;
vec4 texColor = textureLod(tex, tcrgbM, 0.0);
vec3 rgbM = texColor.rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
@ -45,11 +45,11 @@ void main() {
dir * rcpDirMin)) * screenSizeInv;
vec3 rgbA = 0.5 * (
texture(tex, texCoord + dir * (1.0 / 3.0 - 0.5)).rgb +
texture(tex, texCoord + dir * (2.0 / 3.0 - 0.5)).rgb);
textureLod(tex, texCoord + dir * (1.0 / 3.0 - 0.5), 0.0).rgb +
textureLod(tex, texCoord + dir * (2.0 / 3.0 - 0.5), 0.0).rgb);
fragColor.rgb = rgbA * 0.5 + 0.25 * ( // vec3 rgbB
texture(tex, texCoord + dir * -0.5).rgb +
texture(tex, texCoord + dir * 0.5).rgb);
textureLod(tex, texCoord + dir * -0.5, 0.0).rgb +
textureLod(tex, texCoord + dir * 0.5, 0.0).rgb);
// float lumaB = dot(rgbB, luma);
float lumaB = dot(fragColor.rgb, luma);

View File

@ -6,5 +6,5 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
fragColor = texture(tex, texCoord);
fragColor = textureLod(tex, texCoord, 0.0);
}

View File

@ -29,14 +29,14 @@ vec2 getVelocity(vec2 coord, float depth) {
}
void main() {
fragColor.rgb = texture(tex, texCoord).rgb;
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
// Do not blur masked objects
if (texture(gbuffer0, texCoord).a == 1.0) {
if (textureLod(gbuffer0, texCoord, 0.0).a == 1.0) {
return;
}
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
if (depth == 1.0) {
return;
}
@ -48,8 +48,8 @@ void main() {
int processed = 1;
for(int i = 0; i < 8; ++i) {
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
fragColor.rgb += texture(tex, offset).rgb;
if (textureLod(gbuffer0, offset, 0.0).a != 1.0) {
fragColor.rgb += textureLod(tex, offset, 0.0).rgb;
processed++;
}
}

View File

@ -14,12 +14,12 @@ in vec2 texCoord;
out vec4 fragColor;
void main() {
vec2 velocity = texture(sveloc, texCoord).rg * motionBlurIntensity * frameScale;
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale;
fragColor.rgb = texture(tex, texCoord).rgb;
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
// Do not blur masked objects
if (texture(gbuffer0, texCoord).a == 1.0) {
if (textureLod(gbuffer0, texCoord, 0.0).a == 1.0) {
return;
}
@ -29,7 +29,7 @@ void main() {
const int samples = 8;
for (int i = 0; i < samples; ++i) {
vec2 offset = velocity * (float(i) / float(samples - 1) - 0.5);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
fragColor.rgb += textureLod(tex, texCoord + offset, 0.0).rgb;
}
fragColor.rgb /= float(samples + 1);
}

View File

@ -21,7 +21,7 @@ void main() {
texCoord.y = 1.0 - texCoord.y;
#endif
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0); // Normal.xy, metallic/roughness, depth
float roughness = unpackFloat(g0.b).y;
if (roughness > 0.95) {
@ -29,13 +29,13 @@ void main() {
return;
}
float spec = fract(texture(gbuffer1, texCoord).a);
float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a);
if (spec == 0.0) {
fragColor.rgb = vec3(0.0);
return;
}
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 wp = getPos2(invVP, depth, texCoord);
vec2 enc = g0.rg;

View File

@ -21,7 +21,7 @@ void main() {
texCoord.y = 1.0 - texCoord.y;
#endif
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0); // Normal.xy, metallic/roughness, depth
float roughness = unpackFloat(g0.b).y;
if (roughness > 0.95) {
@ -29,13 +29,13 @@ void main() {
return;
}
float spec = fract(texture(gbuffer1, texCoord).a);
float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a);
if (spec == 0.0) {
fragColor.rgb = vec3(0.0);
return;
}
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 wp = getPos2(invVP, depth, texCoord);
vec4 pp = probeVP * vec4(wp.xyz, 1.0);
vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5;

View File

@ -56,9 +56,9 @@ out vec4 fragColor;
// Misc functions
// Gathers current pixel, and the top-left neighbors.
// vec3 SMAAGatherNeighbours(vec2 texcoord/*, vec4 offset[3], sampler2D tex*/) {
// float P = texture(tex, texcoord).r;
// float Pleft = texture(tex, offset0.xy).r;
// float Ptop = texture(tex, offset0.zw).r;
// float P = textureLod(tex, texcoord, 0.0).r;
// float Pleft = textureLod(tex, offset0.xy, 0.0).r;
// float Ptop = textureLod(tex, offset0.zw, 0.0).r;
// return vec3(P, Pleft, Ptop);
// }
@ -88,10 +88,10 @@ vec2 SMAALumaEdgeDetectionPS(vec2 texcoord
// Calculate lumas:
vec3 weights = vec3(0.2126, 0.7152, 0.0722);
float L = dot(texture(colorTex, texcoord).rgb, weights);
float L = dot(textureLod(colorTex, texcoord, 0.0).rgb, weights);
float Lleft = dot(texture(colorTex, offset0.xy).rgb, weights);
float Ltop = dot(texture(colorTex, offset0.zw).rgb, weights);
float Lleft = dot(textureLod(colorTex, offset0.xy, 0.0).rgb, weights);
float Ltop = dot(textureLod(colorTex, offset0.zw, 0.0).rgb, weights);
// We do the usual threshold:
vec4 delta;
@ -103,16 +103,16 @@ vec2 SMAALumaEdgeDetectionPS(vec2 texcoord
discard;
// Calculate right and bottom deltas:
float Lright = dot(texture(colorTex, offset1.xy).rgb, weights);
float Lbottom = dot(texture(colorTex, offset1.zw).rgb, weights);
float Lright = dot(textureLod(colorTex, offset1.xy, 0.0).rgb, weights);
float Lbottom = dot(textureLod(colorTex, offset1.zw, 0.0).rgb, weights);
delta.zw = abs(L - vec2(Lright, Lbottom));
// Calculate the maximum delta in the direct neighborhood:
vec2 maxDelta = max(delta.xy, delta.zw);
// Calculate left-left and top-top deltas:
float Lleftleft = dot(texture(colorTex, offset2.xy).rgb, weights);
float Ltoptop = dot(texture(colorTex, offset2.zw).rgb, weights);
float Lleftleft = dot(textureLod(colorTex, offset2.xy, 0.0).rgb, weights);
float Ltoptop = dot(textureLod(colorTex, offset2.zw, 0.0).rgb, weights);
delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop));
// Calculate the final maximum delta:
@ -142,13 +142,13 @@ vec2 SMAAColorEdgeDetectionPS(vec2 texcoord
// Calculate color deltas:
vec4 delta;
vec3 C = texture(colorTex, texcoord).rgb;
vec3 C = textureLod(colorTex, texcoord, 0.0).rgb;
vec3 Cleft = texture(colorTex, offset0.xy).rgb;
vec3 Cleft = textureLod(colorTex, offset0.xy, 0.0).rgb;
vec3 t = abs(C - Cleft);
delta.x = max(max(t.r, t.g), t.b);
vec3 Ctop = texture(colorTex, offset0.zw).rgb;
vec3 Ctop = textureLod(colorTex, offset0.zw, 0.0).rgb;
t = abs(C - Ctop);
delta.y = max(max(t.r, t.g), t.b);
@ -160,11 +160,11 @@ vec2 SMAAColorEdgeDetectionPS(vec2 texcoord
discard;
// Calculate right and bottom deltas:
vec3 Cright = texture(colorTex, offset1.xy).rgb;
vec3 Cright = textureLod(colorTex, offset1.xy, 0.0).rgb;
t = abs(C - Cright);
delta.z = max(max(t.r, t.g), t.b);
vec3 Cbottom = texture(colorTex, offset1.zw).rgb;
vec3 Cbottom = textureLod(colorTex, offset1.zw, 0.0).rgb;
t = abs(C - Cbottom);
delta.w = max(max(t.r, t.g), t.b);
@ -172,11 +172,11 @@ vec2 SMAAColorEdgeDetectionPS(vec2 texcoord
vec2 maxDelta = max(delta.xy, delta.zw);
// Calculate left-left and top-top deltas:
vec3 Cleftleft = texture(colorTex, offset2.xy).rgb;
vec3 Cleftleft = textureLod(colorTex, offset2.xy, 0.0).rgb;
t = abs(C - Cleftleft);
delta.z = max(max(t.r, t.g), t.b);
vec3 Ctoptop = texture(colorTex, offset2.zw).rgb;
vec3 Ctoptop = textureLod(colorTex, offset2.zw, 0.0).rgb;
t = abs(C - Ctoptop);
delta.w = max(max(t.r, t.g), t.b);

View File

@ -27,9 +27,9 @@ vec4 textureLodA(sampler2D tex, vec2 coords, float lod) {
vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) {
// Fetch the blending weights for current pixel:
vec4 a;
a.x = texture(blendTex, offset.xy).a; // Right
a.y = texture(blendTex, offset.zw).g; // Top
a.wz = texture(blendTex, texcoord).xz; // Bottom / Left
a.x = textureLod(blendTex, offset.xy, 0.0).a; // Right
a.y = textureLod(blendTex, offset.zw, 0.0).g; // Top
a.wz = textureLod(blendTex, texcoord, 0.0).xz; // Bottom / Left
// Is there any blending weight with a value greater than 0.0?
//SMAA_BRANCH

View File

@ -42,11 +42,11 @@ uniform vec2 aspectRatio;
in vec2 texCoord;
in vec3 viewRay;
out vec4 fragColor;
out float fragColor;
void main() {
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
if (depth == 1.0) { fragColor.r = 1.0; return; }
if (depth == 1.0) { fragColor = 1.0; return; }
vec2 enc = textureLod(gbuffer0, texCoord, 0.0).rg;
vec3 n;
@ -65,7 +65,7 @@ void main() {
vec2(sin(randomVec.x * PI), cos(randomVec.x * PI)));
float radius = ssaoSize * randomVec.y;
fragColor.r = 0;
fragColor = 0;
for (int i = 0; i < 12; ++i) {
vec2 k = ((rotMat * kernel[i] * aspectRatio) / currentDistance) * radius;
depth = textureLod(gbufferD, texCoord + k, 0.0).r * 2.0 - 1.0;
@ -76,9 +76,9 @@ void main() {
angle -= currentDistanceA;
angle = max(0.0, angle);
angle /= dot(pos, pos) / currentDistanceB + 0.015; // Fix darkening
fragColor.r += angle;
fragColor += angle;
}
fragColor.r *= ssaoStrength / kernelSize;
fragColor.r = 1.0 - fragColor.r;
fragColor *= ssaoStrength / kernelSize;
fragColor = 1.0 - fragColor;
}

View File

@ -9,7 +9,7 @@ uniform sampler2D gbuffer0;
uniform vec2 dirInv; // texStep
in vec2 texCoord;
out vec4 fragColor;
out float fragColor;
const float blurWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
// const float blurWeights[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
@ -18,15 +18,15 @@ const float discardThreshold = 0.95;
float doBlur(const float blurWeight, const int pos, const vec3 nor, const vec2 texCoord) {
const float posadd = pos + 0.5;
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * dirInv).rg);
vec3 nor2 = getNor(textureLod(gbuffer0, texCoord + pos * dirInv, 0.0).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
vec4 col = texture(tex, texCoord + posadd * dirInv);
float col = textureLod(tex, texCoord + posadd * dirInv, 0.0).r;
fragColor += col * blurWeight * influenceFactor;
float weight = blurWeight * influenceFactor;
nor2 = getNor(texture(gbuffer0, texCoord - pos * dirInv).rg);
nor2 = getNor(textureLod(gbuffer0, texCoord - pos * dirInv, 0.0).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = texture(tex, texCoord - posadd * dirInv);
col = textureLod(tex, texCoord - posadd * dirInv, 0.0).r;
fragColor += col * blurWeight * influenceFactor;
weight += blurWeight * influenceFactor;
@ -34,13 +34,13 @@ float doBlur(const float blurWeight, const int pos, const vec3 nor, const vec2 t
}
void main() {
vec3 nor = getNor(texture(gbuffer0, texCoord).rg);
vec3 nor = getNor(textureLod(gbuffer0, texCoord, 0.0).rg);
fragColor = texture(tex, texCoord) * blurWeights[0];
fragColor = textureLod(tex, texCoord, 0.0).r * blurWeights[0];
float weight = blurWeights[0];
for (int i = 1; i < 5; i++) {
weight += doBlur(blurWeights[i], i, nor, texCoord);
}
fragColor = vec4(fragColor / weight);
fragColor = fragColor / weight;
}

View File

@ -14,10 +14,6 @@ uniform mat4 tiV;
uniform vec2 cameraProj;
// const int ssgiStrength = 1.0;
// const int ssgiMaxSteps = 16;
// const int ssgiBinarySteps = 4;
// const float ssgiRayStep = 0.005;
const float angleMix = 0.5f;
#ifdef _SSGICone9
const float strength = 2.0 * (1.0 / ssgiStrength);
@ -27,15 +23,15 @@ const float strength = 2.0 * (1.0 / ssgiStrength) * 1.8;
in vec3 viewRay;
in vec2 texCoord;
out vec4 fragColor;
out float fragColor;
vec3 hitCoord;
vec2 coord;
float depth;
float occ = 0.0;
#ifdef _RTGI
vec3 col = vec3(0.0);
#endif
// #ifdef _RTGI
// vec3 col = vec3(0.0);
// #endif
vec3 vpos;
vec2 getProjectedCoord(vec3 hitCoord) {
@ -50,39 +46,27 @@ vec2 getProjectedCoord(vec3 hitCoord) {
float getDeltaDepth(vec3 hitCoord) {
coord = getProjectedCoord(hitCoord);
depth = texture(gbufferD, coord).r * 2.0 - 1.0;
depth = textureLod(gbufferD, coord, 0.0).r * 2.0 - 1.0;
vec3 p = getPosView(viewRay, depth, cameraProj);
return p.z - hitCoord.z;
}
// void binarySearch(vec3 dir) {
// for (int i = 0; i < ssgiBinarySteps; i++) {
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// }
// }
void rayCast(vec3 dir) {
hitCoord = vpos;
dir *= ssgiRayStep;
#ifdef _SSGICone9
float dist = 1.0 / 9.0;
#else
float dist = 1.0 / 5.0;
#endif
float dist = 0.1;
for (int i = 0; i < ssgiMaxSteps; i++) {
hitCoord += dir;
float delta = getDeltaDepth(hitCoord);
if (delta > 0.0 && delta < 0.2) {
dist = distance(vpos, hitCoord);
/* binarySearch(dir); */ break;
break;
}
}
occ += dist;
#ifdef _RTGI
col += texture(gbuffer1, coord).rgb * ((ssgiRayStep * ssgiMaxSteps) - dist);
#endif
// #ifdef _RTGI
// col += textureLod(gbuffer1, coord, 0.0).rgb * ((ssgiRayStep * ssgiMaxSteps) - dist);
// #endif
}
vec3 tangent(const vec3 n) {
@ -93,15 +77,13 @@ vec3 tangent(const vec3 n) {
}
void main() {
vec4 g0 = texture(gbuffer0, texCoord);
float d = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// if (d == 1.0) { fragColor.rgb = vec3(0.0); return; }
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0);
float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec2 enc = g0.rg;
vec4 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n.xyz = normalize(n.xyz);
n.w = 1.0;
n = tiV * n;
n.xyz = normalize(n.xyz);
@ -125,9 +107,9 @@ void main() {
rayCast(mix(n.xyz, c2, angleMix));
#endif
#ifdef _RTGI
fragColor.rgb = vec3((occ + col * occ) * strength);
#else
fragColor.r = occ * strength;
#endif
// #ifdef _RTGI
// fragColor.rgb = vec3((occ + col * occ) * strength);
// #else
fragColor = occ * strength;
// #endif
}

View File

@ -9,7 +9,7 @@ uniform sampler2D gbufferD;
uniform sampler2D gbuffer0; // Normal, roughness
uniform sampler2D gbuffer1; // basecol, spec
uniform mat4 P;
uniform mat4 tiV;
uniform mat3 V3;
uniform vec2 cameraProj;
in vec3 viewRay;
@ -40,6 +40,7 @@ float getDeltaDepth(const vec3 hit) {
vec4 binarySearch(vec3 dir) {
float ddepth;
vec3 start = hitCoord;
for (int i = 0; i < numBinarySearchSteps; i++) {
dir *= 0.5;
hitCoord -= dir;
@ -47,7 +48,7 @@ vec4 binarySearch(vec3 dir) {
if (ddepth < 0.0) hitCoord += dir;
}
// Ugly discard of hits too far away
if (abs(ddepth) > 0.01) return vec4(0.0);
if (abs(ddepth) > ssrSearchDist / 50) return vec4(0.0);
return vec4(getProjectedCoord(hitCoord), 0.0, 1.0);
}
@ -77,17 +78,13 @@ void main() {
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
#ifdef _SSRZOnly
if (n.z <= 0.9) { fragColor.rgb = vec3(0.0); return; }
#endif
vec4 viewNormal = tiV * vec4(n, 1.0);
vec3 viewNormal = V3 * n;
vec3 viewPos = getPosView(viewRay, d, cameraProj);
vec3 reflected = normalize(reflect(viewPos, viewNormal));
hitCoord = viewPos;
vec3 reflected = normalize(reflect(viewPos, viewNormal.xyz));
hitCoord = viewPos.xyz;
vec3 dir = reflected * max(ssrMinRayStep, -viewPos.z) * (1.0 - rand(texCoord) * ssrJitter * roughness);
vec3 dir = reflected * (1.0 - rand(texCoord) * ssrJitter * roughness) * 2.0;
// * max(ssrMinRayStep, -viewPos.z)
vec4 coords = rayCast(dir);
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
@ -97,7 +94,7 @@ void main() {
float intensity = pow(reflectivity, ssrFalloffExp) *
screenEdgeFactor *
clamp(-reflected.z, 0.0, 1.0) *
clamp((ssrSearchDist - length(viewPos.xyz - hitCoord)) *
clamp((ssrSearchDist - length(viewPos - hitCoord)) *
(1.0 / ssrSearchDist), 0.0, 1.0) *
coords.w;

View File

@ -11,8 +11,8 @@
"link": "_projectionMatrix"
},
{
"name": "tiV",
"link": "_transposeInverseViewMatrix"
"name": "V3",
"link": "_viewMatrix3"
},
{
"name": "invP",

View File

@ -67,14 +67,14 @@ vec4 SSSSBlur() {
kernel[9] = vec4(0.0192831, 0.00282018, 0.00084214, 1.28);
kernel[10] = vec4(0.00471691, 0.000184771, 5.07565e-005, 2);
vec4 colorM = texture(tex, texCoord);
vec4 colorM = textureLod(tex, texCoord, 0.0);
// Initialize the stencil buffer in case it was not already available:
// if (initStencil) // (Checked in compile time, it's optimized away)
// if (SSSS_STREGTH_SOURCE == 0.0) discard;
// Fetch linear depth of current pixel
float depth = texture(gbufferD, texCoord).r;
float depth = textureLod(gbufferD, texCoord, 0.0).r;
float depthM = cameraProj.y / (depth - cameraProj.x);
// Calculate the sssWidth scale (1.0 for a unit plane sitting on the projection window)
@ -94,10 +94,10 @@ vec4 SSSSBlur() {
for (int i = 1; i < SSSS_N_SAMPLES; i++) {
// Fetch color and depth for current sample
vec2 offset = texCoord + kernel[i].a * finalStep;
vec4 color = texture(tex, offset);
vec4 color = textureLod(tex, offset, 0.0);
// #if SSSS_FOLLOW_SURFACE == 1
// If the difference in depth is huge, we lerp color back to "colorM":
// float depth = texture(depthTex, offset).r;
// float depth = textureLod(depthTex, offset, 0.0).r;
// float s = SSSSSaturate(300.0f * distanceToProjectionWindow *
// sssWidth * abs(depthM - depth));
// color.rgb = SSSSLerp(color.rgb, colorM.rgb, s);
@ -111,10 +111,10 @@ vec4 SSSSBlur() {
void main() {
// SSS only masked objects
if (texture(gbuffer2, texCoord).a == 2) {
if (textureLod(gbuffer2, texCoord, 0.0).a == 2) {
fragColor = clamp(SSSSBlur(), 0.0, 1.0);
}
else {
fragColor = texture(tex, texCoord);
fragColor = textureLod(tex, texCoord, 0.0);
}
}

View File

@ -21,9 +21,9 @@ const float namount = 0.0001; // Dither amount
vec3 color(vec2 coords, const float blur, const sampler2D tex, const vec2 texStep) {
vec3 col = vec3(0.0);
col.r = texture(tex, coords + vec2(0.0, 1.0) * texStep * fringe * blur).r;
col.g = texture(tex, coords + vec2(-0.866, -0.5) * texStep * fringe * blur).g;
col.b = texture(tex, coords + vec2(0.866, -0.5) * texStep * fringe * blur).b;
col.r = textureLod(tex, coords + vec2(0.0, 1.0) * texStep * fringe * blur, 0.0).r;
col.g = textureLod(tex, coords + vec2(-0.866, -0.5) * texStep * fringe * blur, 0.0).g;
col.b = textureLod(tex, coords + vec2(0.866, -0.5) * texStep * fringe * blur, 0.0).b;
const vec3 lumcoeff = vec3(0.299, 0.587, 0.114);
float lum = dot(col.rgb, lumcoeff);
@ -34,7 +34,7 @@ vec3 color(vec2 coords, const float blur, const sampler2D tex, const vec2 texSte
vec3 dof(const vec2 texCoord, const float gdepth, const sampler2D tex, const sampler2D gbufferD, const vec2 texStep, const vec2 cameraProj) {
float depth = linearize(gdepth, cameraProj);
// const float fDepth = compoDOFDistance;
float fDepth = linearize(texture(gbufferD, focus).r * 2.0 - 1.0, cameraProj); // Autofocus
float fDepth = linearize(textureLod(gbufferD, focus, 0.0).r * 2.0 - 1.0, cameraProj); // Autofocus
const float f = compoDOFLength; // Focal length in mm
const float d = fDepth * 1000.0; // Focal plane in mm
@ -50,10 +50,10 @@ vec3 dof(const vec2 texCoord, const float gdepth, const sampler2D tex, const sam
float h = (texStep.y) * blur * maxblur + noise.y;
vec3 col = vec3(0.0);
if (blur < 0.05) {
col = texture(tex, texCoord).rgb;
col = textureLod(tex, texCoord, 0.0).rgb;
}
else {
col = texture(tex, texCoord).rgb;
col = textureLod(tex, texCoord, 0.0).rgb;
float s = 1.0;
int ringsamples;

View File

@ -14,7 +14,7 @@ vec2 getProjectedCoord(vec3 hitCoord) {
float getDeltaDepth(vec3 hitCoord, sampler2D gbufferD, mat4 invVP, vec3 eye) {
vec2 texCoord = getProjectedCoord(hitCoord);
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 wpos = getPos2(invVP, depth, texCoord);
float d1 = length(eye - wpos);
float d2 = length(eye - hitCoord);

View File

@ -14,14 +14,14 @@ out vec4 fragColor;
const float SMAA_REPROJECTION_WEIGHT_SCALE = 30.0;
void main() {
vec4 current = texture(tex, texCoord);
vec4 current = textureLod(tex, texCoord, 0.0);
#ifdef _Veloc
// Velocity is assumed to be calculated for motion blur, so we need to inverse it for reprojection
vec2 velocity = -textureLod(sveloc, texCoord, 0.0).rg;
// Reproject current coordinates and fetch previous pixel
vec4 previous = texture(tex2, texCoord + velocity);
vec4 previous = textureLod(tex2, texCoord + velocity, 0.0);
// Attenuate the previous pixel if the velocity is different
#ifdef _SMAA
@ -34,7 +34,7 @@ void main() {
// Blend the pixels according to the calculated weight:
fragColor = vec4(mix(current.rgb, previous.rgb, weight), 1.0);
#else
vec4 previous = texture(tex2, texCoord);
vec4 previous = textureLod(tex2, texCoord, 0.0);
fragColor = vec4(mix(current.rgb, previous.rgb, 0.5), 1.0);
#endif
}

View File

@ -24,7 +24,7 @@ in vec3 viewRay;
out float fragColor[2];
void main() {
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 p = getPos(eye, eyeLook, normalize(viewRay), depth, cameraProj);
vec4 lightPosition = LWVP * vec4(p, 1.0);
@ -36,7 +36,7 @@ void main() {
fragColor[0] = float(sm + shadowsBias > lPos.z);
// Distance
float d = texture(dilate, lPos.xy).r;
float d = textureLod(dilate, lPos.xy, 0.0).r;
fragColor[1] = max((lPos.z - d), 0.0);
fragColor[1] *= 100 * penumbraDistance;
}

View File

@ -69,9 +69,9 @@ void main() {
vec2 screenPosition = wvpposition.xy / wvpposition.w;
vec2 texCoord = screenPosition * 0.5 + 0.5;
float pixelRayMarchNoise = texture(snoise, texCoord * 100).r * 2.0 - 1.0;
float pixelRayMarchNoise = textureLod(snoise, texCoord * 100, 0.0).r * 2.0 - 1.0;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 worldPos = getPos2(invVP, depth, texCoord);
vec3 viewVec = worldPos - eye;

View File

@ -67,9 +67,9 @@ void rayStep(inout vec3 curPos, inout float curOpticalDepth, inout float scatter
void main() {
float pixelRayMarchNoise = texture(snoise, texCoord * 100).r * 2.0 - 1.0;
float pixelRayMarchNoise = textureLod(snoise, texCoord * 100, 0.0).r * 2.0 - 1.0;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 worldPos = getPos(eye, eyeLook, normalize(viewRay), depth, cameraProj);
vec3 viewVec = worldPos - eye;

View File

@ -171,7 +171,7 @@ vec3 getSeaColor(vec3 p, vec3 n, vec3 l, vec3 eye, vec3 dist) {
}
void main() {
float gdepth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
float gdepth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
// vec4 colorOriginal = vec4(1.0);//texture(tex, texCoord);
if (gdepth == 1.0) {
fragColor = vec4(0.0);

View File

@ -165,7 +165,36 @@ class RenderPathDeferred {
}
#end
#if ((rp_ssgi != "Off") || (rp_antialiasing == "SMAA") || (rp_antialiasing == "TAA"))
#if (rp_ssgi != "Off")
{
var t = new RenderTargetRaw();
t.name = "singlea";
t.width = 0;
t.height = 0;
t.displayp = Inc.getDisplayp();
t.format = "R8";
t.scale = Inc.getSuperSampling();
#if rp_ssgi_half
t.scale *= 0.5;
#end
path.createRenderTarget(t);
}
{
var t = new RenderTargetRaw();
t.name = "singleb";
t.width = 0;
t.height = 0;
t.displayp = Inc.getDisplayp();
t.format = "R8";
t.scale = Inc.getSuperSampling();
#if rp_ssgi_half
t.scale *= 0.5;
#end
path.createRenderTarget(t);
}
#end
#if ((rp_antialiasing == "SMAA") || (rp_antialiasing == "TAA"))
{
var t = new RenderTargetRaw();
t.name = "bufa";
@ -234,7 +263,7 @@ class RenderPathDeferred {
t.displayp = Inc.getDisplayp();
t.format = "R8";
t.scale = Inc.getSuperSampling();
// t.scale = 0.5;
// t.scale = Inc.getSuperSampling() * 0.5;
path.createRenderTarget(t);
}
{
@ -245,7 +274,7 @@ class RenderPathDeferred {
t.displayp = Inc.getDisplayp();
t.format = "R8";
t.scale = Inc.getSuperSampling();
// t.scale = 0.5;
// t.scale = Inc.getSuperSampling() * 0.5;
path.createRenderTarget(t);
}
}
@ -293,6 +322,21 @@ class RenderPathDeferred {
}
#end
#if (rp_ssr || (rp_ssgi != "Off"))
{
{
path.loadShader("shader_datas/downsample_depth/downsample_depth");
var t = new RenderTargetRaw();
t.name = "half";
t.width = 0;
t.height = 0;
t.scale = Inc.getSuperSampling() * 0.5;
t.format = "R32"; // R16
path.createRenderTarget(t);
}
}
#end
#if rp_ssr
{
path.loadShader("shader_datas/ssr_pass/ssr_pass");
@ -300,23 +344,12 @@ class RenderPathDeferred {
path.loadShader("shader_datas/blur_adaptive_pass/blur_adaptive_pass_y3_blend");
#if rp_ssr_half
{
path.loadShader("shader_datas/downsample_depth/downsample_depth");
var t = new RenderTargetRaw();
t.name = "half";
t.width = 0;
t.height = 0;
t.scale = 0.5;
t.format = "DEPTH16";
path.createRenderTarget(t);
}
{
var t = new RenderTargetRaw();
t.name = "ssra";
t.width = 0;
t.height = 0;
t.scale = 0.5;
t.scale = Inc.getSuperSampling() * 0.5;
t.format = Inc.getHdrFormat();
path.createRenderTarget(t);
}
@ -325,7 +358,7 @@ class RenderPathDeferred {
t.name = "ssrb";
t.width = 0;
t.height = 0;
t.scale = 0.5;
t.scale = Inc.getSuperSampling() * 0.5;
t.format = Inc.getHdrFormat();
path.createRenderTarget(t);
}
@ -456,43 +489,49 @@ class RenderPathDeferred {
}
#end
#if (rp_ssr || (rp_ssgi != "Off"))
path.setTarget("half");
path.bindTarget("_main", "texdepth");
path.drawShader("shader_datas/downsample_depth/downsample_depth");
#end
#if ((rp_ssgi == "RTGI") || (rp_ssgi == "RTAO"))
{
if (armory.data.Config.raw.rp_ssgi != false) {
path.setTarget("bufa");
path.bindTarget("_main", "gbufferD");
path.setTarget("singlea");
path.bindTarget("half", "gbufferD");
path.bindTarget("gbuffer0", "gbuffer0");
#if (rp_ssgi == "RTGI")
path.bindTarget("gbuffer1", "gbuffer1");
#end
path.drawShader("shader_datas/ssgi_pass/ssgi_pass");
path.setTarget("bufb");
path.setTarget("singleb");
path.bindTarget("gbuffer0", "gbuffer0");
path.bindTarget("bufa", "tex");
path.bindTarget("singlea", "tex");
path.drawShader("shader_datas/ssgi_blur_pass/ssgi_blur_pass_x");
path.setTarget("bufa");
path.setTarget("singlea");
path.bindTarget("gbuffer0", "gbuffer0");
path.bindTarget("bufb", "tex");
path.bindTarget("singleb", "tex");
path.drawShader("shader_datas/ssgi_blur_pass/ssgi_blur_pass_y");
}
}
#elseif (rp_ssgi == "SSAO")
{
if (armory.data.Config.raw.rp_ssgi != false) {
path.setTarget("bufa");
path.bindTarget("_main", "gbufferD");
path.setTarget("singlea");
path.bindTarget("half", "gbufferD");
path.bindTarget("gbuffer0", "gbuffer0");
path.drawShader("shader_datas/ssao_pass/ssao_pass");
path.setTarget("bufb");
path.bindTarget("bufa", "tex");
path.setTarget("singleb");
path.bindTarget("singlea", "tex");
path.bindTarget("gbuffer0", "gbuffer0");
path.drawShader("shader_datas/blur_edge_pass/blur_edge_pass_x");
path.setTarget("bufa");
path.bindTarget("bufb", "tex");
path.setTarget("singlea");
path.bindTarget("singleb", "tex");
path.bindTarget("gbuffer0", "gbuffer0");
path.drawShader("shader_datas/blur_edge_pass/blur_edge_pass_y");
}
@ -585,7 +624,7 @@ class RenderPathDeferred {
#if (rp_ssgi != "Off")
{
if (armory.data.Config.raw.rp_ssgi != false) {
path.bindTarget("bufa", "ssaotex");
path.bindTarget("singlea", "ssaotex");
}
else {
path.bindTarget("empty_white", "ssaotex");
@ -761,19 +800,14 @@ class RenderPathDeferred {
#if rp_ssr_half
var targeta = "ssra";
var targetb = "ssrb";
path.setTarget("half");
path.bindTarget("_main", "texdepth");
path.drawShader("shader_datas/downsample_depth/downsample_depth");
var targetdepth = "_half";
#else
var targeta = "buf";
var targetb = "gbuffer1";
var targetdepth = "_main";
#end
path.setTarget(targeta);
path.bindTarget("tex", "tex");
path.bindTarget(targetdepth, "gbufferD");
path.bindTarget("half", "gbufferD");
path.bindTarget("gbuffer0", "gbuffer0");
path.bindTarget("gbuffer1", "gbuffer1");
path.drawShader("shader_datas/ssr_pass/ssr_pass");

View File

@ -262,6 +262,8 @@ def build():
else:
assets.add_shader_pass('ssgi_pass')
assets.add_shader_pass('ssgi_blur_pass')
if rpdat.arm_ssgi_half_res:
assets.add_khafile_def('rp_ssgi_half')
if rpdat.rp_renderer == 'Deferred':
assets.add_shader_pass('deferred_light')
@ -308,9 +310,9 @@ def build():
assets.add_shader_pass('blur_adaptive_pass')
if rpdat.arm_ssr_half_res:
assets.add_khafile_def('rp_ssr_half')
assets.add_shader_pass('downsample_depth')
if rpdat.rp_ssr_z_only:
wrd.world_defs += '_SSRZOnly'
if rpdat.rp_ssr or rpdat.rp_ssgi != 'Off':
assets.add_shader_pass('downsample_depth')
if rpdat.rp_motionblur != 'Off':
assets.add_khafile_def('rp_motionblur={0}'.format(rpdat.rp_motionblur))

View File

@ -130,7 +130,7 @@ def update_preset(self, context):
rpdat.rp_antialiasing = 'TAA'
rpdat.rp_compositornodes = True
rpdat.rp_volumetriclight = False
rpdat.rp_ssgi = 'RTGI'
rpdat.rp_ssgi = 'RTAO'
rpdat.arm_ssrs = False
rpdat.rp_ssr = True
rpdat.rp_bloom = True
@ -303,8 +303,8 @@ class ArmRPListItem(bpy.types.PropertyGroup):
rp_ssgi = EnumProperty(
items=[('Off', 'No AO', 'Off'),
('SSAO', 'SSAO', 'Screen space ambient occlusion'),
('RTAO', 'RTAO', 'Ray-traced ambient occlusion'),
('RTGI', 'RTGI', 'Ray-traced global illumination')
('RTAO', 'RTAO', 'Ray-traced ambient occlusion')
# ('RTGI', 'RTGI', 'Ray-traced global illumination')
],
name="SSGI", description="Screen space global illumination", default='SSAO', update=update_renderpath)
rp_bloom = BoolProperty(name="Bloom", description="Bloom processing", default=False, update=update_renderpath)
@ -413,7 +413,6 @@ class ArmRPListItem(bpy.types.PropertyGroup):
name="Filter", description="Scaling filter", default='Linear')
rp_dynres = BoolProperty(name="Dynamic Resolution", description="Dynamic resolution scaling for performance", default=False, update=update_renderpath)
arm_ssr_half_res = BoolProperty(name="Half Res", description="Trace in half resolution", default=True, update=update_renderpath)
rp_ssr_z_only = BoolProperty(name="Z Only", description="Trace in Z axis only", default=False, update=update_renderpath)
rp_voxelgi_relight = BoolProperty(name="Relight", description="Relight voxels when light is moved", default=True, update=update_renderpath)
arm_voxelgi_dimensions = FloatProperty(name="Dimensions", description="Voxelization bounds",default=16, update=assets.invalidate_shader_cache)
arm_voxelgi_revoxelize = BoolProperty(name="Revoxelize", description="Revoxelize scene each frame", default=False, update=assets.invalidate_shader_cache)
@ -432,7 +431,6 @@ class ArmRPListItem(bpy.types.PropertyGroup):
('8', '8', '8'),
('16', '16', '16')],
name="MSAA", description="Samples per pixel usable for render paths drawing directly to framebuffer", default='1')
arm_ssao_half_res = BoolProperty(name="Half Res", description="Trace in half resolution", default=False, update=assets.invalidate_shader_cache)
arm_voxelgi_diff = FloatProperty(name="Diffuse", description="", default=3.0, update=assets.invalidate_shader_cache)
arm_voxelgi_cones = EnumProperty(
@ -473,7 +471,8 @@ class ArmRPListItem(bpy.types.PropertyGroup):
items=[('9', '9', '9'),
('5', '5', '5'),
],
name="Rays", description="Number of rays to trace for RTAO/RTGI", default='5', update=assets.invalidate_shader_cache)
name="Rays", description="Number of rays to trace for RTAO", default='5', update=assets.invalidate_shader_cache)
arm_ssgi_half_res = BoolProperty(name="Half Res", description="Trace in half resolution", default=False, update=assets.invalidate_shader_cache)
arm_bloom_threshold = FloatProperty(name="Threshold", default=1.0, update=assets.invalidate_shader_cache)
arm_bloom_strength = FloatProperty(name="Strength", default=3.5, update=assets.invalidate_shader_cache)
arm_bloom_radius = FloatProperty(name="Radius", default=3.0, update=assets.invalidate_shader_cache)

View File

@ -892,6 +892,8 @@ class ArmRenderPathPanel(bpy.types.Panel):
row = self.row(box)
self.prop(row, rpdat, "rp_ssgi", expand=True)
col = self.column(box, enabled=(rpdat.rp_ssgi != 'Off'))
row = self.row(col, align=True)
self.prop(row, rpdat, 'arm_ssgi_half_res')
self.prop(col, rpdat, 'arm_ssgi_rays')
row = self.row(col, align=True, alignment='EXPAND')
self.prop(row, rpdat, 'arm_ssgi_step')
@ -902,7 +904,6 @@ class ArmRenderPathPanel(bpy.types.Panel):
col = self.column(box, enabled=(rpdat.rp_ssr))
row = self.row(col, align=True)
self.prop(row, rpdat, 'arm_ssr_half_res')
self.prop(row, rpdat, 'rp_ssr_z_only')
row = self.row(col, align=True, alignment='EXPAND')
self.prop(row, rpdat, 'arm_ssr_ray_step')
self.prop(row, rpdat, 'arm_ssr_min_ray_step')

View File

@ -484,11 +484,9 @@ const vec3 seaWaterColor = vec3(""" + str(round(rpdat.arm_ocean_water_color[0] *
const float seaFade = """ + str(round(rpdat.arm_ocean_fade * 100) / 100) + """;
""")
if rpdat.rp_ssgi == 'SSAO' or rpdat.rp_volumetriclight:
scale = 0.5 if rpdat.arm_ssao_half_res else 1.0
f.write(
"""const float ssaoSize = """ + str(round((rpdat.arm_ssgi_step / 32) * 100) / 100) + """;
const float ssaoStrength = """ + str(round((rpdat.arm_ssgi_strength / 2) * 100) / 100) + """;
const float ssaoTextureScale = """ + str(scale) + """;
""")
if rpdat.rp_ssgi == 'RTGI' or rpdat.rp_ssgi == 'RTAO':
f.write(