2011-10-20 9 views
1

私はインターネット上で発見された教科書から高いqulityアンチエイリアスを取得しようとしています(http://www.rkoenig.eu/index.php?option=com_content & view = article & id = 21:chapter- 3-das-erste-echte-3d-objekt & catid = 6:directx10-basic & 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上でそれを見つけたので、将来的に他の誰かを助けるかもしれないと答えていると思います...

まず、パスカル、あなたはMSAAを最大限に設定していません...あなたは8:これは、0(ゼロ)の品質で8サンプルを意味します...絶対に最大ではありません。 「最大」とは、ローカルマシンにインストールされているGPUによって異なります。したがって、それはPCによって異なります。そのためDirectXアプリケーションでは、DXGIを使用してハードウェアデバイスを適切に列挙し、どの設定が有効かを判断する必要があります。これは些細な話題ではなく、あなた自身の研究と実践を必要とします。 DirectX SDKのドキュメントとサンプル/チュートリアルは素晴らしいスタート地点ですが、オンラインで見つかる多くの資料があります。しかし私のマシンでは、例えばGTX-580 GPUは8:16 MSAAをサポートすることができます(おそらく上位ですが、チェックはしていません)。

DXGIを使用してグラフィックカードとモニタを列挙し、サポートできるMSAAレベル(およびその他のグラフィック機能/設定)を把握する必要があります。これは、たとえば、「最大」MSAA設定やモニタの正しいリフレッシュレートを把握する唯一の方法です。あなたが巧みであれば、あなたのためのハードウェアデバイスを列挙し、最適なグラフィックス設定を把握して将来のプロジェクトにこれを何度もやり直す必要がないように、あなたのゲームエンジン用の小さなライブラリやコンポーネントを作成します。

よろしく、

--ATC--

関連する問題