2016-05-27 3 views
3

金属のテクスチャに深度バッファを保存したいのですが、何も試したことがないようです。 Metalでテクスチャに深度バッファを保存するにはどうすればよいですか?

_renderPassDesc.colorAttachments[1].clearColor = MTLClearColorMake(0.f, 0.f, 0.f, 1.f); 
[self createTextureFor:_renderPassDesc.colorAttachments[1] 
        size:screenSize 
      withDevice:_device 
       format:MTLPixelFormatRGBA16Float]; 

_renderPassDesc.depthAttachment.loadAction = MTLLoadActionClear; 
_renderPassDesc.depthAttachment.storeAction = MTLStoreActionStore; 
_renderPassDesc.depthAttachment.texture = self.depthTexture; 
_renderPassDesc.depthAttachment.clearDepth = 1.0; 

私は(私の他のテクスチャからのデータと正常に動作します)私のシェーダにdepthTextureを渡す

は、私が得るすべては赤色画素です。

clearDepthを0に近い値に変更すると、暗い色合いの赤が表示されます。おそらく私はシェイダーでテクスチャを正しくサンプリングしていないのでしょうか?

fragment float4 cubeFrag(ColorInOut in [[stage_in]], 
        texture2d<float> albedo [[ texture(0) ]], 
        texture2d<float> normals [[ texture(1) ]], 
        texture2d<float> albedo2 [[ texture(2) ]], 
        texture2d<float> normals2 [[ texture(3) ]], 
        texture2d<float> lightData [[ texture(4) ]], 
        texture2d<float> depth [[ texture(5) ]]) 
{ 
    constexpr sampler texSampler(min_filter::linear, mag_filter::linear); 
    return depth.sample(texSampler, in.texCoord).rgba; 
} 

答えて

0

OK、それは私がちょうどにTexture2Dの代わりにdepth2d使用するために必要なことがわかった:引数の型として代わりにtexture2d<float>

depth2d<float> depth [[ texture(5) ]]) 
2

使用depth2d<float>、および深度テクスチャfloat val = depth.sample(texSampler, in.texCoord);

からフロートを読みます
関連する問題