Created
January 18, 2025 23:15
-
-
Save baba-s/e66292049be383b43a301682c6564a1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] TextMeshPro tmpStandard; | |
[SerializeField] TextMeshProUGUI tmpUI; | |
public void SendTmpToRenderTexture() | |
{ | |
Vector2 size = new Vector2(100f, 100f); | |
RenderTexture tex = RenderTexture.GetTemporary(100f, Mathf.RoundToInt(size.y * 200f), 24, RenderTextureFormat.ARGB32); | |
GL.PushMatrix(); // copy current camera matrix settings | |
GL.LoadIdentity(); | |
Matrix4x4 proj = Matrix4x4.Ortho(-size.x / 2f, size.x / 2f, -size.x / 2f, size.y / 2f, -10f, 100f); | |
GL.LoadProjectionMatrix(proj); | |
RenderTexture currentActiveRT = RenderTexture.active; | |
Graphics.SetRenderTarget(tex); | |
GL.Clear(false, true, new Color(0f, 0f, 0f, 0f)); | |
if (tmpUI) | |
{ | |
tmpUI.materialForRendering.SetPass(0); | |
Graphics.DrawMeshNow(tmpUI.mesh, Matrix4x4.identity); | |
} | |
else | |
{ | |
if (Application.isPlaying) | |
tmpStandard.renderer.material.SetPass(0); | |
else | |
tmpStandard.renderer.sharedMaterial.SetPass(0); | |
Graphics.DrawMeshNow(tmpStandard.mesh, Matrix4x4.identity); | |
} | |
//restore settings | |
GL.PopMatrix(); | |
RenderTexture.active = currentActiveRT; | |
//assign texture to image | |
img.gameObject.SetActive(true); | |
imgRt.sizeDelta = thisRt.sizeDelta; | |
img.texture = tex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment