I currently have a working scene in LWJGL that renders a bunch of voxels. I'm using a VBO with all the verticies, normals, and colors of the geometry and glDrawArrays() that to the screen.
I've search all over google for how to render my scene with SSAO, or Screen-Space Ambient Occlusion. Almost all the results that I find are just detailing the GLSL code that I would need, but completely leaves out the required lwjgl code.
This is one of the Fragment shader's I found for SSAO (I don't remember who the author was, or if the person who posted it was even the original author)
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform vec2 camerarange;
uniform vec2 screensize;
varying vec2 texCoord;
float readDepth( in vec2 coord ) {
return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture0, coord ).x * (camerarange.y - camerarange.x));
}
void main(void)
{
float depth = readDepth( texCoord );
float d;
float pw = 1.0 / screensize.x;
float ph = 1.0 / screensize.y;
float aoCap = 1.0;
float ao = 0.0;
float aoMultiplier=1000.0;
float depthTolerance = 0.0001;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
ao/=16.0;
gl_FragColor = vec4(1.0-ao) * texture2D(texture1,texCoord);
}
My question is, what do I have to do in my LWJGL space to pass along the variables for
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform vec2 camerarange;
uniform vec2 screensize;
If texture0 is the depth buffer in a 2d texture format, how would I create that?
Would I need to render my geometry VBO to the screen and then get the depth buffer texture thing?
And what is texture1? My program only uses colors and not textures so I have no idea what that could be.