Hello!
My goal:
- For a given FOV and aspect ratio, project screen space pixels into 3D world space based on pixel depth value. Depth is in absolute floating point format.
(as seen done in depthProjection comp) - Transform these points in 3D space based on transformations of a given camera view. A default camera state should correspond to no transformation (all zeroes, scale at 1)
- Project these 3D points back into the screen space (of camera from step 1).
- Output the offset in screen space between pixel UV position before and after 3D imaginary camera transformation.
Essentially the effect is analogous to a scenario where we would create geometry based on a depth map, then move with a camera around it, except here I want to have UV offset data to use with pixel displacements.
Despite my best efforts, I feel completely defeated on this relatively simple task after several days of trial and only error. I started knowing nothing about GLSL, but able to visualize all the transformations in my head.
I ended up knowing a lot more about matrix transformations, shader language, NDC, and conversions between world, view, and projection spaces, but alas, after countless youtube tutorials and an infinitely long chatGPT thread, Iām only making the AI and myself more confused at this point. I need real humans.
Iāve tried to put the aforementioned steps into a GLSL pixel shader.
The āimaginaryā camera is a camera comp that I feed in as uniform mat4 through .transform()
method. FOV and aspect come in as vec2. Depth is one of top inputs.
The code in the depthProjection component seemed like a good start, but most of the information online and especially what chatGPT follows are the conventions from graphics pipelines with various openGL libraries, which I struggled to fit together with that code. For example it often suggests the perspective()
function to built the projection matrix, which is not available by default as far as I am aware?
If anyone is willing to look into this:
glsl projection.toe (719.2 KB)
I am attaching a template .toe file with locked tops that hold an example depth and image frame, but I essentially only left pseudo code (my logical thinking) inside GLSL main function, because all of my countless variants failed in one way or another, working almost right, but not quite right. It became a spaghetti of rethinking and redoing everything, and nobody deserves to be tortured by that.
Also attached is a displace node, that alludes to further steps in my pipeline and should visualize correct UV offsets by displacing the scene with apparent depth.
Thank you! Iād be excited to eventually share my project after I get over this bottleneck.