Hello, so far I have had a positive experience only with babylon.js. Currently I want to look at Unity. I have no experience with Unity, so please be patient for now
My question sounds, how to draw a 2D sprite in a classical 3D scene? But I don’t want to draw the texture in the “plane” object, because the plane object distorted by camera angle… What I need is to render a 2D sprite at a specific 2D coordinate and even though I move the sprite image, the image will still look the same, regardless of the position of the sprite to the camera.
The attached picture illustrates what I want to see. We can see a simple 3d scene with basic objects and 2x lamp sprites. Sprites are not a texture of plane 3D object and that is why it looks the same on the right as on the left side of scene. Sprites are not linked to perspective. Is it possible to do this in Unity? Thank you for your time.
easiest: make a UI (generally a Canvas using the UnityEngine.UI namespace classes) and put your 2D stuff there
make a second camera with orthographic perspective, set it to clear depth only and depth on top of your perspective camera, then use layers to have each camera see the correct parts of your scene
do your own in-scene card constantly aligned to the camera.
Thank you for answer. When we talk about option one (easiest option). Is it possible to set UI Sprite drawing ordered relative to 3D object? For example, the right UI sprite lamp, will be drawn behind a teapot of gray color. Possible? Thanks.
If you use overlay canvas it will be drawn on top (overlaid) on top of all the 3d stuff.
But if you use camera canvas mode, it is possible to assign z depth. Just need to use correct API to convert between camera canvas coordinates and world 3d coordinates and also calculate the size. Note that this isn’t arbitrary setting of drawing order, but instead based on z buffer so if you don’t position your sprites carefully they may partially clip into 3d objects. You also need to be aware that ordering of canvas objects relative to 3d objects will not be the same as between multiple canvas objects, so it’s possible to get physically impossible setups where canvas object A is in front of canvas object B, but A is behind 3d object D which is behind B.
Another thing that might not be relevant depending on the complexity of your setup. Even though UI objects can take into account z-depth they don’t change it.
If you want the ordering between 2d and 3d objects to be based on small amount of categories instead of Z depth, multiple camera setup might be more suitable. Multiple cameras can still be combined with canvases.
The default 3D Renderers draw stuff according to Z depth - distance from camera.
SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties
UI Canvas Renderers draw in linear transform sequence, like a stack of papers
If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:
identify what you are using
search online for the combination of things you are doing and how to to achieve what you want.