Hello,
I have been working on a glsl shader that requires the camera position and direction of every frame in order to display some shapes on the pixels that appear to be 3D. However I couldn’t find any shader input from Panda3d that gives directly camera position and camera direction, so I tried to create them using shader translation matrices.
I am fairly new to the world of shaders, so I took a trial-and-error approach. The closest I managed to get to finding the camera position was by using the trans_view_to_world matrix to transform my vector and then exchanging the y with the z components of the vector. Here’s what it looks like in my code
vec4 camera_start = vec4(0.,0.,0.,1.);
vec4 camera_pos = trans_view_to_world * camera_start;
vec3 cp = vec3(camera_pos_4[0] , camera_pos_4[2] , camera_pos_4[1] );
return cp; // current camera position
Though this gives results that are seemingly correct (zooming in and out and panning seem to work rather well), the result is off. When the camera rotates the shapes shoot off in an unexpected direction and it always feels that they are further away from the camera that they should be.
Any ideas on how I can find the correct camera position would be very welcome, thanks a lot!