SharpDX:启用BlendState [英] SharpDX: Enabling BlendState

查看:91
本文介绍了SharpDX:启用BlendState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使 SharpDX.Direct3D11.DeviceContext.OutputMerger.Blendstate正常工作。没有这个,我将拥有一个不错的场景(上面有纹理的多边形,用于Spaceshooter)。在过去的三年中,我已经完成了OpenGL Graphics,所以我认为它可能和OpenGL中一样简单-只需启用Blending并设置正确的Dst / Src模式即可。但是,如果我设置了新的BlendStateDescription,则即使 RenderTarget [x] .IsBlendEnabled设置为 false,所有输出都是黑色的。
我搜索了某个教程或其他内容,然后找到了一个-但它使用了效果。所以我的问题很简单-我必须在SharpDX中使用技巧和效果吗?没有其他方法可以进行简单的混合吗?

I'm trying to get the "SharpDX.Direct3D11.DeviceContext.OutputMerger.Blendstate" to work. Without this, i have nice scene (Polygones with textures on it, for a Spaceshooter). I've done OpenGL Graphics in the past three years, so i thought it might be as simple as in OpenGL - just enable Blending and set the right Dst/Src Modes. But if i set a new BlendStateDescription, all Output is Black, even if "RenderTarget[x].IsBlendEnabled" is set to "false". I searched for a tutorial or something, and find one - but it uses effects. So my question is simple - do i have to use technique's and effects in SharpDX? No other way left for simple blending?

这就是我所做的:

mBackBuffer = Texture2D.FromSwapChain<Texture2D>(mSwapChain, 0);
mRenderView = new RenderTargetView(mDevice, mBackBuffer);
mContext.OutputMerger.SetTargets(mDepthStencilView, mRenderView);
mContext.OutputMerger.SetBlendState(new BlendState(mDevice, new BlendStateDescription()), new SharpDX.Color4(1.0f), -1);

mContext.OutputMerger.BlendState.Description.RenderTarget[0].IsBlendEnabled = true;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].BlendOperation = BlendOperation.Add;           
mContext.OutputMerger.BlendState.Description.RenderTarget[0].SourceAlphaBlend = BlendOption.One;            
mContext.OutputMerger.BlendState.Description.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;          
mContext.OutputMerger.BlendState.Description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;          
mContext.OutputMerger.BlendState.Description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;           

而且,即使只是简单地做:

And, even if just simply do:

mContext.OutputMerger.SetBlendState(new BlendState(mDevice, new BlendStateDescription()), new SharpDX.Color4(1.0f), -1);
mContext.OutputMerger.BlendState.Description.RenderTarget[0].IsBlendEnabled = false;

输出全是黑色的。.也许我只需要更改像素着色器中的某些内容?

ouput is all black.. maybe i just have to change something in the pixel shaders?

推荐答案

Direct3D11中的所有资源都是不可变的,因此在创建新的Blendstate(mDevice,new BlendStateDescription())时,无法更改稍后说明。
正常的工作流程是:

All resource in Direct3D11 are immutable, so when you are creating the new Blendstate(mDevice, new BlendStateDescription()), you cannot change the description later. The normal workflow is:


var blendDescription = new BlendDescription();
blendDescription.RenderTarget[0].IsBlendEnabled = .. // set all values 
[...]
var blendState = new BlendState(device, blendDescription);
context.OutputMerger.SetBlendState(blendState, ...);

资源对象也需要存储在某个地方,并在它们完全用完后处置(大多数情况下是blendstates)

Also resource objects need to be stored somewhere and disposed when you are completely done with them (most of the time for blendstates, at the end of your application), otherwise you will get memory leaks.

我建议您在不确定API使用情况的情况下,仔细研究一些Direct3D11 C ++示例。另外,我建议您阅读Frank.D.Luna所著的《 DirectX 11 3D游戏编程入门》一书,非常适合开始和学习Direct3D11 API。

I advice you to look more closely at some Direct3D11 C++ samples when you are not sure about the API usage. Also, I recommend you to read a book like "Introduction to 3D Game Programming with DirectX 11" by Frank.D.Luna which is perfect to begin and learn the Direct3D11 API.

这篇关于SharpDX:启用BlendState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆