2011-10-20 33 views
1

我試圖從我在互聯網上找到的tuturial獲得高質量的抗鋸齒(http://www.rkoenig.eu/index.php?option=com_content & view = article & id = 21:chapter- 3-das-erste-echte-3d-objekt & catid = 6:directx10-basics & Itemid = 3)。但沒有達到很好的解決方案。SLIMDX antialising

我已經設置了多重採樣到最大:

m_swapChainDesc.SampleDescription = new DXGI.SampleDescription(8,0); 

對我來說,它顯示爲渲染圖像的像素大小比我的屏幕的實際像素大小。

非常感謝你提前爲您的寶貴意見

這裏是完整的代碼:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using SlimDX; 

using DX10 = SlimDX.Direct3D10; 
using DXGI = SlimDX.DXGI; 

namespace TutorialSeries.DirectX10.Chapter3 
{ 
    public partial class MainWindow : Form 
    { 
     private DX10.Device m_device; 
     private DXGI.SwapChainDescription m_swapChainDesc; 
     private DXGI.SwapChain m_swapChain; 
     private DXGI.Factory m_factory; 
     private DX10.RenderTargetView m_renderTarget; 
     private bool m_initialized; 

     private SimpleBox m_simpleBox; 

     private Matrix m_viewMatrix; 
     private Matrix m_projMatrix; 
     private Matrix m_worldMatrix; 
     private Matrix m_viewProjMatrix; 

     public MainWindow() 
     { 
      InitializeComponent(); 

      this.SetStyle(ControlStyles.ResizeRedraw, true); 
      this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
      this.SetStyle(ControlStyles.Opaque, true); 
     } 

     /// <summary> 
     /// Initializes device and other resources needed for rendering. Returns true, if successful. 
     /// </summary> 
     private bool Initialize3D() 
     { 
      try 
      { 
       m_device = new DX10.Device(DX10.DriverType.Warp, DX10.DeviceCreationFlags.SingleThreaded); 

       m_factory = new DXGI.Factory(); 

       m_swapChainDesc = new DXGI.SwapChainDescription(); 
       m_swapChainDesc.OutputHandle = this.Handle; 
       m_swapChainDesc.IsWindowed = true; 
       m_swapChainDesc.BufferCount = 1; 
       m_swapChainDesc.Flags = DXGI.SwapChainFlags.AllowModeSwitch; 
       m_swapChainDesc.ModeDescription = new DXGI.ModeDescription(
        this.Width, 
        this.Height, 
        new Rational(60, 1), 
        DXGI.Format.R8G8B8A8_UNorm); 
       m_swapChainDesc.SampleDescription = new DXGI.SampleDescription(8,0); 
       m_swapChainDesc.SwapEffect = DXGI.SwapEffect.Discard; 
       m_swapChainDesc.Usage = DXGI.Usage.RenderTargetOutput; 

       m_swapChain = new DXGI.SwapChain(m_factory, m_device, m_swapChainDesc); 



       DX10.Viewport viewPort = new DX10.Viewport(); 
       viewPort.X = 0; 
       viewPort.Y = 0; 
       viewPort.Width = this.Width; 
       viewPort.Height = this.Height; 
       viewPort.MinZ = 0f; 
       viewPort.MaxZ = 1f; 

       //DX10.Texture2D backBuffer = m_swapChain.GetBuffer<DX10.Texture2D>(0); 
       DX10.Texture2D Texture = DX10.Texture2D.FromSwapChain<DX10.Texture2D>(m_swapChain,0); 

       //m_renderTarget = new DX10.RenderTargetView(m_device, backBuffer); 
       //DX10.RenderTargetViewDescription renderDesc = new DX10.RenderTargetViewDescription(); 
       //renderDesc.FirstArraySlice = 0; 
       //renderDesc.MipSlice = 0; 

       m_renderTarget = new DX10.RenderTargetView(m_device, Texture); 

       Texture.Dispose(); 

       DX10.RasterizerStateDescription rsd = new DX10.RasterizerStateDescription(); 
       rsd.CullMode = DX10.CullMode.Back; 
       rsd.FillMode = DX10.FillMode.Wireframe; 
       rsd.IsMultisampleEnabled = true; 
       rsd.IsAntialiasedLineEnabled = false; 
       rsd.IsDepthClipEnabled = false; 
       rsd.IsScissorEnabled = false; 

       DX10.RasterizerState RasterStateWireFrame = DX10.RasterizerState.FromDescription(m_device,rsd); 

       DX10.BlendStateDescription blendDesc = new DX10.BlendStateDescription(); 
       blendDesc.BlendOperation = DX10.BlendOperation.Add; 
       blendDesc.AlphaBlendOperation = DX10.BlendOperation.Add; 
       blendDesc.SourceAlphaBlend = DX10.BlendOption.Zero; 
       blendDesc.DestinationAlphaBlend = DX10.BlendOption.Zero; 
       blendDesc.SourceBlend = DX10.BlendOption.SourceColor; 
       blendDesc.DestinationBlend = DX10.BlendOption.Zero; 
       blendDesc.IsAlphaToCoverageEnabled = false; 
       blendDesc.SetWriteMask(0, DX10.ColorWriteMaskFlags.All); 
       blendDesc.SetBlendEnable(0, true); 
       DX10.BlendState m_blendState = DX10.BlendState.FromDescription(m_device, blendDesc); 

       m_device.Rasterizer.State = RasterStateWireFrame; 
       m_device.Rasterizer.SetViewports(viewPort); 
       m_device.OutputMerger.BlendState = m_blendState; 
       m_device.OutputMerger.SetTargets(m_renderTarget); 

       m_viewMatrix = Matrix.LookAtLH(
        new Vector3(0f, 0f, -4f), 
        new Vector3(0f, 0f, 1f), 
        new Vector3(0f, 1f, 0f)); 
       m_projMatrix = Matrix.PerspectiveFovLH(
        (float)Math.PI * 0.5f, 
        this.Width/(float)this.Height, 
        0.1f, 100f); 
       m_viewProjMatrix = m_viewMatrix * m_projMatrix; 
       m_worldMatrix = Matrix.RotationYawPitchRoll(0.85f, 0.85f, 0f); 

       m_simpleBox = new SimpleBox(); 
       m_simpleBox.LoadResources(m_device); 

       m_initialized = true; 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("Error while initializing Direct3D10: \n" + ex.Message); 
       m_initialized = false; 
      } 

      return m_initialized; 
     } 

     /// <summary> 
     /// Rendering is done during the standard OnPaint event 
     /// </summary> 
     protected override void OnPaint(PaintEventArgs e) 
     { 
      base.OnPaint(e); 

      if (m_initialized) 
      { 
       m_device.ClearRenderTargetView(m_renderTarget, new Color4(Color.CornflowerBlue)); 

       m_simpleBox.Render(m_device, m_worldMatrix, m_viewProjMatrix); 

       m_swapChain.Present(0, DXGI.PresentFlags.None); 
      } 
     } 



     /// <summary> 
     /// Initialize 3D-Graphics within OnLoad event 
     /// </summary> 
     protected override void OnLoad(EventArgs e) 
     { 
      base.OnLoad(e); 
      Initialize3D(); 
     } 
    } 
} 

回答

0

這是一個老問題,但它是一個恥辱,它從來沒有得到回答;我偶然發現它在Google上,所以我認爲回答它可能會幫助其他人在將來...

首先,Pascal,您沒有將MSAA設置爲最大值...您正在使用8:0,這意味着8個樣本的質量爲0(零)...絕對不是最大值。 「最大值」取決於安裝在本地機器上的GPU。所以它從PC到PC都不相同。這就是爲什麼DirectX應用程序需要使用DXGI來正確枚舉硬件設備並確定哪些設置是有效的。這不是一個小問題,需要你自己做一些研究和實踐。 DirectX SDK文檔和樣本/教程是一個很好的起點,還有很多其他材料可以在線找到。但是在我的機器上,例如,我的GTX-580 GPU可以支持8:16 MSAA(可能更高,但未檢查)。

因此,您需要學習使用DXGI來枚舉您的圖形卡和顯示器,並找出它可以支持的MSAA級別(以及其他圖形功能/設置)。例如,這是您唯一能夠計算出「最大」MSAA設置或顯示器的正確刷新率的唯一方法。如果你很聰明,你會爲自己寫一個小型庫或組件給你的遊戲引擎,它會爲你枚舉硬件設備,並找出最佳的圖形設置,這樣你就不必爲了將來的項目重複這樣做。

問候,

--ATC--