1
\$\begingroup\$

I'm using dx11 and I'm working on SSAO. I am having wierd results, so I tried debugging it using RenderDoc and stepping through the pixel shader log, all the values of the static array seems to default to 0-vector. For example, look at r3-register in the following screenshot.

enter image description here

Here's the pixel shader I'm using. The global static variable that seems to be all null despite my initialization is the gSSAOKernel. Why is this? Isn't this correct?

#ifndef SSAO_PIXEL_HLSL
#define SSAO_PIXEL_HLSL

#include "Constants.h"
#include "Common.hlsl"

static const float gKernelSize = 16.0;
static const float gRadius = 1.5;
static const float gSSAOPower = 2.0;
static const float3 gSSAOKernel[gKernelSize] =
{
    float3(-0.0780436, 0.0558389, 0.0281286),
    float3(0.034318, -0.0635879, 0.0741237),
    float3(0.00230821, 0.0807279, 0.0805477),
    float3(0.0124638, 0.117585, 0.0578601),
    float3(0.093943, -0.0944602, 0.0816459),
    float3(0.139348, -0.109816, 0.0618508),
    float3(-0.181872, -0.129649, 0.0380075),
    float3(0.240066, -0.0494057, 0.118559),
    float3(0.115965, -0.0374714, 0.301286),
    float3(-0.294819, -0.100726, 0.225789),
    float3(-0.149652, 0.37459, 0.202967),
    float3(0.261695, -0.292813, 0.349015),
    float3(-0.37944, -0.425145, 0.206921),
    float3(0.628994, -0.189387, 0.224343),
    float3(-0.331257, -0.646864, 0.307335),
    float3(-0.467004, 0.439687, 0.618459),
};


cbuffer SSAOCBuffer : register(CBUFFER_REGISTER_PIXEL)
{
    float4x4 gViewProjMatrix;
    float4x4 gProjMatrix;
    float2 gScreenSize;
};

Texture2D gPositionTexture : register(TEXTURE_REGISTER_POSITION);
Texture2D gNormalTexture : register(TEXTURE_REGISTER_NORMAL);
Texture2D gNoiseTexture : register(TEXTURE_REGISTER_DIFFUSE);
Texture2D gDepthTexture : register(TEXTURE_REGISTER_DEPTH);
SamplerState gPointSampler : register(SAMPLER_REGISTER_POINT);

float linearizeDepth(in float depth, in float4x4 projMatrix) {
    return projMatrix[3][2] / (depth - projMatrix[2][2]);
}

float4 ssao(in float3x3 kernelBasis, in float3 originPos)
{
    float occlusion = 0.0;
    for (int i = 0; i < gKernelSize; i++)
    {
        float3 samplePos = mul(kernelBasis, gSSAOKernel[i]);   <---------------------- this line
        samplePos *= gRadius * originPos;

        float4 offset = mul(gViewProjMatrix, float4(samplePos, 1.0));
        offset.xy /= offset.w;
        offset.xy = offset.xy * 0.5 + 0.5;

        float depth = gDepthTexture.Sample(gPointSampler, offset.xy).r;
        depth = linearizeDepth(depth, gProjMatrix);

        float rangeCheck = abs(originPos.z - depth) < gRadius ? 1.0 : 0.0;
        occlusion += (depth <= samplePos.z ? 1.0 : 0.0) * rangeCheck;

    }
    occlusion = 1.0 - (occlusion / float(gKernelSize));

    return pow(occlusion, gSSAOPower);
}

float4 ps_main(float4 position : SV_Position) : SV_Target0
{
    float2 coords = float2(1920.0, 1080.0) / float2(4.0, 4.0);
    coords *= float2(position.x / gScreenSize.x, position.y / gScreenSize.y);

    float3 originPos = gPositionTexture[uint2(position.xy)].xyz;
    float3 normal = gNormalTexture[uint2(position.xy)].xyz;

    float3 rvec = gNoiseTexture.Sample(gPointSampler, coords).xyz; //texture(uNoiseTex, noiseTexCoords).rgb * 2.0 - 1.0;
    float3 tangent = normalize(rvec - normal * dot(rvec, normal));
    float3 bitangent = cross(tangent, normal);
    float3x3 kernelBasis = CreateMatrixFromCols(tangent, bitangent, normal);

    return ssao(kernelBasis, originPos);// gFinalTexture.Sample(gPointSampler, coords);//float4(1.0, 0.0, 1.0, 1.0);
}

#endif

Also - offtopic, but this pixelshader murders my framerate, all the way from solid 450+ to 80-90. I guess with all the texture lookups the technique is simply expensive, but still, I must be doing something wrong in regard to performance.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

This is my fault - the 0 values are caused by a bug in RenderDoc v0.20 - the x0[] indexable temp register being used there which contains your kernel data wasn't implemented in the shader debugging at the time of that release - I implemented it a few months ago. I'm hoping to get v0.21 with all the latest fixes out this week-ish.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Oh ok, that was unexpected. Thanks and btw awesome debugging software. \$\endgroup\$ Sep 22, 2014 at 11:10

You must log in to answer this question.

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