I put the taken photo to background RawImage with preserved aspect ratio and original size. The photo is big and could be bigger than screen. So it overflows the screen and part of the photo is not visible.
After that i put some TextMeshPro objects on top of it.
Then i want to get combined texture (photo + text meshes).
So if i would use RenderTexture with main camera i will get just camera (display) resolution which could be worse and cropped TextMeshPro object if it doesn’t fit in the screen (but does fit in the bigger image).
I was trying to create another adhoc camera and set position and viewport to embrace the whole photo but it doesn’t render since TextMeshPro is a UI element within Canvas, which itself renders on the Main Camera only.
Sorry for bumping this, but seeing as the answer is a bit undetailed and one of the first results on Google (along with the decade old link OP provided), I’d like to hear people’s take on the best way to achieve this effect, preferably in detail?
I only just learned about the existence of Render Texture, so if anyone has valid input on the best way to achieve this, maybe with TextMesh Pro I would be ever so happy!
see the attached file, a simple demo, using Graphics.DrawMeshNow. Using Unity 2020.3.1f1 (64-bit), and the shader of the text’ material is Distance Field SSD.
it works amazing in build-in pipeline, but when I play it on URP, the text.mesh all seems to rendered as simple blocks, only shows the bounds of every character of my words.
And I use a silly way: just add a render texture to a camera, and use this render texture as my material’s maintex, it works but not that elegant.
In 2024 this thread was still a big help (TMP docs were not of any hepl - the official FAQ linked to from Unity manual is still offline after more than a year, and there was nothing in the docs about materials and how TMP uses them in an unusual way).
TL;DR: For anyone else using DrawMesh or similar, and getting this:
…Where the actual mesh being rendered (and so the above image should look like this):
… it seems to be that (as per @_eternal 's comment above), TMP requires you to:
Ignore the material on the TMP object (its MeshRenderer.sharedMaterial) - it will fail with the blocks output above (presumably something to do with TMP using custom shaders to do the SDF effect for smooth text etc? - that would make sense)
Use TMP’s custom .renderer attribute, and the material on that instead.
The SetPass stuff shouldn’t be needed for modern DrawMesh (it’s needed I think for the low-level GL approach @_eternal was using)
… I don’t know why @_eternal was doing a switch based on Application state.
Also I couldn’t find anything in the TMP docs explaining any of this, so this is trial-and-error/guesswork - but kind-of makes sense after the fact.