Added lighting to SSAO example. small changes and fixes

This commit is contained in:
saschawillems 2016-10-29 13:18:20 +02:00
parent 9212a9e3cb
commit 06369fc72e
11 changed files with 40 additions and 25 deletions

View file

@ -9,11 +9,10 @@ layout (location = 0) in vec2 inUV;
layout (location = 0) out float outFragColor;
const int blurSize = 4;
void main()
{
const int blurRange = 2;
int n = 0;
vec2 texelSize = 1.0 / vec2(textureSize(samplerSSAO, 0));
float result = 0.0;
for (int x = -blurRange; x < blurRange; x++)
@ -22,7 +21,8 @@ void main()
{
vec2 offset = vec2(float(x), float(y)) * texelSize;
result += texture(samplerSSAO, inUV + offset).r;
n++;
}
}
outFragColor = result / (blurRange * blurRange * blurRange * blurRange);
outFragColor = result / (float(n));
}

Binary file not shown.

View file

@ -23,12 +23,14 @@ layout (location = 0) out vec4 outFragColor;
void main()
{
vec3 fragPos = texture(samplerposition, inUV).rgb;
vec3 normal = texture(samplerNormal, inUV).rgb;
vec3 normal = normalize(texture(samplerNormal, inUV).rgb * 2.0 - 1.0);
vec4 albedo = texture(samplerAlbedo, inUV);
float ssao = (uboParams.ssaoBlur == 1) ? texture(samplerSSAOBlur, inUV).r : texture(samplerSSAO, inUV).r;
outFragColor = vec4(vec3(0.0), 1.0);
vec3 lightPos = vec3(0.0);
vec3 L = normalize(lightPos - fragPos);
float NdotL = max(0.5, dot(normal, L));
if (uboParams.ssaoOnly == 1)
{
@ -36,16 +38,18 @@ void main()
}
else
{
vec3 baseColor = albedo.rgb * NdotL;
if (uboParams.ssao == 1)
{
outFragColor.rgb = ssao.rrr;
if (uboParams.ssaoOnly != 1)
outFragColor.rgb *= albedo.rgb;
outFragColor.rgb *= baseColor;
}
else
{
outFragColor.rgb = albedo.rgb;
outFragColor.rgb = baseColor;
}
}
}

View file

@ -13,7 +13,7 @@ layout (location = 1) out vec4 outNormal;
layout (location = 2) out vec4 outAlbedo;
const float NEAR_PLANE = 0.1f; //todo: specialization const
const float FAR_PLANE = 50.0f; //todo: specialization const
const float FAR_PLANE = 64.0f; //todo: specialization const
float linearDepth(float depth)
{

Binary file not shown.

View file

@ -23,18 +23,19 @@ layout (location = 0) out float outFragColor;
// todo: specialization const
const int kernelSize = 64;
const float radius = 1.0;
const float radius = 0.5;
void main()
{
// Get G-Buffer values
vec3 fragPos = texture(samplerPositionDepth, inUV).rgb;
vec3 normal = normalize(texture(samplerNormal, inUV).rgb) * 2.0 - 1.0f;
vec3 normal = normalize(texture(samplerNormal, inUV).rgb * 2.0 - 1.0);
// Get a random vector using a noise lookup
ivec2 texDim = textureSize(samplerPositionDepth, 0);
const vec2 noiseUV = vec2(float(texDim.x)/4.0f, float(texDim.y)/4.0f) * inUV;
vec3 randomVec = texture(ssaoNoise, noiseUV).xyz * 2.0 - 1.0;
ivec2 noiseDim = textureSize(ssaoNoise, 0);
const vec2 noiseUV = vec2(float(texDim.x)/float(noiseDim.x), float(texDim.y)/(noiseDim.y)) * inUV;
vec3 randomVec = texture(ssaoNoise, noiseUV).xyz;
// Create TBN matrix
vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));

Binary file not shown.