SSAO works
This commit is contained in:
@@ -18,4 +18,8 @@ uint faceHasAlphaCuttoutOverride(uint faceData) {
|
||||
|
||||
bool modelHasBiomeLUT(BlockModel model) {
|
||||
return ((model.flagsA)&2) != 0;
|
||||
}
|
||||
|
||||
bool modelIsTranslucent(BlockModel model) {
|
||||
return ((model.flagsA)&4) != 0;
|
||||
}
|
||||
@@ -6,9 +6,9 @@ layout(early_fragment_tests) in;
|
||||
|
||||
flat in uint id;
|
||||
flat in uint value;
|
||||
//out vec4 colour;
|
||||
out vec4 colour;
|
||||
|
||||
void main() {
|
||||
visibilityData[id] = value;
|
||||
//colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1);
|
||||
colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1);
|
||||
}
|
||||
@@ -19,8 +19,7 @@ void main() {
|
||||
|
||||
//Transform ipos with respect to the vertex corner
|
||||
ivec3 pos = (((ipos<<detail)-baseSectionPos)<<5);
|
||||
pos += aabbOffset;
|
||||
pos -= (1<<detail);
|
||||
pos += (aabbOffset-1)*(1<<detail);
|
||||
pos += (ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1)*(size+2))*(1<<detail);
|
||||
|
||||
gl_Position = MVP * vec4(vec3(pos),1);
|
||||
|
||||
@@ -6,17 +6,17 @@ layout(binding = 0) uniform sampler2D blockModelAtlas;
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 1) in flat vec2 baseUV;
|
||||
layout(location = 2) in flat vec4 colourTinting;
|
||||
layout(location = 3) in flat uint discardAlpha;
|
||||
layout(location = 2) in flat vec4 tinting;
|
||||
layout(location = 3) in flat vec4 addin;
|
||||
layout(location = 4) in flat uint flags;
|
||||
|
||||
layout(location = 0) out vec4 outColour;
|
||||
void main() {
|
||||
vec2 uv = mod(uv, vec2(1))*(1f/(vec2(3,2)*256f));
|
||||
vec4 colour = texture(blockModelAtlas, uv + baseUV);
|
||||
if (discardAlpha == 1 && colour.a <= 0.25f) {
|
||||
if ((flags&1) == 1 && colour.a <= 0.25f) {
|
||||
discard;
|
||||
}
|
||||
outColour = colour * colourTinting;
|
||||
|
||||
outColour = (colour * tinting) + addin;
|
||||
//outColour = vec4(uv + baseUV, 0, 1);
|
||||
}
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
layout(location = 0) out vec2 uv;
|
||||
layout(location = 1) out flat vec2 baseUV;
|
||||
layout(location = 2) out flat vec4 colourTinting;
|
||||
layout(location = 3) out flat uint discardAlpha;
|
||||
layout(location = 2) out flat vec4 tinting;
|
||||
layout(location = 3) out flat vec4 addin;
|
||||
layout(location = 4) out flat uint discardAlpha;
|
||||
|
||||
uint extractLodLevel() {
|
||||
return uint(gl_BaseInstance)>>29;
|
||||
@@ -93,20 +94,25 @@ void main() {
|
||||
discardAlpha |= uint(any(greaterThan(quadSize, ivec2(1)))) & faceHasAlphaCuttoutOverride(faceData);
|
||||
|
||||
//Compute lighting
|
||||
colourTinting = getLighting(extractLightId(quad));
|
||||
tinting = getLighting(extractLightId(quad));
|
||||
|
||||
//Apply model colour tinting
|
||||
uint tintColour = model.colourTint;
|
||||
if (modelHasBiomeLUT(model)) {
|
||||
tintColour = colourData[tintColour + extractBiomeId(quad)];
|
||||
}
|
||||
colourTinting *= uint2vec4RGBA(tintColour).yzwx;
|
||||
tinting *= uint2vec4RGBA(tintColour).yzwx;
|
||||
addin = vec4(0);
|
||||
if (!modelIsTranslucent(model)) {
|
||||
tinting.w = 0;
|
||||
addin.w = float(face|(lodLevel<<3))/255;
|
||||
}
|
||||
|
||||
//Apply face tint
|
||||
if (face == 0) {
|
||||
colourTinting.xyz *= vec3(0.75, 0.75, 0.75);
|
||||
tinting.xyz *= vec3(0.75, 0.75, 0.75);
|
||||
} else if (face != 1) {
|
||||
colourTinting.xyz *= vec3((float(face-2)/4)*0.6 + 0.4);
|
||||
tinting.xyz *= vec3((float(face-2)/4)*0.7 + 0.3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#version 460
|
||||
#extension GL_NV_compute_shader_derivatives : require
|
||||
layout(local_size_x = 32, local_size_y = 32, local_size_x = 1) in;
|
||||
|
||||
|
||||
layout(binding = 0, rgba8) uniform restrict image2D colourTex;
|
||||
layout(binding = 1) uniform sampler2D depthTex;
|
||||
layout(location = 2) uniform mat4 MVP;
|
||||
layout(location = 3) uniform mat4 invMVP;
|
||||
|
||||
vec3 rev3d(vec3 clip) {
|
||||
vec4 view = invMVP * vec4(clip*2-1,1);
|
||||
return view.xyz/view.w;
|
||||
}
|
||||
|
||||
vec3 proj3dscreen(vec3 pos) {
|
||||
vec4 view = MVP * vec4(pos, 1);
|
||||
view.xyz /= view.w;
|
||||
return view.xyz * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 reDeProject(vec3 pos) {
|
||||
vec4 view = MVP * vec4(pos, 1);
|
||||
view.xy /= view.w;
|
||||
view.z = texture(depthTex, clamp(view.xy*0.5+0.5, 0, 1)).x*2-1;
|
||||
view.w = 1;
|
||||
view = invMVP * view;
|
||||
return view.xyz/view.w;
|
||||
}
|
||||
|
||||
vec3 reDeProjectContained(vec3 pos) {
|
||||
vec4 view = MVP * vec4(pos, 1);
|
||||
view.xy /= view.w;
|
||||
float depth = texture(depthTex, clamp(view.xy*0.5+0.5, 0, 1)).x*2-1;
|
||||
view.z = min(view.z, depth);
|
||||
view.w = 1;
|
||||
view = invMVP * view;
|
||||
return view.xyz/view.w;
|
||||
}
|
||||
|
||||
vec3 computeDifference(vec3 pos, vec3 offset) {
|
||||
return reDeProject(pos + offset) - pos - offset;
|
||||
}
|
||||
|
||||
float computeAngleDifference(vec3 pos, vec3 offset) {
|
||||
vec3 repro = reDeProject(pos + offset) - pos;
|
||||
return dot(repro, offset)/(length(repro) * length(offset));
|
||||
}
|
||||
|
||||
float computeAOAngle(vec3 pos, float testHeight, vec3 normal) {
|
||||
vec3 repro = reDeProject(pos + normal*testHeight) - pos;
|
||||
float len = length(repro);
|
||||
return dot(repro, normal)/len;
|
||||
}
|
||||
|
||||
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))) {
|
||||
return;
|
||||
}
|
||||
vec4 colour = imageLoad(colourTex, ivec2(gl_GlobalInvocationID.xy));
|
||||
uint metadata = uint(colour.w*255);
|
||||
uint face = metadata&7;
|
||||
uint lod = (metadata>>3)&7;
|
||||
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);//normalize(cross(dFdx(pos), dFdy(pos)));
|
||||
//vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (-sign(pos));//normalize(cross(dFdx(pos), dFdy(pos)));
|
||||
|
||||
|
||||
float d = computeAOAngle(pos, 0.75*(1<<lod), viewNormal);//1
|
||||
//if (any(lessThan(ivec3(4), abs(repro-offset)))) {// || all(lessThan(abs(repro-offset), ivec3(0.01)))
|
||||
//return;
|
||||
//}
|
||||
if (d<0.1) {
|
||||
return;
|
||||
}
|
||||
|
||||
//vec4 ocolour = vec4(max(0, d), abs(min(0,d)), 0, 1);
|
||||
//vec4 ocolour = vec4(repro-(viewNormal/2), 1);
|
||||
//vec4 ocolour = vec4(viewNormal/2+0.5, 1);
|
||||
vec4 ocolour = colour;
|
||||
ocolour.xyz *= ((1-d)/2+0.5);
|
||||
ocolour.w = 1;
|
||||
imageStore(colourTex, ivec2(gl_GlobalInvocationID.xy), ocolour);
|
||||
}
|
||||
Reference in New Issue
Block a user