【发布时间】:2018-11-30 22:36:10
【问题描述】:
在 MonoGame 中,我有一个具有两种输出颜色的像素着色器。
第一个是绘制到标准 4 通道 32 位颜色渲染目标的常规颜色。
第二个是绘制到 1 通道 16 位 HalfSingle 渲染目标的 z-index。
我想对第一种颜色进行 alpha 混合,而不是在 z-index 上。
有没有办法在不为底层纹理声明采样器并手动进行 alpha 混合的情况下做到这一点?
matrix WorldViewProjection;
Texture2D SpriteTexture;
sampler2D SpriteTextureSampler = sampler_state
{
Texture = <SpriteTexture>;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
float2 depth : TEXCOORD1;
};
struct PS_OUTPUT
{
float4 color : COLOR0;
float4 depth : COLOR1;
};
VertexShaderOutput SpriteVertexShader(float4 position : POSITION0, float2 float4 color : COLOR0, float2 texCoord : TEXCOORD0)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.Position = mul(position, WorldViewProjection);
output.Color = color;
output.TextureCoordinates = texCoord;
output.depth.x = position.z;
return output;
}
PS_OUTPUT SpritePixelShader(VertexShaderOutput input) : COLOR
{
PS_OUTPUT output = (PS_OUTPUT)0;
float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates) * input.Color;
output.color = color;
output.depth.x = input.depth.x;
return output;
}
technique SpriteDrawing
{
pass P0
{
VertexShader = compile vs_2_0 SpriteVertexShader();
PixelShader = compile ps_2_0 SpritePixelShader();
}
};
【问题讨论】:
-
您能否澄清一下“我想在第一种颜色上进行 alpha 混合,而不是在 z-index 上。”我了解第一种颜色,但是,我不明白接下来的内容。你打算混合什么?
标签: xna shader monogame hlsl alphablending