OK I know it sounds really stupid but... do you know if conversion from screen-space to camera-space coordinates is possible without using any matrix transformation at all ?
I'll explain a bit why I'm asking this. Basically I'm trying to mod a certain dx9 game by hooking it and applying various effects on top of it. I've got a few SSAO implementations working nicely already. But I noticed some of these SSAO shaders required to have camera space positions at hand (more specifically I'm trying to port Scalable Ambient Obscurance to DX9) and they most certainly don't work properly without them.
Oh and... retrieving the game original projection matrix is not possible in my case :/
So all I have is screen space position from my very simple Vertex shader :
VSOUT FrameVS(VSIN IN)
{
VSOUT OUT = (VSOUT)0.0f;
OUT.vertPos = IN.vertPos;
OUT.UVCoord = IN.UVCoord;
return OUT;
}
Which is certainly insufficient to convert from screen-space to camera-space/view-space position, right ?
Now something that sill puzzles me to this day, and you're going to laugh at me because I copy/pasted some magic code that works -to some extent- but that I can't really understand :
const float fovy = 40.0 * 3.14159265 / 180.0; // 40 deg in radian
const float invFocalLenX = tan(fovy * 0.5) * width / height;
const float invFocalLenY = tan(fovy * 0.5);
vec3 uv_to_eye(vec2 uv, float eye_z)
{
uv = (uv * vec2(2.0, -2.0) - vec2(1.0, -1.0));
return vec3(uv * vec2(invFocalLenX, invFocalLenY) * eye_z, eye_z); // get eye position
}
vec3 fetch_eye_pos(vec2 uv)
{
float z = texture2D(tex1, uv).a; // Depth/Normal buffer
return uv_to_eye(uv, z);
}
Correct me if I'm wrong but from screen-space this code should get me back to eye-space position (I guess it's the same as camera-space position right ?)
... And it doesn't use any matrix transformation at all...
... And It does work at least for my HBAO shader. So I was mostly happy copy/pasting this without having to understand how the magic happens... but now that it doesn't work at all with SAO (Scalable Ambient Obscurance) I realize I'm mostly clueless about how all these things work and what's the missing piece of the puzzle for that matter
Sorry for sounding so ignorant. I am