Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualbearsomg

Posted 29 May 2013 - 04:23 PM

I've been working on adding SSAO support to my Direct3D10 program, but I'm a bit confused when it comes to using the normal and depth maps to build the occlusion buffer, which is then blended with the scene. From my understanding, this is the process:

 

(Pass 1): Generate the normal and depth maps (I use one pass and put the normal in RGB and the depth in A)

(Pass 2): Generate the AO map using the view space normal/depth map

(Pass 3): Render the actual scene using the occlusion factor from the AO map generated in pass 2

 

I'm confused when it comes to pass 2. I'm attempting to follow the tutorial here: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753 but I got confused with how to implement the shader. Namely, where does the

float2 uv
 

parameter come from in the pixel shader, and how is it calculated?

 

This is my shader for creating the normal/depth map:

 

 

//Vertex Input
struct VS_INPUT_SKIN
{
     float4 position : POSITION;
     float3 normal    : NORMAL;
     float2 tex0    : TEXCOORD;
     float3 boneLinks : BONELINKS;    
};
struct SSAO_PS_INPUT
{
    float4 pos : SV_POSITION;
    float3 normal : TEXCOORD0;
    float depth : TEXCOORD1;
};
SSAO_PS_INPUT vs_SSAO(VS_INPUT_SKIN IN)
{
    SSAO_PS_INPUT OUT;

    float4 skinnedPos = skinVert(IN.position, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);
    float3 skinnedNormal = skinNorm(IN.normal, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);

    float4 worldPos = mul(skinnedPos, worldMatrix);

    OUT.pos = mul(worldPos, viewMatrix);
    OUT.pos = mul(OUT.pos, projMatrix);

    OUT.normal = mul(skinnedNormal, worldMatrix);
    OUT.normal = mul(OUT.normal, viewMatrix);
    OUT.normal = normalize(OUT.normal);

    OUT.depth = mul(worldPos, viewMatrix).z;

    return OUT;
}
float4 ps_SSAO(SSAO_PS_INPUT IN) : SV_Target
{
    return float4(IN.normal,IN.depth);
}
technique10 SSAO_T
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, vs_SSAO() ) );
        SetPixelShader( CompileShader( ps_4_0, ps_SSAO() ) );
        SetGeometryShader( NULL );
    }
}

 

Basically, I'm confused as how to execute pass 2 using my generated map.


#2bearsomg

Posted 29 May 2013 - 03:49 PM

I've been working on adding SSAO support to my Direct3D10 program, but I'm a bit confused when it comes to using the normal and depth maps to build the occlusion buffer, which is then blended with the scene. From my understanding, this is the process:

 

(Pass 1): Generate the normal and depth maps (I use one pass and put the normal in RGB and the depth in A)

(Pass 2): Generate the AO map using the view space normal/depth map

(Pass 3): Render the actual scene using the occlusion factor from the AO map generated in pass 2

 

I'm confused when it comes to pass 2. I'm attempting to follow the tutorial here: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753 but I got confused with how to implement the shader. Namely, where does the

float2 uv
 

parameter come from in the pixel shader, and how is it calculated?

 

This is my shader for creating the normal/depth map:

 

 

//Vertex Input
struct VS_INPUT_SKIN
{
     float4 position : POSITION;
     float3 normal    : NORMAL;
     float2 tex0    : TEXCOORD;
     float3 boneLinks : BONELINKS;    
};
struct SSAO_PS_INPUT
{
    float4 pos : SV_POSITION;
    float3 normal : TEXCOORD0;
    float depth : TEXCOORD1;
};
SSAO_PS_INPUT vs_SSAO(VS_INPUT_SKIN IN)
{
    SSAO_PS_INPUT OUT;

    float4 skinnedPos = skinVert(IN.position, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);
    float3 skinnedNormal = skinNorm(IN.normal, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);

    float4 worldPos = mul(skinnedPos, worldMatrix);

    OUT.pos = mul(worldPos, viewMatrix);
    OUT.pos = mul(OUT.pos, projMatrix);

    OUT.normal = mul(skinnedNormal, worldMatrix);
    OUT.normal = mul(OUT.normal, viewMatrix);
    OUT.normal = normalize(OUT.normal);

    OUT.depth = mul(worldPos, viewMatrix).z;

    return OUT;
}
float4 ps_SSAO(SSAO_PS_INPUT IN) : SV_Target
{
    return float4(IN.normal,IN.depth);
}
technique10 SSAO_T
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, vs_SSAO() ) );
        SetPixelShader( CompileShader( ps_4_0, ps_SSAO() ) );
        SetGeometryShader( NULL );
    }
}

 

Basically, I'm confused as how to execute pass 2 using my generated map.


#1bearsomg

Posted 29 May 2013 - 03:47 PM

I've been working on adding SSAO support to my Direct3D10 program, but I'm a bit confused when it comes to using the normal and depth maps to build the occlusion buffer, which is then blended with the scene. From my understanding, this is the process:

 

(Pass 1): Generate the normal and depth maps (I use one pass and put the normal in RGB and the depth in A)

(Pass 2): Generate the AO map using the view space normal/depth map

(Pass 3): Render the actual scene using the occlusion factor from the AO map generated in pass 2

 

I'm confused when it comes to pass 2. I'm attempting to follow the tutorial here: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753 but I got confused with how to implement the shader. Namely, where does the

float2 uv
 

parameter come from in the pixel shader, and how is it calculated?

 

This is my shader for creating the normal/depth map:

 

 

//Vertex Input
struct VS_INPUT_SKIN
{
     float4 position : POSITION;
     float3 normal    : NORMAL;
     float2 tex0    : TEXCOORD;
     float3 boneLinks : BONELINKS;    
};
struct SSAO_PS_INPUT
{
    float4 pos : SV_POSITION;
    float3 normal : TEXCOORD0;
    float depth : TEXCOORD1;
};
SSAO_PS_INPUT vs_SSAO(VS_INPUT_SKIN IN)
{
    SSAO_PS_INPUT OUT;

    float4 skinnedPos = skinVert(IN.position, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);
    float3 skinnedNormal = skinNorm(IN.normal, IN.boneLinks[2], MatrixPalette[IN.boneLinks[0]], MatrixPalette[IN.boneLinks[1]]);

    float4 worldPos = mul(skinnedPos, worldMatrix);

    OUT.pos = mul(worldPos, viewMatrix);
    OUT.pos = mul(OUT.pos, projMatrix);

    OUT.normal = mul(skinnedNormal, worldMatrix);
    OUT.normal = mul(OUT.normal, viewMatrix);
    OUT.normal = normalize(OUT.normal);

    OUT.depth = mul(worldPos, viewMatrix).z;

    return OUT;
}
float4 ps_SSAO(SSAO_PS_INPUT IN) : SV_Target
{
    return float4(normedNorms,IN.depth);
}
technique10 SSAO_T
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, vs_SSAO() ) );
        SetPixelShader( CompileShader( ps_4_0, ps_SSAO() ) );
        SetGeometryShader( NULL );
    }
}

 

Basically, I'm confused as how to execute pass 2 using my generated map.

 


PARTNERS