本文介绍了我需要在Windows Phone 8中进行混合的紧急帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C ++编写WP8的游戏引擎,但是在混合时遇到了一些非常烦人的问题.

I am writing a game engine for WP8 in C++, but have run into some pretty annoying problems with blending.

1.我的纹理具有Alpha通道.我希望标记为透明的部分(在Alpha通道中为黑色)是透明的,而不要使用清晰的颜色...

1. My textures have alpha channels. I want the parts that are marked as transparent (black in the alpha channel) to be transparent and not use the clear color...

2.我的精灵可以分配不同的透明度,因此事物可以淡入和淡出.

2. My sprites can have different amounts of transparency assigned to them, so things can fade in and out of view.

这里的代码:

// Creating blend state
D3D11_BLEND_DESC blendDesc;
ZeroMemory(&blendDesc, sizeof(blendDesc));
blendDesc.RenderTarget[0].BlendEnable = true;
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;

-------------------------------------------

// Using blend state in rendering
const float blendFactor[] = { 0, 0, 0, 0 };
this->Context->OMSetBlendState(this->BlendState, blendFactor, 0xffffffff);

-------------------------------------------

// The Pixel Shader
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);

struct PixelShaderInput
{
	float4 pos : SV_POSITION;
	float4 color : COLOR0;
	float2 tex : TEXCOORD0;
};

float4 main(PixelShaderInput input) : SV_TARGET
{
	float4 diffuse = Texture.Sample(Sampler, input.tex);
	return (diffuse * input.color);
}

--------------------------------------------

问题:

-纹理的完全透明的部分以透明颜色而不是透明的颜色呈现,因此无法覆盖多个精灵.

如何获得具有正确透明度的纹理?除了blendstate之外,我只使用了samplerstate.没有深度模具状态或其他任何内容.

How do I get the textures to be rendered with correct transparency? I am using only a samplerstate apart from the blendstate. No depth stencil state or anything else.

推荐答案

我使用DirectX Toolkit中的DDS Loader类加载它们.

I load them using the DDS Loader class from the DirectX Toolkit.


这篇关于我需要在Windows Phone 8中进行混合的紧急帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:27