Fixed side facing "AO"/lighting/shading, fix slight race condition in clearing data
This commit is contained in:
@@ -117,7 +117,7 @@ public abstract class AbstractFarWorldRenderer <T extends Viewport> {
|
||||
var update = this.blockStateUpdates.pop();
|
||||
this.models.addEntry(update.id, update.state);
|
||||
}
|
||||
//this.models.bakery.renderFaces(Blocks.LAVA.getDefaultState(), 1234, true);
|
||||
//this.models.bakery.renderFaces(Blocks.ROSE_BUSH.getDefaultState(), 1234, false);
|
||||
}
|
||||
|
||||
//TODO: fix this in a better way than this ungodly hacky stuff
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11C;
|
||||
|
||||
import static org.lwjgl.opengl.ARBComputeShader.glDispatchCompute;
|
||||
import static org.lwjgl.opengl.ARBCopyImage.glCopyImageSubData;
|
||||
import static org.lwjgl.opengl.ARBFramebufferObject.*;
|
||||
import static org.lwjgl.opengl.ARBShaderImageLoadStore.glBindImageTexture;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
@@ -24,12 +25,14 @@ import static org.lwjgl.opengl.GL30C.GL_R32F;
|
||||
import static org.lwjgl.opengl.GL43.GL_DEPTH_STENCIL_TEXTURE_MODE;
|
||||
import static org.lwjgl.opengl.GL44C.glBindImageTextures;
|
||||
import static org.lwjgl.opengl.GL45C.glBlitNamedFramebuffer;
|
||||
import static org.lwjgl.opengl.GL45C.glCopyTextureSubImage2D;
|
||||
|
||||
public class PostProcessing {
|
||||
private final GlFramebuffer framebuffer;
|
||||
private int width;
|
||||
private int height;
|
||||
private GlTexture colour;
|
||||
private GlTexture colourCopy;
|
||||
private GlTexture depthStencil;
|
||||
|
||||
private final FullscreenBlit emptyBlit = new FullscreenBlit("voxy:post/noop.frag");
|
||||
@@ -43,6 +46,7 @@ public class PostProcessing {
|
||||
.addCapability(GL_DEPTH_TEST)
|
||||
.addTexture(GL_TEXTURE0)
|
||||
.addTexture(GL_TEXTURE1)
|
||||
.addTexture(GL_TEXTURE2)
|
||||
.build();
|
||||
|
||||
public PostProcessing() {
|
||||
@@ -54,11 +58,15 @@ public class PostProcessing {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
if (this.colour != null) {
|
||||
if (this.colourCopy != null) {
|
||||
this.colourCopy.free();
|
||||
}
|
||||
this.colour.free();
|
||||
this.depthStencil.free();
|
||||
}
|
||||
|
||||
this.colour = new GlTexture().store(GL_RGBA8, 1, width, height);
|
||||
this.colourCopy = new GlTexture().store(GL_RGBA8, 1, width, height);
|
||||
this.depthStencil = new GlTexture().store(GL_DEPTH24_STENCIL8, 1, width, height);
|
||||
|
||||
this.framebuffer.bind(GL_COLOR_ATTACHMENT0, this.colour);
|
||||
@@ -71,6 +79,7 @@ public class PostProcessing {
|
||||
|
||||
public void shutdown() {
|
||||
this.framebuffer.free();
|
||||
if (this.colourCopy != null) this.colourCopy.free();
|
||||
if (this.colour != null) this.colour.free();
|
||||
if (this.depthStencil != null) this.depthStencil.free();
|
||||
this.emptyBlit.delete();
|
||||
@@ -115,20 +124,26 @@ public class PostProcessing {
|
||||
//Computes ssao on the current framebuffer data and updates it
|
||||
// this means that translucency wont be effected etc
|
||||
public void computeSSAO(Matrix4f projection, MatrixStack stack) {
|
||||
glCopyImageSubData(this.colour.id, GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
this.colourCopy.id, GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
this.width, this.height, 1);
|
||||
|
||||
this.ssaoComp.bind();
|
||||
float[] data = new float[4*4];
|
||||
var mat = new Matrix4f(projection).mul(stack.peek().getPositionMatrix());
|
||||
mat.get(data);
|
||||
glUniformMatrix4fv(2, false, data);//MVP
|
||||
glUniformMatrix4fv(3, false, data);//MVP
|
||||
mat.invert();
|
||||
mat.get(data);
|
||||
glUniformMatrix4fv(3, false, data);//invMVP
|
||||
glUniformMatrix4fv(4, false, data);//invMVP
|
||||
|
||||
glBindImageTexture(0, this.colour.id, 0, false,0, GL_READ_WRITE, GL_RGBA8);
|
||||
//glBindImageTexture(1, this.depthStencil.id, 0, false,0, GL_READ_ONLY, GL_R32F);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
GL11C.glBindTexture(GL_TEXTURE_2D, this.depthStencil.id);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
GL11C.glBindTexture(GL_TEXTURE_2D, this.colourCopy.id);
|
||||
|
||||
glDispatchCompute((this.width+31)/32, (this.height+31)/32, 1);
|
||||
}
|
||||
|
||||
@@ -57,16 +57,16 @@ public class ActiveSectionTracker {
|
||||
System.err.println("Unable to load section " + section.key + " setting to air");
|
||||
status = 1;
|
||||
}
|
||||
if (status == 1) {
|
||||
//We need to set the data to air as it is undefined state
|
||||
Arrays.fill(section.data, Mapper.AIR);
|
||||
}
|
||||
section.acquire();
|
||||
holder.obj = section;
|
||||
if (nullOnEmpty && status == 1) {//If its air return null as stated, release the section aswell
|
||||
section.release();
|
||||
return null;
|
||||
}
|
||||
if (status == 1) {
|
||||
//We need to set the data to air as it is undefined state
|
||||
Arrays.fill(section.data, Mapper.AIR);
|
||||
}
|
||||
return section;
|
||||
} else {
|
||||
WorldSection section = null;
|
||||
|
||||
@@ -49,7 +49,8 @@ void main() {
|
||||
uint modelId = extractStateId(quad);
|
||||
BlockModel model = modelData[modelId];
|
||||
uint faceData = model.faceData[face];
|
||||
|
||||
bool hasAO = modelHasMipmaps(model);//TODO: replace with per face AO flag
|
||||
bool isShaded = hasAO;//TODO: make this a per face flag
|
||||
//Change the ordering due to backface culling
|
||||
//NOTE: when rendering, backface culling is disabled as we simply dispatch calls for each face
|
||||
// this has the advantage of having "unassigned" geometry, that is geometry where the backface isnt culled
|
||||
@@ -120,16 +121,21 @@ void main() {
|
||||
uint encodedData = 0;
|
||||
encodedData |= face;
|
||||
encodedData |= (lodLevel<<3);
|
||||
encodedData |= uint(modelHasMipmaps(model))<<6;//TODO: add if the face has AO as a face property instead of just using if it has mipmaps
|
||||
encodedData |= uint(hasAO)<<6;
|
||||
addin.w = float(encodedData)/255.0;
|
||||
}
|
||||
|
||||
//Apply face tint
|
||||
if ((face>>1) == 0) {
|
||||
tinting.xyz *= 1.0;
|
||||
} else if ((face>>1) == 1) {
|
||||
tinting.xyz *= 0.8;
|
||||
} else {
|
||||
tinting.xyz *= 0.6;
|
||||
if (isShaded) {
|
||||
if ((face>>1) == 1) {
|
||||
tinting.xyz *= 0.8f;
|
||||
} else if ((face>>1) == 2) {
|
||||
tinting.xyz *= 0.6f;
|
||||
} else if (face == 0){
|
||||
tinting.xyz *= 0.5f;
|
||||
} else {
|
||||
//TODO: FIXME: DONT HAVE SOME ARBITARY TINT LIKE THIS
|
||||
tinting.xyz *= 0.95f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ layout(local_size_x = 32, local_size_y = 32) 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;
|
||||
layout(binding = 2) uniform sampler2D colourTexCpy;
|
||||
layout(location = 3) uniform mat4 MVP;
|
||||
layout(location = 4) uniform mat4 invMVP;
|
||||
|
||||
vec3 rev3d(vec3 clip) {
|
||||
vec4 view = invMVP * vec4(clip*2.0-1.0,1.0);
|
||||
@@ -22,6 +23,10 @@ vec4 reDeProject(vec3 pos) {
|
||||
if (depth == 1.0f) {
|
||||
return vec4(-1.0f);
|
||||
}
|
||||
uint meta = uint(255.0f*texture(colourTexCpy, UV).w);
|
||||
if ((meta>>6)==0) {
|
||||
return vec4(-1.0f);
|
||||
}
|
||||
view.z = depth*2.0-1.0;
|
||||
view.w = 1.0;
|
||||
view = invMVP * view;
|
||||
|
||||
Reference in New Issue
Block a user