为自定义ShaderEffect创建黑色滤镜 [英] Creating a black filter for a custom ShaderEffect
问题描述
我正在使用此代码示例调整WPF应用程序在BitmapImage上的亮度和对比度. HLSL代码的相关位是这样的:
I am using this code example to adjust brightness and contrast on a BitmapImage for my WPF app. The relevant bit of HLSL code is this:
sampler2D input : register(s0);
float brightness : register(c0);
float contrast : register(c1);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color = tex2D(input, uv);
float4 result = color;
result = color + brightness;
result = result * (1.0+contrast)/1.0;
return result;
}
我想做的是添加一些东西来滤除低强度像素-这个想法是我想说图像的任何部分(我只是猜测我必须对每个像素执行此操作)都在一定的阈值,使其变黑.我正在尝试滤除灰色的低强度材料,以使较亮的部分弹出得更多(这是灰度图像).然后,我将使用滑块来调整该阈值.
What I would like to do is add something to filter out low intensity pixels- the idea is that I want to say that any part of the image (I'm just guessing I have to do this per pixel) is below a certain threshold, make it black. I'm trying to filter out greys a low intensity stuff to make the lighter parts pop out more (this is a greyscale image). I would then use a slider to adjust that threshold.
我只是不知道这是一个过滤器还是什么,原本希望它只是上面代码的简单mod.总计HLSL为n00b.
I just have no idea if this is a filter or what, was was hoping it's just a simple mod to the code above. Total n00b to HLSL.
推荐答案
尝试一下:
sampler2D input : register(s0);
float threshold : register(c0);
float4 blankColor : register(c1);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color = tex2D(input, uv);
float intensity = (color.r + color.g + color.b) / 3;
float4 result;
if (intensity < threshold)
{
result = blankColor;
}
else
{
result = color;
}
return result;
}
这篇关于为自定义ShaderEffect创建黑色滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!