Three.JS:GLSL着色器中的高斯模糊
我有一个vert/frag着色器,它使用顶点数据和两个纹理 我正在尝试应用后模糊效果,但之后只有矩形 垂直: frag: 在对纹理2D/sampler2D应用模糊之前,我如何“烘焙”所有内容?Three.JS:GLSL着色器中的高斯模糊,three.js,glsl,blur,fragment-shader,texture2d,Three.js,Glsl,Blur,Fragment Shader,Texture2d,我有一个vert/frag着色器,它使用顶点数据和两个纹理 我正在尝试应用后模糊效果,但之后只有矩形 垂直: frag: 在对纹理2D/sampler2D应用模糊之前,我如何“烘焙”所有内容? 也许我需要创建另一个模糊着色器并将texture2D传递给它?PS:我不想使用EffectComposer或RenderPass。您是否尝试过使用不同的分辨率值?此外,您可能希望开始实际接受问题的答案。我使用了不同的分辨率值,是的,我知道gl_FragColor=blur2D(纹理、uv、分辨率.xy
也许我需要创建另一个模糊着色器并将texture2D传递给它?PS:我不想使用EffectComposer或RenderPass。您是否尝试过使用不同的分辨率值?此外,您可能希望开始实际接受问题的答案。我使用了不同的分辨率值,是的,我知道gl_FragColor=blur2D(纹理、uv、分辨率.xy、方向)重写了所有内容,必须以某种方式将中间结果放入纹理/采样器,但是不知道如何使用。PS:我不想使用EffectComposer或RenderPass。您是否尝试过使用不同的分辨率值?此外,您可能希望开始实际接受问题的答案。我使用了不同的分辨率值,是的,我知道gl_FragColor=blur2D(纹理、uv、分辨率.xy、方向)重写了所有内容,必须以某种方式将中间结果放入纹理/采样器,但不知道如何进行。
attribute float type;
attribute float size;
attribute float phase;
attribute float increment;
uniform float time;
uniform vec2 resolution;
uniform sampler2D textureA;
uniform sampler2D textureB;
varying float t;
void main() {
t = type;
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 );
if(t == 0.) {
gl_PointSize = size * 0.8;
} else {
gl_PointSize = size * sin(phase + time * increment) * 12.;
}
gl_Position = projectionMatrix * mvPosition;
}
uniform float time;
uniform vec2 resolution;
uniform sampler2D textureA;
uniform sampler2D textureB;
varying float t;
uniform sampler2D texture;
vec4 blur2D(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.3846153846) * direction;
vec2 off2 = vec2(3.2307692308) * direction;
color += texture2D(image, uv) * 0.2270270270;
color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
return color;
}
void main() {
vec2 direction = vec2(1., 0.);
vec2 uv = vec2(gl_FragCoord.xy / resolution.xy);
gl_FragColor = vec4(vec3(1.0, 1.0, 1.0), 1.);
if(t == 0.){
gl_FragColor = gl_FragColor * texture2D(textureA, gl_PointCoord);
} else {
gl_FragColor = gl_FragColor * texture2D(textureB, gl_PointCoord);
}
gl_FragColor = blur2D(texture, uv, resolution.xy, direction);
}