Image processing 作为HLSL着色器的外部辉光
我仍在从事一个图像处理项目,该项目利用HLSL着色器添加Photoshop风格的过滤器,如阴影、斜角等等。现在我正在寻找一种在HLSL中实现外部辉光效果的方法 我目前正在试验以下想法: 1) 缩放当前纹理以创建辉光(参数:glowSize,用于设置轮廓的大小) 2) 模糊水平 3) 垂直模糊,将模糊颜色更改为辉光颜色,并在顶部添加原始纹理 我正在使用以下多重过程HLSL着色器渲染光晕:Image processing 作为HLSL着色器的外部辉光,image-processing,directx,hlsl,outline,glow,Image Processing,Directx,Hlsl,Outline,Glow,我仍在从事一个图像处理项目,该项目利用HLSL着色器添加Photoshop风格的过滤器,如阴影、斜角等等。现在我正在寻找一种在HLSL中实现外部辉光效果的方法 我目前正在试验以下想法: 1) 缩放当前纹理以创建辉光(参数:glowSize,用于设置轮廓的大小) 2) 模糊水平 3) 垂直模糊,将模糊颜色更改为辉光颜色,并在顶部添加原始纹理 我正在使用以下多重过程HLSL着色器渲染光晕: float4 PS_Scale(VS_OUTPUT IN) : COLOR0 { float2 tex
float4 PS_Scale(VS_OUTPUT IN) : COLOR0
{
float2 tex = IN.texture0;
float2 scaleCenter = float2(0.5f, 0.5f);
float2 scaleTex = (tex - scaleCenter) * glowSize + scaleCenter;
return tex2D(foreground, scaleTex);
}
float4 PS_GlowH(VS_OUTPUT IN) : COLOR0
{
float2 Tex = IN.texture0;
float4 sum = float4(0.0, 0.0, 0.0, 0.0);
sum += tex2D(secondForeground, float2(Tex.x - 4.0*blur, Tex.y))*0.05;
sum += tex2D(secondForeground, float2(Tex.x - 3.0*blur, Tex.y))*0.09;
sum += tex2D(secondForeground, float2(Tex.x - 2.0*blur, Tex.y))*0.12;
sum += tex2D(secondForeground, float2(Tex.x - blur, Tex.y))*0.15;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y))*0.16;
sum += tex2D(secondForeground, float2(Tex.x + blur, Tex.y))*0.15;
sum += tex2D(secondForeground, float2(Tex.x + 2.0*blur, Tex.y))*0.12;
sum += tex2D(secondForeground, float2(Tex.x + 3.0*blur, Tex.y))*0.09;
sum += tex2D(secondForeground, float2(Tex.x + 4.0*blur, Tex.y))*0.05;
return sum;
}
float4 PS_GlowV(VS_OUTPUT IN) : COLOR0
{
float2 Tex = IN.texture0;
float4 sum = float4(0.0, 0.0, 0.0, 0.0);
sum += tex2D(secondForeground, float2(Tex.x, Tex.y - 4.0*blur))*0.05;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y - 3.0*blur))*0.09;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y - 2.0*blur))*0.12;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y - blur))*0.15;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y))*0.16;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y + blur))*0.15;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y + 2.0*blur))*0.12;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y + 3.0*blur))*0.09;
sum += tex2D(secondForeground, float2(Tex.x, Tex.y + 4.0*blur))*0.05;
float4 result = sum * opacity;
result.rgb = float3(glowColor.r, glowColor.g, glowColor.b) / 255.0f;
float4 src = tex2D(foreground, IN.texture0.xy);
return result * (1-src.a) + src;
}
使用椭圆等简单形状时,此代码的结果看起来正常,但在文本上应用着色器时不起作用:
很明显,缩放存在问题。我不知道如何缩放原始纹理以将其用作轮廓。这可能吗?如何在HLSL中实现外部发光或轮廓过滤器,还有其他想法吗
提前感谢您。您的缩放策略不能应用于这种情况。扔掉缩放步骤,只使用模糊步骤和合成步骤。它会起作用的 让我向您演示模糊着色器如何创建光晕效果 A:有一个原始图像 B:更改图像的颜色,并应用模糊着色器 C:将模糊图像与原始图像合并 如果要控制光晕大小,请使用模糊步长的内核大小,而不是缩放。我使用高斯模糊来创建下面的图像
- 内核大小5
- 内核大小10
- 内核大小15
我上面发布的模糊着色器如何能提供与Photoshop辉光混合选项类似的结果?我的代码已经做到了这一点,但我想不出在不进行缩放的情况下设置辉光大小的方法。我从着色器中获得的光晕是可以的,但是如果没有缩放,它就无法生长…很抱歉回复太晚。我还没看到你更新了答案。