原文链接:http://tech.it168.com/n/2007-03-29/200703291522292_1.shtml
灰度,在HLSL中使用。
sampler2D Texture0; //采样器
//像素着色器,替换多纹理阶段,纹理混合
//用于处理色彩
//像素是由RGBA四个分量混合的。
//输入的是颜色值,输出的也是颜色值。
float4 PS_Main(float2 texCoord : TEXCOORD0) : COLOR
{
float4 _inColor = tex2D(Texture0, texCoord); //2D采样
float h = 0.3 * _inColor.x + 0.59 * _inColor.y + 0.11 * _inColor.z;
float4 _outColor = float4(h,h,h,1.0);
//float4 grayValue = 0.3 * color.r + 0.59 * color.g + 0.11 * color.b;
return _outColor;
}
该片代码返回的是常量的颜色值。采样后利用灰度公式得到灰度颜色,最后输出像素。