3
\$\begingroup\$

I'm trying to implement depth-only SSAO and for that, I render a depth map into a texture and pass it to my SSAO shader which then uses it.

The problem is that when I try to output the depth map values from SSAO fragment shader (for testing purpose), I get something really weird.

Here is the result :

depth_map_from_ssao

And, here is how it normally looks rendered before giving it to the SSAO shader :

depth_map

The depth buffer seems OK, so I guess it comes from a transformation done in the SSAO shader.

Here are the shaders (I'm using the bgfx library, but the shader language is very similar to GLSL):

Here is the way I output the depth from my SSAO for testing :

//Vertex Shader
$input a_position, a_texcoord0
$output v_texcoord0

#include "../common/common.sh"

void main()
{
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
    v_texcoord0 = a_texcoord0;
}

//Fragment Shader
$input v_texcoord0

#include "../common/common.sh"

SAMPLER2D(s_depth, 0);

float readDepth( in vec2 coord )
{
#if BGFX_SHADER_LANGUAGE_HLSL
    float z = texture2D( s_depth, coord );
#else
    float z = texture2D( s_depth, coord ) * 2.0 - 1.0;
#endif // BGFX_SHADER_LANGUAGE_HLSL

    return z;   
}

void main()
{
    float depth = readDepth( v_texcoord0 );
    ...
    //Some computation
    ...
    gl_FragColor = vec4(vec3_splat(depth), 1);
}

And here the shader for storing the depth into a texture :

//Vertex Shader
$input a_position
#include "../common/common.sh"

void main()
{
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
}

//Fragment Shader

void main()
{
    gl_FragColor = gl_FragCoord.z/gl_FragCoord.w;
}

My guess is that I may be projecting the depth texture in a wrong way.

Thanks in advance for any help.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I found that replacing v_texcoord0 with gl_FragCoord.xy / vec2(screen_width, screen_height) in the SSAO shader, solved this issue.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .