- Home /
Correcting Object Offset on WorldToScreenPoint
I've been trying to make a skybox generator based on objects in the world. I have been using the WorldToScreenPoint function to try and plot dots to corresponding coordinates on a 2D image. But once the process is complete and everything is built and running, there is a significant offset for the dots on the image vs. the objects in the scene. Here is the code involved in rendering a side:
if(s.transform.position.z > 0){
Vector3 screenPosFront = _cameraLeft.WorldToScreenPoint(s.transform.position);
tex_front.SetPixel(Mathf.RoundToInt(screenPosFront.x), Mathf.RoundToInt(screenPosFront.y), Color.cyan);
}
I have also set the pixel width and the pixel height of the camera to the same resolution as the textures used to hopefully eliminate that variable. I should also mention that I am trying to render objects that aren't even in the camera view. In other words objects that are really far away.
It looks like you want a stencil image. If that's the case, you should do this via a shader which is invoked for all/specific objects in the scene via RenderWithShader
I can't use that for a number of reasons. 1 being that the objects that I am trying to plot are too far away to even be seen by the camera.
there is a significant offset for the dots on the image vs. the objects in the scene
How do you position the resultant image for the camera that renders it? Edit: sorry- bad comment- you clearly state you are using a skybox.
Another Edit: I think using a skybox may be the cause of your problem. The skybox will wrap the image all the way around the camera, rather than simply showing an image at a distance that perfectly fills the screen. So, your worldtoscreen point, wont be converting to what the ACTUAL screen point is (it will get warped to fill 360deg, rather than the cemera's viewing angle).
Try putting the image you generate on a sprite, on a canvas that is set to screen-size. Or something similar, the point being to render a plain-ol' rectangular image, that exactly fills the screen.
Your answer
Follow this Question
Related Questions
GUIButtons Follow different GameObjects?? 1 Answer
Why does my TMP inputfield text disappears when I rotate It, why using a world space camera 0 Answers
Cinemachine not working with my Movement Script 0 Answers
how to get the most right point or left point atc of object as visual on the screen in 3d project? 0 Answers