{"id":2061,"date":"2020-07-02T12:40:07","date_gmt":"2020-07-02T04:40:07","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=2061"},"modified":"2020-07-02T12:40:07","modified_gmt":"2020-07-02T04:40:07","slug":"unityunity%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89rt%e6%b8%b2%e6%9f%93%e7%89%a9%e4%bb%b6%ef%bc%8c%e7%89%a9%e4%bb%b6%e6%b8%b2%e6%9f%93%e5%bc%82%e5%b8%b8%e7%9a%84%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=2061","title":{"rendered":"[Unity]Unity\u4e2d\u81ea\u5b9a\u4e49RT\u6e32\u67d3\u7269\u4ef6\uff0c\u7269\u4ef6\u6e32\u67d3\u5f02\u5e38\u7684\u95ee\u9898\u89e3\u51b3"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>            int lastLayer = actor.layer;\n            actor.ChangeLayer(LayersDefine.DynamicRtRender);\n\n            renderCamera.CopyFrom(mainCamera);\n            renderCamera.cullingMask = 1 &lt;&lt; LayersDefine.DynamicRtRender;\n            renderCamera.backgroundColor = new Color(0, 0, 0, 0);\n            renderCamera.clearFlags = CameraClearFlags.SolidColor;\n\n            RenderTexture currRt = RenderTexture.GetTemporary (mainCamera.pixelWidth, mainCamera.pixelHeight);\n            renderCamera.targetTexture = currRt;\n            renderCamera.Render();\n\n            RenderTexture lastRt = RenderTexture.active;\n            RenderTexture.active = currRt;\n\n            Texture2D tex2D = new Texture2D(mainCamera.pixelWidth, mainCamera.pixelHeight);\n            tex2D.ReadPixels(new Rect(0, 0, mainCamera.pixelWidth, mainCamera.pixelHeight), 0, 0);\n            tex2D.Apply();\n\n            RenderTexture.active = lastRt;\n            RenderTexture.ReleaseTemporary (currRt);\n\n            image.sprite =  Sprite.Create(tex2D, new Rect(0, 0, tex2D.width, tex2D.height), new Vector2(0.5f, 0.5f), 100.0f);<\/code><\/pre>\n\n\n\n<p> \u53d1\u73b0\u6e32\u67d3\u6b21\u5e8f\u9519\u8bef <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RenderTexture.GetTemporary (mainCamera.pixelWidth, mainCamera.pixelHeight\uff0c 24); \/\/ \u89e3\u51b3\u95ee\u9898 <\/code><\/pre>\n\n\n\n<p>\n\nRenderTexture.GetTemporary<br>public static RenderTexture GetTemporary(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false);<br><strong>Parameters<\/strong><\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>width<\/td><td>Width in pixels.<\/td><\/tr><tr><td>height<\/td><td>Height in pixels.<\/td><\/tr><tr><td>depthBuffer<\/td><td>Depth buffer bits (0, 16 or 24). Note that only 24 bit depth has stencil buffer.<\/td><\/tr><tr><td>format<\/td><td>Render texture format.<\/td><\/tr><tr><td>readWrite<\/td><td>Color space conversion mode.<\/td><\/tr><tr><td>antiAliasing<\/td><td>Number of antialiasing samples to store in the texture. Valid values are 1, 2, 4, and 8. Throws an exception if any other value is passed.<\/td><\/tr><tr><td>memorylessMode<\/td><td>Render texture memoryless mode.<\/td><\/tr><tr><td>desc<\/td><td>Use this RenderTextureDesc for the settings when creating the temporary RenderTexture.<\/td><\/tr><\/tbody><\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u53d1\u73b0\u6e32\u67d3\u6b21\u5e8f\u9519\u8bef RenderTexture.GetTemporarypublic static Render [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2061"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2061"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2061\/revisions"}],"predecessor-version":[{"id":2062,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2061\/revisions\/2062"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}