fix SSAO rendering
This commit is contained in:
-1
@@ -48,7 +48,6 @@ public class SSAOShader extends AbstractShaderRenderer
|
||||
(float) ((RenderUtil.getFarClipPlaneDistanceInBlocks() + LodUtil.REGION_WIDTH) * Math.sqrt(2)));
|
||||
|
||||
this.shader.setUniform(this.shader.getUniformLocation("gProj"), perspective);
|
||||
this.shader.setUniform(this.shader.getUniformLocation("gProjInv"), perspective.invert());
|
||||
this.shader.setUniform(this.shader.getUniformLocation("gSampleRad"), 3.0f);
|
||||
this.shader.setUniform(this.shader.getUniformLocation("gFactor"), 0.8f);
|
||||
this.shader.setUniform(this.shader.getUniformLocation("gPower"), 1.0f);
|
||||
|
||||
@@ -80,8 +80,7 @@ void main()
|
||||
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// we only want to apply Fog to LODs, not to the sky outside the LODs
|
||||
// FIXME: This bit of code causes problems on intel integrated graphics
|
||||
if (fragmentDepth < 0.99999)
|
||||
if (fragmentDepth < 1)
|
||||
{
|
||||
if (fullFogMode == 0)
|
||||
{
|
||||
@@ -118,6 +117,11 @@ void main()
|
||||
fragColor = vec4(vec3(depthValue), 1.0); // Convert depth value to grayscale color
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// every pixel needs to be set to something, otherwise the pixel may be undefined by some drivers (specifically Intel)
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ uniform float gSampleRad;
|
||||
uniform float gFactor;
|
||||
uniform float gPower;
|
||||
uniform mat4 gProj;
|
||||
uniform mat4 gProjInv;
|
||||
|
||||
const int MAX_KERNEL_SIZE = 32;
|
||||
const float INV_MAX_KERNEL_SIZE_F = 1.0 / float(MAX_KERNEL_SIZE);
|
||||
@@ -18,17 +17,23 @@ uniform vec3 gKernel[MAX_KERNEL_SIZE];
|
||||
|
||||
vec3 calcViewPosition(vec2 coords) {
|
||||
float fragmentDepth = texture(gDepthMap, coords).r;
|
||||
vec4 ndc = vec4(coords.xy, fragmentDepth, 1.0);
|
||||
ndc.xyz = ndc.xyz * 2.0 - 1.0;
|
||||
|
||||
vec4 vs_pos = gProjInv * ndc;
|
||||
return vs_pos.xyz / vs_pos.w;
|
||||
vec4 ndc = vec4(
|
||||
coords.x * 2.0 - 1.0,
|
||||
coords.y * 2.0 - 1.0,
|
||||
fragmentDepth * 2.0 - 1.0,
|
||||
1.0
|
||||
);
|
||||
|
||||
vec4 vs_pos = inverse(gProj) * ndc;
|
||||
vs_pos.xyz = vs_pos.xyz / vs_pos.w;
|
||||
return vs_pos.xyz;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 viewPos = calcViewPosition(TexCoord);
|
||||
vec3 viewNormal = normalize(cross(dFdx(viewPos.xyz), dFdy(viewPos.xyz)));
|
||||
vec3 viewNormal = normalize(cross(dFdy(viewPos.xyz), dFdx(viewPos.xyz)) * -1.0);
|
||||
|
||||
vec3 randomVec = vec3(0.0, -1.0, 0.0);
|
||||
|
||||
@@ -37,8 +42,10 @@ void main()
|
||||
mat3 TBN = mat3(tangent, bitangent, viewNormal);
|
||||
|
||||
float occlusion_factor = 0.0;
|
||||
for (int i = 0; i < MAX_KERNEL_SIZE; i++) {
|
||||
vec3 samplePos = TBN * gKernel[i] * gSampleRad;
|
||||
for (int i = 0; i < MAX_KERNEL_SIZE; i++)
|
||||
{
|
||||
vec3 samplePos = vec3(0.0) + (TBN * gKernel[i]);
|
||||
samplePos = viewPos + samplePos * gSampleRad;
|
||||
|
||||
vec4 offset = gProj * vec4(samplePos + viewPos, 1.0);
|
||||
offset.xy /= offset.w;
|
||||
|
||||
@@ -13,9 +13,13 @@ void main()
|
||||
float fragmentDepth = texture(gDepthMap, TexCoord).r;
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// we only want to apply SSAO to LODs, not to the sky outside the LODs
|
||||
if (fragmentDepth < 0.99999)
|
||||
if (fragmentDepth < 1)
|
||||
{
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
fragColor.a -= textureLod(gSSAOMap, TexCoord, 0).r;
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 1-texture(gSSAOMap, TexCoord).r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// every pixel needs to be set to something, otherwise the pixel may be undefined by some drivers (specifically Intel)
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user