2015-02-05 3 views
2

렌더러를 변경하려고했습니다. SlimDX에서 SharpDX로 쓴 후 문제가 발생했습니다. 나는 여러가 (따기이 경우 색상과 오브젝트 ID의) 렌더 타겟에이 (같은 차원 및 멀티 설정으로 모든)에 렌더의 초기화가Sharpdx - MRT (Multiple Render Targets)를 사용할 때 Depthstencil이 작동하지 않습니다.

렌더링하는

 //Swapchain, Device, Primary Rendertarget 
     var description = new SwapChainDescription() 
     { 
      BufferCount = 1, 
      Usage = Usage.RenderTargetOutput, 
      OutputHandle = Form.Handle, 
      IsWindowed = true, 
      ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm), 
      SampleDescription = new SampleDescription(1, 0), 
      Flags = SwapChainFlags.AllowModeSwitch, 
      SwapEffect = SwapEffect.Discard 
     }; 

     this.Device = new Device(adapter); 
     this.SwapChain = new SwapChain(factory, Device, description); 

     this.backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(SwapChain, 0); 
     this.RenderTargetView = new RenderTargetView(Device, backBuffer); 

     //Depthbuffer 
     Texture2DDescription descDepth = new Texture2DDescription(); 
     descDepth.Width = (int)Viewport.Width; 
     descDepth.Height = (int)Viewport.Height; 
     descDepth.MipLevels = 1; 
     descDepth.ArraySize = 1; 
     descDepth.Format = Format.D32_Float; 
     descDepth.Usage = ResourceUsage.Default; 
     descDepth.SampleDescription = new SampleDescription(1, 0); 
     descDepth.BindFlags = BindFlags.DepthStencil; 
     descDepth.CpuAccessFlags = 0; 
     descDepth.OptionFlags = 0; 

     using (Texture2D depthStencil = new Texture2D(Device, descDepth)) 
     { 
      depthView = new DepthStencilView(Device, depthStencil); 
     } 

     //Rendertargetview for the ID 
     Texture2DDescription IdMapDesc = new Texture2DDescription(); 
     IdMapDesc.Width = (int)Viewport.Width; 
     IdMapDesc.Height = (int)Viewport.Height; 
     IdMapDesc.ArraySize = 1; 
     IdMapDesc.MipLevels = 1; 
     IdMapDesc.Format = Format.R16_UInt; 
     IdMapDesc.Usage = ResourceUsage.Default; 
     IdMapDesc.SampleDescription = new SampleDescription(1, 0); 
     IdMapDesc.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget; 
     IdMapDesc.CpuAccessFlags = 0; 
     IdMapDesc.OptionFlags = 0; 

     using (Texture2D idMap = new Texture2D(Device, IdMapDesc)) 
     { 
      idView = new RenderTargetView(Device, idMap); 
     } 

이것은 내가 얼마나입니다 원하는 그러나이 출력

(이미지를 게시 할 수 없습니다,이 장면이 작동 depthstencil과의)를 생산

public override void Render() 
    { 
     Context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1f, 0); 

     Context.OutputMerger.SetTargets(depthView, RenderTargetView); 

     staticMeshRenderer.UpdateCameraConstants(); 

     foreach(TerrainSegment segment in terrain.SegmentMap) 
     { 
      terrainRenderer.Draw(segment, null); 
     } 

     objectManager.DrawContent(Device); 
    } 

렌더링 사용하는 경우 여러 작업을 수행 이 같은 렌더 타겟

Context.OutputMerger.SetTargets(depthView, RenderTargetView, idView); 

Depthstencil이 작업을 중단합니다. 모두 시도에 사용 HLSL 코드 :

struct PS_Output 
{ 
    float4 Color  : SV_TARGET0; 
    uint ID    : SV_TARGET1; 
}; 

PS_Output PShader(VS_OutputStatic input) 
{ 
    PS_Output output; 
    output.ID = 3; //test 
    output.Color = Diffuse.Sample(StateLinear, input.TexCoords).rgba; 
    return output; 
} 

은 내가 잘못 여기서 뭐하는 거지? 미리 감사드립니다.

+0

그런 시나리오에서 [RenderDoc] (https://github.com/baldurk/renderdoc)와 같은 그래픽 디버거를 사용해보아야합니다. 그러면 문제를 빨리 찾을 수 있습니다. – xoofx

+0

감사합니다. 이제 유용한 프로그램입니다! 그것은 ClientSize를 사용했지만 1900x1177의 버퍼와 1900x1200의 다른 버퍼를 보여주었습니다 ... 저는 다른 방법으로이 값을 내 양식에 할당했고 이제는 작동합니다! – janfo

답변

1

RenderDoc을 사용하여 디버깅 한 결과 내 버퍼 크기가 동일하지 않은 것으로 나타났습니다. 문제를 해결 한 문제 해결.

관련 문제