【问题标题】:HLSL TextureSampler Color returning whiteHLSL TextureSampler 颜色返回白色
【发布时间】:2014-11-12 05:45:44
【问题描述】:

我正在按照教程在 XNA/Monogame 中构建基本效果纹理。一切似乎都在工作,但如果 Percentage = 0 它总是将颜色返回为白色。我很难弄清楚为什么会发生这种情况。这是相关的hlsl代码

float Percentage;

sampler TextureSampler: register(s0);
float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 Tex : TEXCOORD0) : SV_TARGET0
{
    float4 Color = tex2D(TextureSampler, Tex).abgr;
    float a = Color.a;
    float r = Color.r;
    float g = Color.g;
    float b = Color.b;
    Color.rgb = dot(Color.rgb, float3(0.7 * Percentage, 0.59 * Percentage, 0.11 * Percentage));
    r = r - (r - Color.rgb) * Percentage;
    g = g - (g - Color.rgb) * Percentage;
    b = b - (b - Color.rgb) * Percentage;
    Color.a = a;
    Color.r = r;
    Color.g = g;
    Color.b = b;
    return Color;
}


technique hit
{
    pass Pass1
    {
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}

当我将 argb 设置为 color1.argb 时,它会输出正确的颜色,但它呈现为实心正方形,而不是实际对象(在本例中为圆形)

【问题讨论】:

  • 我已通过将 float4 Color = tex2D(TextureSampler, Tex).abgr; 更改为 float4 Color = tex2D(TextureSampler, Tex).abgr * color1; 来解决此问题
  • 使用答案而不是评论并接受它,因此它不会显示为未解决的问题。

标签: shader hlsl monogame


【解决方案1】:

我已经通过更改解决了这个问题

float4 Color = tex2D(TextureSampler, Tex).abgr; 

float4 Color = tex2D(TextureSampler, Tex).abgr * color1;

【讨论】:

    猜你喜欢
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多