将像素着色器应用于模型时的不可见边缘

时间:2015-09-07 09:47:31

标签: graphics directx shader hlsl pixel-shader

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

enter image description here

在图片编号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);
}

1 个答案:

答案 0 :(得分:1)

这是因为您在整个表面上设置了相同的颜色,而不考虑法线影响。如果要在左侧复制图片,则必须查看lambert和phong着色模型。这有点复杂。

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

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