输入量
int p_Width, //图像的宽度
int p_Height, //图像的高度
int p_X, //当前像素的X坐标
int p_Y, //当前像素的Y坐标
//当前输入层的三通道值
__TEXTURE__ p_TexR,
__TEXTURE__ p_TexG,
__TEXTURE__ p_TexB
初始化
float colR = 0.0f;
float colG = 0.0f;
float colB = 0.0f;
float lumR = 0.0f;
float lumG = 0.0f;
float lumB = 0.0f;
STEP1 - 计算当前输出对应坐标所对应的亮度
float y = p_Y / (p_Height - 1.0f);
STEP2 - 求该垂直扫描线上符合条件的像素数量
lumR > 0.005f && lumR (1.0f - y) * 1.005f && lumR + 0.005f > (1.0f - y) * 1.005f ? colR += 0.02f : 0.0f; //容差0.005f
STEP3 - 完整扫描线求解
for (int i = 0; i p_Height; i+=1){
lumR = _tex2D(p_TexR, p_X, i);取得单垂直扫描线上每一个像素的值
lumR > 0.005f && lumR (1.0f - y) * 1.005f && lumR + 0.005f > (1.0f - y) * 1.005f ? colR += 0.02f : 0.0f;
}
STEP4 - 求解其余通道
for (int i = 0; i p_Height; i+=1){
lumG = _tex2D(p_TexG, p_X, i);
lumG > 0.005f && lumG (1.0f - y) * 1.005f && lumG + 0.005f > (1.0f - y) * 1.005f ? colG += 0.02f : 0.0f;
}
for (int i = 0; i p_Height; i+=1){
lumB = _tex2D(p_TexB, p_X, i);
lumB > 0.005f && lumB (1.0f - y) * 1.005f && lumB + 0.005f > (1.0f - y) * 1.005f ? colB += 0.02f : 0.0f;
}
STEP5 - 返回该点的输出像素的值
float r = colR;
float g = colG;
float b = colB;
return make_float3(r, g, b);
效果图
INPUT
OUTPUT