I tried rearranging my constant buffer like this:
cbuffer cCameraParams
{
float gfx_gCamProjA;
float gfx_gCamProjB;
float pad1;
float pad2;
}
But i'm still getting the same problem as before. Forcing gfx_gCamProjB in the second register seems to fix the problem.
I tried rarranging my cbuffer to this:
cbuffer cCameraParams
{
float gfx_gCamProjA;
float gfx_gCamProjB;
float3 pad;
}
Since variable pad won't fit in the first 16-byte register, variable pad's offset correctly aligned itself in the second register, 16 bytes, based on the ShaderReflection. So i don't think it has a problem with the 16-byte alignment.
Also calling constant buffer map and unmap method doesn't show any debug warnings. When i compile my shader i add the following shader flags:
#ifdef PSX_DEBUG flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_WARNINGS_ARE_ERRORS ; #endif
I'm beginning to think the Visual Studio graphics debugger tool isn't showing the values right. I'm following MJP's post on reconstructing view space position from depth. I compared the "right" and "wrong" constant buffer formats and both of them returned the same view space position values. Here's the shader code that's using the gfx_gCamProjA and gfx_gCamProjB values:
float3 GetPositionVS( in float2 screenTexCoord, in float3 viewRay )
{
// Sample the depth and convert to linear view space Z (assume it gets sampled as
// a floating point value of the range [0,1])
float depth = gfx_gLPDepthBuffer.Sample( samPoint, screenTexCoord ).x;
float linearDepth = gfx_gCamProjB / (depth - gfx_gCamProjA);
float3 positionVS = viewRay * linearDepth;
return positionVS;
}
As you might know, my attempt to extract view space position from depth isn't going well either. But that'll be in my next post; hoping MJP will help me out. ![]()