GLSL-仅模糊红色通道



所以,我在GLSL中有这两个函数。一种通过其rgb通道分割纹理,然后单独置换它们的方法。还有一个只是模糊了纹理。我想把它们结合起来。但我希望能够只模糊通道的位移。例如,我可能想模糊rgbShift函数中的红色通道。

问题是,红色通道是一个单独的浮动,模糊函数需要一个完整的采样2D图像,这样它就可以应用UV和其他东西。我想我需要一种方法来模糊一个浮动?我对GLSL不是很有经验,我已经想了好几天了。我会非常感谢你的任何建议。

GLSL功能如下所示。

vec4 blur5(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 offset = (vec2(1.3333333333333333) * direction) / resolution;
color += texture2D(image, uv) * 0.29411764705882354;
color += texture2D(image, uv + offset) * 0.35294117647058826;
color += texture2D(image, uv - offset) * 0.35294117647058826;
return color;
}
vec3 rgbShift(sampler2D textureimage, vec2 uv, float offset) {
float displace = sin(PI*vUv.y) * offset;
float r = texture2D(textureimage, uv + displace).r;
float g = texture2D(textureimage, uv).g;
float b = texture2D(textureimage, uv + -displace).b;
return vec3(r, g, b);
}

我大声思考:

我想我想做这样的事情:

vec4 blurredTexture = blur5(textureImage);
float red = texture2D(blurredTexture, uv + displace).r;

或者这个:

float redChannel = texture2D(blurredTexture, uv + displace).r; 
vec4 blurredRedChannel = blur5(redChannel );

但两者都不起作用,因为我不知道如何转换类型。我需要将模糊的vec4转换为rgbShift函数的sample2D。或者红色通道浮动到模糊函数的sample2D中。是否有可能以某种方式将值转换为sample2D?

也许我需要一些其他的解决方案,我根本不需要转换sample2D。

是否可以以某种方式将值转换为sample2D?

有点。您需要将该值写入临时纹理。然后可以绑定该纹理并运行第二次过程,该过程将从该纹理采样。对于你试图做的简单过滤来说,这可能是一种过度的做法

也许我需要一些其他的解决方案,我根本不需要转换sample2D。

一个更简单的解决方案是将这两个功能合并为一个:

vec3 shiftAndBlur(sampler2D image, vec2 uv, float offset, vec2 resolution, vec2 direction) {
vec2 offset = (vec2(1.3333333333333333) * direction) / resolution;
float displace = sin(PI*vUv.y) * offset;
float r = texture2D(image, uv + displace).r * 0.29411764705882354
+ texture2D(image, uv + displace + offset).r * 0.35294117647058826
+ texture2D(image, uv + displace - offset).r * 0.35294117647058826;
float g = texture2D(image, uv).g;
float b = texture2D(image, uv - displace).b;
return vec3(r,g,b);
}

最新更新