I am building a game for MOBILE where I want to have 3D characters in my dialogue UI.
I was going to change the canvas render mode from Overlay to Camera and assign the already perspective camera to the canvas and load the 3D model dynamically into right position in the canvas.
But a friend of mine suggest that I use have my characters render in other place and Render their texture as a raw image into a UI element.
It would be easier to control the layers he said.
But I am worry about the performance impact.
Does anyone have any similar experience?
What is the best way to render a 3D model in UI system?
render texture is the way to go… sooo many sorting issues when trying to mix 3d and 2d.
create a render texture, create a new layer, and new camera just to render child object in front of that camera (render camera only renders your new layer, and your normal camera(s) set to not render the new render layer)
Set the camera to clear the background with 0 alpha in the background color (so you get a sprite with transparent border rendered)
Then assign the render texture to RawImage type Ui, and it should all work.
Remember to turn off the RenderCamera when not in use.
Also make the render texture size appropriate… don’t make it 2048 if your screen RawImage is only 128
Devils advocate…
only tricky part here, is if you want to render a character with alpha as part of the character’s texture (semi transparent… say fairy wings) we’ll need to use a shader that writes alpha into the target render texture, or the wings will look opaque or disappear completely.
If your character is just plain opaque model… you shouldn’t need to worry about that. It should just work.
If you do have such alpha… you may need to try experimenting with some different shader options.