Position Reconstruction Problem

Started by
4 comments, last by Laccolith 14 years ago
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
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]
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;};
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.
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?
Many thanks, all seems to be working now :D

Hosted by imgur.com

This topic is closed to new replies.

Advertisement