Jump to content
  • Advertisement
Sign in to follow this  
Laccolith

Position Reconstruction Problem

This topic is 3008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to reconstruct the world space position of a pixel in a Compute Shader to do the lighting calculations but I don't seem to be getting the correct position. I'm storing the value with "output.vDepth = Input.vDepth.x / Input.vDepth.y;". Then this mess of code in the Compute Shader should give the position but I'm just getting strange results.
float depthVal = gBufferTexture3[dispatchThreadId.xy].r;
	
uint2 dimensions;
gBufferTexture1.GetDimensions(dimensions.x, dimensions.y);
	
float2 coords = float2(((float)dispatchThreadId.x / (float)dimensions.x), ((float)dispatchThreadId.y / (float)dimensions.y));
	
float2 screenPos = (2.0f * float2(coords.x, coords.y)) - 1.0f;

float4 position;
position.xy = float2(screenPos.x, -screenPos.y);
position.z = depthVal;
position.w = 1.0f;

position = mul(position, InvertViewProjection);
position /= position.w;
These are some screencaps on a long corridor model, there should be a single light close to where the camera is in the first 2 shots but when rotating the camera everything changes, the last 3 pics are just of the diffuse lighting from the light buffer. http://laccolith.imgur.com/deffered_problem I can post more of the shaders code if it'll help? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I can't say that I see anything immediately wrong with your code, assuming that you set everything up correctly. It would be nice if we could debug compute shaders in PIX. [sad]

Share this post


Link to post
Share on other sites
yea :(

This is my first time using D3D11 so it's very possible I've made a misstake else where. I'm pretty sure that its sampling the right pixels of the buffers and the gbuffer textures have the right data in them. Maybe I've set up the cbuffer incorrectly and so the inverseViewProjection matrix is coming thought wrong, this is cbuffers struct in the main program code:
struct CB_CS
{
int lightCount;
D3DXVECTOR3 cameraPosition;
D3DXMATRIX InvertViewProjection;
};
Then I map it with:
mProj = *g_Camera.GetProjMatrix();
mView = *g_Camera.GetViewMatrix();
mViewProjection = mView*mProj;
D3DXMatrixInverse(&mInverseViewProjection, NULL, &mViewProjection);

D3D11_MAPPED_SUBRESOURCE CSMappedResource;
V( pd3dImmediateContext->Map( g_pcbCS, 0, D3D11_MAP_WRITE_DISCARD, 0, &CSMappedResource ) );
CB_CS* pcbCS = ( CB_CS* )CSMappedResource.pData;
pcbCS->lightCount = g_iNumLights;
pcbCS->cameraPosition = *g_Camera.GetEyePt();
pcbCS->InvertViewProjection = mInverseViewProjection;

pd3dImmediateContext->Unmap( g_pcbCS, 0 );
ID3D11Buffer* ppCB[1] = { g_pcbCS };
pd3dImmediateContext->CSSetConstantBuffers( 0, 1, ppCB );

And at the top of my shader its:
cbuffer cbCS : register( b0 )
{
int lightCount;
float3 cameraPosition;
float4x4 InvertViewProjection;
};

Share this post


Link to post
Share on other sites
Just found out about PerfStudio 2 so I can now step though the shader line by line to find the problem but it will only let me go though the assembly.

Anyway the position value seems to be okay up until the multiply with the InverseViewProjection then the position values go haywire(I think?). Heres the before and after for the multiply:

Hosted by imgur.com
Hosted by imgur.com

Doing some more debugging to try and compare the matrix before sending to the compute shader and what the compute shader receives.

Share this post


Link to post
Share on other sites
Ahh I see your problem. You need to transpose your matrix before setting it into your constant buffer.

Also with regards to source code debugging...are you compiling your shaders with D3D10_SHADER_DEBUG?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!