SSAO WIP
This commit is contained in:
parent
54a36e1476
commit
5852c409e6
|
@ -81,6 +81,6 @@ void main()
|
|||
// store result into result image
|
||||
//imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(normalView, 1.0f));
|
||||
//imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f));
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(imageLoad(ssaoImage, globalThread).rgb, 1.0f));
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(imageLoad(ssaoImage, globalThread).rgba/*, 1.0f*/));
|
||||
|
||||
}
|
Binary file not shown.
|
@ -7,7 +7,7 @@ const int ROTATION_KERNEL_H = 4;
|
|||
|
||||
// can perhaps pass in as push constant.
|
||||
const float RADIUS = 0.5f;
|
||||
const float BIAS = 0.005f;
|
||||
const float BIAS = 0.025f;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
layout(set = 4, binding = 0, rgba32f) uniform image2D positions;
|
||||
|
@ -43,17 +43,17 @@ void main()
|
|||
// load all the necessary variables
|
||||
vec3 viewSpacePos = imageLoad (positions, globalThread).rgb;
|
||||
vec3 viewSpaceNormal = normalize (imageLoad (normals, globalThread).rgb);
|
||||
viewSpaceNormal = -viewSpaceNormal;
|
||||
//viewSpaceNormal = -viewSpaceNormal;
|
||||
|
||||
ivec2 noiseDim = textureSize(noiseTexture, 0);
|
||||
vec2 noiseDim = vec2 (textureSize(noiseTexture, 0));
|
||||
vec2 threadUV = (vec2(globalThread) + vec2 (0.5f)) / vec2(size);
|
||||
vec2 noiseUVMult = vec2 (float(size.x)/float(noiseDim.x), float(size.y) / float(noiseDim.y));
|
||||
vec2 noiseUVMult = vec2 ((vec2(size) / noiseDim);
|
||||
noiseUVMult *= threadUV;
|
||||
vec3 randomVec = texture(noiseTexture, noiseUVMult).rgb * 2.0f - 1.0f;
|
||||
vec3 randomVec = texture(noiseTexture, noiseUVMult).rgb;
|
||||
|
||||
// Gram schmidt
|
||||
vec3 tangent = normalize (randomVec - (viewSpaceNormal * dot(viewSpaceNormal, randomVec)));
|
||||
vec3 bitangent = cross (viewSpaceNormal, tangent);
|
||||
vec3 bitangent = normalize (cross (tangent, viewSpaceNormal));
|
||||
|
||||
// matrix for tangent to view
|
||||
mat3 TBN = mat3(tangent, bitangent, viewSpaceNormal);
|
||||
|
@ -75,16 +75,16 @@ void main()
|
|||
// and bring it from [-1, 1] to screen coordinates
|
||||
offsetPos.xyz = ((offsetPos.xyz * 0.5f) + 0.5f);
|
||||
offsetPos.xy *= vec2(size.xy);
|
||||
//offsetPos.y = size.y - offsetPos.y;
|
||||
|
||||
float sampleDepth = imageLoad (positions, ivec2 (offsetPos.xy)).z;
|
||||
|
||||
float rangeCheck = smoothstep (0.0f, 1.0f, RADIUS / abs (viewSpacePos.z - sampleDepth));
|
||||
occlusion += (sampleDepth >= samplePos.z + BIAS ? 1.0f : 0.0f) * rangeCheck;
|
||||
occlusion += (sampleDepth <= samplePos.z + BIAS ? 1.0f : 0.0f) * rangeCheck;
|
||||
//occlusion += (sampleDepth <= samplePos.z + BIAS ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
occlusion = 1.0f - (occlusion / float(NUM_SAMPLES));
|
||||
|
||||
// store result into result image
|
||||
imageStore(outputImage, ivec2(gl_GlobalInvocationID.xy), vec4(occlusion.rrr, 0.0f));
|
||||
imageStore(outputImage, globalThread, vec4(occlusion.rrr, 1.0f));
|
||||
}
|
Binary file not shown.
|
@ -19,6 +19,23 @@ namespace SHADE
|
|||
// generate samples
|
||||
for (uint32_t i = 0; i < NUM_SAMPLES; ++i)
|
||||
{
|
||||
//SHVec3 temp
|
||||
//{
|
||||
// distrib(generator) * 2.0f - 1.0f, // -1.0f - 1.0f
|
||||
// distrib(generator) * 2.0f - 1.0f, // -1.0f - 1.0f
|
||||
// distrib(generator), // 0.0f - 1.0f so that sample space is a hemisphere
|
||||
//};
|
||||
|
||||
//temp = SHVec3::Normalise(temp);
|
||||
//temp *= distrib(generator);
|
||||
|
||||
//// This makes sure that most points are closer to fragment's position
|
||||
//float scale = 1.0f / static_cast<float>(NUM_SAMPLES);
|
||||
//scale = std::lerp(0.1f, 1.0f, scale * scale);
|
||||
//temp *= scale;
|
||||
//samples[i] = SHVec4 (temp.x, temp.y, temp.z, 0.0f);
|
||||
|
||||
|
||||
samples[i] = SHVec4
|
||||
{
|
||||
distrib(generator) * 2.0f - 1.0f, // -1.0f - 1.0f
|
||||
|
|
Loading…
Reference in New Issue