将像素着色器应用于模型时看不见边缘
问题描述:
我目前正在使用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);
}
答
这是因为您沿整个表面设置了相同的颜色,而没有考虑法线的影响。如果要在左侧复制图片,您必须查看lambert和phong着色模型。这有点复杂。
在这里你可以找到一个很好的解释:
https://takinginitiative.wordpress.com/2010/08/30/directx-10-tutorial-8-lighting-theory-and-hlsl/
+0
谢谢,我想我仍然需要学习很多! –
另外,记住颜色值的工作[0,1]范围内。你正在返回255的alpha值 –
@EmilioMartinez是我的错。但我认为它不会改变任何东西,除非它看起来很糟糕 - 如果值大于1,它默认设置为1) –