I have a ray and its direction is (o,d). Multiply it by the model matrix to rotate the model.
o = uCamera.xyz, d = GenRay();
o = vec3(uModel * vec4(o,1));
d = vec3(uModel * vec4(d,0));
Then beam, RayMarchLeaf(o, d, t, color, normal); where get the position vec3 t of the collision of the beam. (in model coordinates).
Then traslate t to world coordinates :
t = vec3(inverse(uModel) * vec4(t,1)); // map to world pos;
ok, we have a 3d camera coordinate and a point. For Depth value, we can use length(uCamera.xyz - t), but this is not accurate. My camera is moving and rotating in 3d space.
How to accurate calculate depth value to store in texture?