I am using Templates->Python->Operator Modal View3D Raycast template script which uses
event.mouse_region_x, event.mouse_region_y
to create raycasts into the scene. When I specify the coord to be (0, 0) for example then the raycast is done from the bottom left corner of 3D View.
What I am trying to achieve is to raycast from a perspective camera view into the scene using pixel coordinates. So for example if I give coordinates (0, 0) I would expect the raycast to be done from bottom left corner of the camera view. Or if I were to give (1920, 1080) as the coordinate, I'd expect the raycast to be done from top right corner of the camera view (considering render settings are at 1920x1080 resolution).
I found How to find image coordinates of the rendered vertex? for translating 3D cursor into 2D px coordinates, but I am not sure how to do it vice versa - from 2D coordinates of the camera view raycast into the 3D scene.
Essentially I am trying to build a script that takes image as an input and registers a 3D point on a surface of a mesh visible from the camera view at that particular image coordinate (render settings are adjusted to fit the image resolution of course).