[程式] 如何讀取Rendertexture的深度資訊
最近因為這東西卡好幾天了, 希望有經驗的前輩能夠幫忙看一下
想請問有沒有辦法能夠在shader中使用render texture的depth buffer
也就是說, 我有一個camera 是render到render texture
有一個效果我需要讀取render texture中的depth 資訊
但是問題來了, 在render texture中我唯一找得到跟depth有關係的東西是
rendertexture.depthBuffer, 但是這東西沒有辦法丟進material 中
的setTexture 參數, 我也查不到有甚麼辦法能夠把render buffer轉成
texture的方式
雖然的確是有辦法可以繞過這個限制, 例如說可以建立兩個render texture
一個是color, 一個是depth, 然後再用
_sceneCamera.SetTargetBuffers(_renderTexture.colorBuffer,
_depthTexture.depthBuffer);
這方法來抓depth value
但是這方法不適用於當我想使用post processing的時候, 當我想要用PP時
我唯一能讓該camera成功有PP的方式就是 _sceneCamera.targetTexture =
_renderTexture;
但這方法又會沒辦法讓我讀取depth texture
後來我又嘗試把 depbuffer轉成textture2D
_renderTexture = new RenderTexture(Screen.width, Screen.height, 24,
RenderTextureFormat.Default);
_renderTexture.Create();
_textDepth = Texture2D.CreateExternalTexture(_renderTexture.width,
_renderTexture.height, TextureFormat.RGB24, false, false,
_renderTexture.GetNativeDepthBufferPtr());
但是unity直接crash
希望我的解釋夠清楚 感謝回答
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 24.210.62.187
※ 文章網址: https://www.ptt.cc/bbs/GameDesign/M.1507912584.A.430.html
※ 編輯: Ninja5566 (24.210.62.187), 10/14/2017 01:11:54
推
10/14 01:49,
7年前
, 1F
10/14 01:49, 1F
→
10/14 01:49,
7年前
, 2F
10/14 01:49, 2F
→
10/14 01:50,
7年前
, 3F
10/14 01:50, 3F
→
10/14 04:24,
7年前
, 4F
10/14 04:24, 4F
→
10/14 04:41,
7年前
, 5F
10/14 04:41, 5F
→
10/14 04:41,
7年前
, 6F
10/14 04:41, 6F
→
10/14 09:11,
7年前
, 7F
10/14 09:11, 7F
→
10/14 09:12,
7年前
, 8F
10/14 09:12, 8F
→
10/14 20:42,
7年前
, 9F
10/14 20:42, 9F
→
10/14 20:43,
7年前
, 10F
10/14 20:43, 10F
GameDesign 近期熱門文章
PTT遊戲區 即時熱門文章
12
39