Remove the need for full screen texture copy for ssao

This commit is contained in:
mcrcortex
2024-02-23 01:50:03 +10:00
parent 1e793630e7
commit b961705ea3
3 changed files with 43 additions and 44 deletions

View File

@@ -2,9 +2,9 @@
layout(local_size_x = 32, local_size_y = 32) in;
layout(binding = 0, rgba8) uniform restrict image2D colourTex;
layout(binding = 0, rgba8) uniform writeonly restrict image2D colourTexOut;
layout(binding = 1) uniform sampler2D depthTex;
layout(binding = 2) uniform sampler2D colourTexCpy;
layout(binding = 2) uniform sampler2D colourTex;
layout(location = 3) uniform mat4 MVP;
layout(location = 4) uniform mat4 invMVP;
@@ -23,7 +23,7 @@ vec4 reDeProject(vec3 pos) {
if (depth == 1.0f) {
return vec4(-1.0f);
}
uint meta = uint(255.0f*texture(colourTexCpy, UV).w);
uint meta = uint(255.0f*texture(colourTex, UV).w);
if ((meta>>6)==0) {
return vec4(-1.0f);
}
@@ -44,35 +44,38 @@ float computeAOAngle(vec3 pos, float testHeight, vec3 normal) {
}
void main() {
ivec2 size = imageSize(colourTex);//TODO: dont use imageSize as it is slow, swap for uniform
vec2 point = vec2(gl_GlobalInvocationID.xy)/size;
float depth = texture(depthTex, point).r;
if (depth == 1.0f || any(lessThanEqual(size, gl_GlobalInvocationID.xy))) {
ivec2 size = imageSize(colourTexOut);//TODO: dont use imageSize as it is slow, swap for uniform
if (any(lessThanEqual(size, gl_GlobalInvocationID.xy))) {
return;
}
vec4 colour = imageLoad(colourTex, ivec2(gl_GlobalInvocationID.xy));
uint metadata = uint(colour.w*255.0f);
uint face = metadata&7u;
uint lod = (metadata>>3)&7u;
bool hasAO = (metadata>>6)!=0;
vec3 pos = rev3d(vec3(point, depth));
vec2 point = vec2(gl_GlobalInvocationID.xy)/size;
float depth = texture(depthTex, point).r;
vec4 ocolour = vec4(0);
if (depth < 1.0f) {
vec4 colour = texture(colourTex, point);
uint metadata = uint(colour.w*255.0f);
uint face = metadata&7u;
uint lod = (metadata>>3)&7u;
bool hasAO = (metadata>>6)!=0;
vec3 pos = rev3d(vec3(point, depth));
//TODO: TODO: only encode the axis, then use then it as as a mask along with pos and multiply by the -sign of everything
vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (float(int(face)&1)*2-1);
//vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (-sign(pos));
//TODO: TODO: only encode the axis, then use then it as as a mask along with pos and multiply by the -sign of everything
vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (float(int(face)&1)*2-1);
//vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (-sign(pos));
float d = 0.0;
if (hasAO) {
d = computeAOAngle(pos, 1.0*(1<<lod), viewNormal);//1
if (d<0.1) {
d = 0.0f;
float d = 0.0;
if (hasAO) {
d = computeAOAngle(pos, 1.0*(1<<lod), viewNormal);//1
if (d<0.1) {
d = 0.0f;
}
}
}
vec4 ocolour = colour;
ocolour.xyz *= ((1.0f-d)/3.0f+(2.0f/3.0f));
ocolour.w = 1.0f;
imageStore(colourTex, ivec2(gl_GlobalInvocationID.xy), ocolour);
ocolour = colour;
ocolour.xyz *= ((1.0f-d)/3.0f+(2.0f/3.0f));
ocolour.w = 1.0f;
}
imageStore(colourTexOut, ivec2(gl_GlobalInvocationID.xy), ocolour);
}
//vec4 ocolour = vec4(max(0, d), abs(min(0,d)), 0, 1);
//vec4 ocolour = vec4(repro-(viewNormal/2), 1);