その先にあるもの…

스크립트에서 RenderTexture 사용 본문

프로그래밍/Unity

스크립트에서 RenderTexture 사용

specialJ 2015. 2. 25. 18:25

현재 찍혀있는 화면을 얻어와서 매터리얼의 텍스쳐에 연결하기


코드로 작성하는 것 보다 유니티 창에서 연결하는게 더 편하다.


처음 해보는 것이니 기록은 코드로...



m_RenderTexture
      = new RenderTexture((int)Camera.main.pixelWidth, (int)Camera.main.pixelHeight, 16);
this.gameObject.camera.targetTexture = m_RenderTexture;




 

this.gameObject.SetActive(true);

this.gameObject.camera.CopyFrom(Camera.main);

this.gameObject.camera.targetTexture = m_RenderTexture;

RenderTexture rt = RenderTexture.active;

RenderTexture.active = this.gameObject.camera.targetTexture;

this.gameObject.camera.Render();


//this.gameObject.camera.targetTexture은 texture타입이니까.

GameValue.SceneImg.ChangeText(this.gameObject.camera.targetTexture);

this.gameObject.camera.targetTexture.DiscardContents();

RenderTexture.active = rt;

this.gameObject.SetActive(false);

     

검색 링크

http://docs.unity3d.com/ScriptReference/RenderTexture.html

http://docs.unity3d.com/ScriptReference/Camera.Render.html

http://www.devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=5797&sca=&sfl=wr_subject%7C%7Cwr_content&stx=RenderTexture.active&sop=and&currentId=44

http://answers.unity3d.com/questions/22954/how-to-save-a-picture-take-screenshot-from-a-camer.html

http://blog.almostlogical.com/2009/12/11/render-to-texture-unity3d/


free version rendertexture

http://blog.christianhenschel.com/2014/03/09/render-screen-to-texture-in-unity3d-without-pro/

http://www.reddit.com/r/Unity3D/comments/2kb0sx/rendertextures_in_free_unity/

Comments