I'm struggling again with my deferred renderer. This time I'm rewriting it from OpenGL/Cg to DX11/HLSL. I have almost everything working but (I think) my reconstruction from depth is now working correctly (I compared normals and they look the same as in OGL renderer, so I guess they are fine). The result I get is somewhat correct but bad things start to happen when I move away from the lit object - It becomes darker and darker and eventually gets all black. The thing is that I use almost the same code as when dealing with Cg/OGL and perhaps I've overlooked something with conversion. Fun fact - walls that are closer to the camera gets darker quicker than walls that are further away - maybe this will give some hint.
//compute view space position #define ZNEAR zNearZFar.x #define ZFAR zNearZFar.y #define A (ZNEAR + ZFAR) #define B (ZNEAR - ZFAR) #define C (2.0 * ZNEAR * ZFAR) #define D (ndcPos.z * B) #define ZEYE (-C / (A + D)) float depth2 = shaderTexture2.Sample(SampleType, texCoord); float3 ndcPos = (float3(texCoord.x, 1 - texCoord.y, depth2) - 0.5) * 2.0; //<<<Here I had to flip Y coord when compared to the OGL/Cg shader float4 clipPos; clipPos.w = -ZEYE; clipPos.xyz = ndcPos * clipPos.w; float3 vsPos = mul(invProj, clipPos).xyz;