SharpDX 및 SharpDX Toolkit을 사용하여 간단한 3D 도형을 그리는 응용 프로그램에서 작업 중이며 Geometrics.Desktop 샘플은 시작하는 데 매우 유용했습니다. 지금 나는 어떤 모양을 투명하게 만들고, 일을 간단하게하기 위해 나는 그 샘플에서 찻 주전자 모델을 투명하게 보이려고 노력하고 있습니다. (아마도 반투명이 더 정확할 것입니다).SharpDX Toolkit으로 투명한 3D 오브젝트를 그릴 수있는 방법은 무엇입니까?
Geometrics.Desktop 샘플에 익숙하지 않은 사용자를 위해 3D에서 몇 가지 간단한 기본 기하학적 모양을 그립니다. 샘플 앱이기 때문에 매우 간단하므로 SharpDX "Toolkit"라이브러리의 3D 기능을 실험하기에 꽤 좋은 스크래치 패드를 만듭니다.
내가 혼합 할 Direct3D를 준비하기위한 노력의 일환으로, (시작 시간에 한 번 실행)을 LoadContent 방법이 추가되었습니다 다음과 같이
var blendStateDescription = new BlendStateDescription();
blendStateDescription.AlphaToCoverageEnable = false;
blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add;
blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero;
blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
var blendState = SharpDX.Toolkit.Graphics.BlendState.New(this.GraphicsDevice, blendStateDescription);
this.GraphicsDevice.SetBlendState(blendState);
내가 깊이 스텐실을 설정 한 :
var depthDisabledStencilDesc = new DepthStencilStateDescription()
{
IsDepthEnabled = false,
DepthWriteMask = DepthWriteMask.All,
DepthComparison = Comparison.Less,
IsStencilEnabled = true,
StencilReadMask = 0xFF,
StencilWriteMask = 0xFF,
// Stencil operation if pixel front-facing.
FrontFace = new DepthStencilOperationDescription()
{
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Increment,
PassOperation = StencilOperation.Keep,
Comparison = Comparison.Always
},
// Stencil operation if pixel is back-facing.
BackFace = new DepthStencilOperationDescription()
{
FailOperation = StencilOperation.Keep,
DepthFailOperation = StencilOperation.Decrement,
PassOperation = StencilOperation.Keep,
Comparison = Comparison.Always
}
};
// Create the depth stencil state.
var depthDisabledStencilState = SharpDX.Toolkit.Graphics.DepthStencilState.New(this.GraphicsDevice, depthDisabledStencilDesc);
//turn z-buffer off
this.GraphicsDevice.SetDepthStencilState(depthDisabledStencilState, 1);
그리고 Draw 메서드 (프레임 속도로 실행하고 작은 3D 모델 배열을 반복하면서 각각을 그리는)에서 아래 코드를 추가했습니다. 그것은 주전자를 뷰포트의 중심으로 이동시키고 다른 물체의 일부를 가릴만큼 충분히 크게 만듭니다. 주전자는 지난 그려, 그래서 다른 모델은 이미 렌더링 된, 그래서 난 정말이 그들 위에 반투명 주전자를 그릴 것 기대했다 :
// Draw the primitive using BasicEffect
if (i == 6)
{
basicEffect.Alpha = 0.5f;
basicEffect.World *= Matrix.Translation(-x, -y, 0);
basicEffect.World *= Matrix.Scaling(3);
}
else
{
basicEffect.Alpha = 1;
}
primitive.Draw(basicEffect);
(코멘트와의 있었다 부분을 그립니다 최종 호출 원래의 샘플 코드)
그러나 슬프게도, 결과가 다른 개체들 사이에서 큰 불투명 주전자입니다.
는 내가 그 테를 만들기 위해 어떻게해야합니까 투명 한 apot?
내가 누락되었거나 혼합 상태를 잘못 구성 했습니까?
그리고 완벽을 기하기 위해 알파 채널이 50 % 인 이미지로 개체를 텍스처링했지만 여전히 불투명 한 개체가 생성되었습니다.
미리 도움을 청하십시오!
direct3d11을 사용하고 있습니까? * primitive * just * context *가 없기 때문입니다. –
예 D3D11을 사용하고 있지만 큐브, 구, 원통 등과 같은 기하학적 인 의미에서 "프리미티브"라는 단어를 사용하고있었습니다. SharpDX 툴킷에는 이러한 모양을 쉽게 그리는 클래스가 있으며 작업하기 쉽습니다. 대개. 투명하게 만드는 것은 매우 어려웠습니다. – NSFW