将像素着色器应用于模型时不可见的边缘
Invisible edges when applying pixel shader to model
我目前正在 hlsl 中开发一个简单的着色器。当光标放在我屏幕上的对象上时,我想要实现的是 'highlight' 效果。我的问题是,像素着色器无法正常工作:
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/
我目前正在 hlsl 中开发一个简单的着色器。当光标放在我屏幕上的对象上时,我想要实现的是 'highlight' 效果。我的问题是,像素着色器无法正常工作:
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/