我正在渲染一個3d模型到rendertarget2D,然後使用sprite批處理將其繪製到屏幕上。我啓用了使用這條線在我的構造抗鋸齒:在XNA中渲染非空渲染tarhet禁用了抗鋸齒
graphics.PreferMultiSampling = true;
當我直接渲染模型後備緩衝區,抗鋸齒髮揮預期。現在我正在渲染rendertarget2D,抗鋸齒功能不再起作用,並且出現鋸齒邊緣。 (我沒有調整大小或旋轉rendertarget2D。)
可以爲我解釋這個謎嗎?
代碼:
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferHeight = 720;
graphics.PreferredBackBufferWidth = 1208;
graphics.PreparingDeviceSettings += setBackbufferPreserveContents;
graphics.PreferMultiSampling = true;
this.IsMouseVisible = true;
this.Window.Title = "MyGame";
graphics.ApplyChanges();
}
public void setBackbufferPreserveContents(object sender, PreparingDeviceSettingsEventArgs e)
{
e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(BoardScreen);
GraphicsDevice.Clear(Color.Transparent);
Board.DrawMe(cam);
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.CornflowerBlue);
sb.Begin();
sb.Draw((Texture2D)BoardScreen, new Rectangle(0, 0, 720, 720), Color.White);
sb.End();
base.Draw(gameTime);
}
板是類DrawableModel,其中包含一個模型和它簡單地繪製模型到屏幕的方法DrawMe(相機照相機)的。相機是一個簡單的類,包含投影和視圖矩陣,相機的位置和目標位置。
更新:
這裏的DrawMe方法做什麼:
public void DrawMe(Camera camera)
{
foreach (ModelMesh mesh in ModelToDraw.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = Matrix.CreateTranslation(Translation);
effect.Projection = camera.Projection;
effect.View = camera.View;
}
mesh.Draw();
}
}
更新2:
這裏是我做過什麼主XNA文件中的其餘功能(更新和卸載內容尚未觸及。):
protected override void Initialize()
{
BoardScreen = new RenderTarget2D(graphics.GraphicsDevice, 720, 720);
base.Initialize();
}
protected override void LoadContent()
{
sb = new SpriteBatch(GraphicsDevice);
Board = new DrawableModel(Content.Load<Model>("Models/Board"), Vector3.Zero, Vector3.Zero, Vector3.One);
}
在DrawMe()函數,你用任何形式SamplerState系列的初始化你spritebatch?更具體地說,一個PointClamp採樣器狀態? – jgallant
我使用一個裸露的最小模型繪製循環,循環遍歷模型中的網格物體,並通過每個網格中的效果,爲網格啓用基本照明和每像素照明,併爲每個效果設置世界,投影和視圖矩陣網格,然後調用ModelMesh實例的Draw方法。 –
您的繪製矩形可能與您的RenderTarget(BoardScreen)大小不一致,從而導致失真? – jgallant