Skip to content

Commit

Permalink
better random seed ssao
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-deliot committed Jan 10, 2018
1 parent e8ee4f0 commit aeaaac7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Camera : public Component
{
finalDeferred = read_program("m2tp/Shaders/finalDeferred.glsl");
finalDeferredSSR = read_program("m2tp/Shaders/finalDeferredSSR.glsl");
shaderSSAO = read_program("m2tp/Shaders/SSAO.glsl");
//shaderSSAO = read_program("m2tp/Shaders/SSAO.glsl");
SetParameters(frameWidth, frameHeight, fov, nearZ, farZ);
}

Expand Down
2 changes: 1 addition & 1 deletion Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Engine : public App
mainCamera->FinishDeferredRendering(mainLight, ambientLight, true);

// Draw post effects
mainCamera->DrawPostEffects();
//mainCamera->DrawPostEffects();

// Blit to screen
glBindFramebuffer(GL_READ_FRAMEBUFFER, mainCamera->GetFrameBuffer());
Expand Down
8 changes: 6 additions & 2 deletions Shaders/SSAO.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ void main()
vec3 vsNormal = mat3(viewMatrix) * worldNormal;
float z = texture(depthBuffer, vtexcoord).x;
if(z >= 0.9999f)
return temp;
{
finalColor = temp;
return;
}

vec4 clipSpacePosition = vec4(vtexcoord.xy * 2.0 - 1.0, z * 2.0 - 1.0, 1);
vec4 viewSpacePosition = invProj * clipSpacePosition;
viewSpacePosition /= viewSpacePosition.w;
vec3 vsPos = viewSpacePosition.xyz;

finalColor = vec4(temp.rgb * ComputeSSAOAtten(vsPos, vsNormal), temp.a);
//finalColor = vec4(temp.rgb * ComputeSSAOAtten(vsPos, vsNormal), temp.a);
finalColor = vec4(worldNormal.xyz, 1);
}


Expand Down
3 changes: 2 additions & 1 deletion Shaders/finalDeferredSSR.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ float ComputeSSAOAtten(vec3 vsPos, vec3 vsNormal)
vec3 sampleTangent = vec3(sin(angleTheta) * cos(anglePhi), sin(angleTheta) * sin(anglePhi), cos(angleTheta));
vec3 sampleVector = sampleTangent.x * rightDir + sampleTangent.y * upDir + sampleTangent.z * vsNormal;

vec2 seed = vec2(sampleVector.x + sampleTangent.z + vsNormal.y, sampleVector.z + sampleTangent.y + vsNormal.x);
vec2 seed = vec2(vsPos.y * vsPos.x + sampleVector.x + sampleTangent.z + vsNormal.y,
vsPos.z * vsPos.y + sampleVector.z + sampleTangent.y + vsNormal.x);
vec3 samplePos = vsPos + sampleVector * GetRandomNumberBetween(seed, 1.0, ssaoDist);
vec4 temp = projToPixel * vec4(samplePos, 1);
temp.xyz /= temp.w;
Expand Down

0 comments on commit aeaaac7

Please sign in to comment.