How would in a PostProcess get back the worldspace position of a pixel?
This has to be possible? Or even better the “ray” direction of each pixel in worldspace?
How would in a PostProcess get back the worldspace position of a pixel?
This has to be possible? Or even better the “ray” direction of each pixel in worldspace?
Send the inverse of viewProjectionMatrix and do a unproject in your shader kind of like here:
hmmm, ok in the shader is the sourceXYZ basically
vec3(vUV, depthValue)?
not sure how to get the correct XYZ values, is it UV space I pass it or pixel? Im thinking it must be the camera.maxZ*depth.
depth on screen is 0 so (uv, 0)
So:
vec3 ssToPos(){
mat4 matrix = world*view;
matrix *= projection;
matrix = inverse(matrix);
vec3 ss = vec3(0.);
ss.x = vUV.x / resolution.x * 2. - 1.;
ss.y = -( vUV.y / resolution.y * 2. - 1.);
ss.z = 0.0;
vec3 result = vec3(matrix * vec4(ss, 1.0));
float num = vUV.x * matrix[0][3] + vUV.y * matrix[1][3] + 0.0 * matrix[2][3] + matrix[3][3];
return result*(1.0/num);
}
I think?
https://playground.babylonjs.com/#63NSAD
Aww what the heck…
So I copy and past it directly from my local and it works like a charm?!?
What would be different from the playground then my local version using the same BJS version?
UPDATE
It was something about my camera min and max z. Once I got rid of those on my local whabam… anyways what would be a way to apply that to my matrices?