【问题标题】:Invisible edges when applying pixel shader to model将像素着色器应用于模型时不可见的边缘
【发布时间】:2015-09-07 19:14:59
【问题描述】:

我目前正在用 hlsl 开发一个简单的着色器。当光标放在屏幕上的对象上时,我想要实现的是“突出显示”效果。我的问题是,像素着色器无法正常工作:

在图片编号 1 中有一个没有应用任何效果的对象。图片 2 显示了具有效果的对象。

如您所见,边缘不再可见。如何改进我的像素着色器?像素着色器代码:

sampler cubeSampler : register (s0);

struct VertexShaderOutput
{
  float4 Position : POSITION;
  float2 UV : TEXCOORD;
};

float4 main(VertexShaderOutput vertex) : COLOR
{
        float4 color = tex2D(cubeSampler, vertex.UV.xy);
        float value = 0.3f * color.r + 0.59f * color.g + 0.11f * color.b;       //Desaturated hue
        float3 tint = float3(0.26f, 0.37f, 0.67f);                              //Filter color (R: 68, G: 95, B: 173)
        float tintMix = 0.8f;

        float OutputR = tintMix * value * tint.r + (1 - tintMix) * color.r;
        float OutputG = tintMix * value * tint.g + (1 - tintMix) * color.g;
        float OutputB = tintMix * value * tint.b + (1 - tintMix) * color.b;

        return float4(OutputR, OutputG, OutputB, 255);
}

【问题讨论】:

  • 另外,请记住颜色值在 [0;1] 范围内起作用。你在那里返回 255 的 alpha
  • @EmilioMartinez 是的,我的错。但我认为它不会改变任何东西,只是看起来很糟糕 - 如果值大于 1,则默认设置为 1 ;)

标签: graphics directx shader hlsl pixel-shader


【解决方案1】:

这是因为您沿整个曲面设置了相同的颜色,而没有考虑法线影响。如果你想复制左边的图片,你必须看看 Lambert 和 phong 着色模型。这有点复杂。

在这里你可以找到一个很好的解释:

https://takinginitiative.wordpress.com/2010/08/30/directx-10-tutorial-8-lighting-theory-and-hlsl/

【讨论】:

    猜你喜欢
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多