我的场景中有很多相邻的圆圈(白色圆圈和不同颜色的圆圈)。我只想模糊白色圆圈。(在我的情况下,白色表示 (1,1,1)。)
我的问题是:我应该如何仅使用片段着色器来选择和模糊白色片段?
我想在 GLSL 中做这样的事情:
if (my_current_fragment's_color == white)
{blur current fragment;}
else
{do not blur current fragment}
(我有一个有效的模糊效果,但它不恰当地模糊了整个场景,因为我无法根据片段的颜色在我的代码中做出决定。)
我该怎么做?上述代码在 GLSL 语言中的精确匹配是什么?如何确定片段的颜色是否为白色?你们有什么想法吗?
如果您可能需要,这是我的代码:
vertexShader: [
//"#define KERNEL_SIZE 25.0",
"uniform vec2 uImageIncrement;",
"varying vec2 vUv;",
"void main() {",
"vUv = uv - ( ( KERNEL_SIZE - 1.0 ) / 2.0 ) * uImageIncrement;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join("\n"),
fragmentShader: [
//"#define KERNEL_SIZE 25",
"uniform float cKernel[ KERNEL_SIZE ];",
"uniform sampler2D tDiffuse;",
"uniform vec2 uImageIncrement;",
"varying vec2 vUv;",
"void main() {",
"vec2 imageCoord = vUv;",
"vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );",
"for( int i = 0; i < KERNEL_SIZE; i ++ ) {",
"sum += texture2D( tDiffuse, imageCoord ) * cKernel[ i ];",
//THE ABOVE LINE SHOULD BE RUN FOR WHITE FRAGMENTS ONLY. BUT HOW?
"imageCoord += uImageIncrement;",
"}",
"gl_FragColor = sum;",
"}"