# 2D Filter glitch

Hello,

I am experiencing a strange situation when creating a 2D filter.
The problem is that when I deform the Texture Coordinate the “offscreen/empty space”, that shoud be Black, gets kind of glitchy.
So, I’m wondering if there is a way to get rid of that.

BUMP
My question seems to be very difficult for anyone to answer

I’m going to guess there’s not enough info to go off of at the moment. Share your entire filter or an example blend file (probably better).

Here’s the filter code. I’m not gonna post the .blend, because I’ts my personal project…
It somulates a old CRT TV, but the problem is in the screen curvature ( vec2 crt(vec2 coord, float blend); ).
The “empty” areas are glitchy as you can see in the image.

This is what is expected (please note the black areas that BGE don’t leave black):

``````
uniform sampler2D bgl_RenderedTexture;
uniform float time;
uniform float power;
uniform bool crt_on;

vec2 crt(vec2 coord, float bend)
{
// put in symmetrical coords
coord = (coord - 0.5) * 2.0;

coord *= 1.1;

// deform coords
coord.x *= 1.0 + pow((abs(coord.y) / bend), 2.0);
coord.y *= 1.0 + pow((abs(coord.x) / bend), 2.0);

// transform back to 0.0 - 1.0 space
coord  = (coord / 2.0) + 0.5;

return coord;
}

vec3 Gamma(vec3 value, float param)
{
return vec3(pow(abs(value.r), param),pow(abs(value.g), param),pow(abs(value.b), param));
}

void main()
{
vec2 texcoord = vec2(gl_TexCoord[0].xy);

if (crt_on)
texcoord = crt(texcoord, power);

vec4 col = texture2D(bgl_RenderedTexture, texcoord);

vec2 uv = 0.5 + (texcoord-0.5) * (0.9 + 0.01*sin(0.5*time));

if (crt_on)
{
col = clamp(col*0.5+0.5*col*col*1.2,0.0,1.0);
col *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y);
col *= vec4(0.7,1.0,0.7,1);
col *= 0.9+0.1*sin(10.0*time+uv.y*1000.0);
col *= 0.97+0.03*sin(110.0*time);

gl_FragColor = col+(col*0.6);
}
else
{
gl_FragColor = col;
}

float feather = 1.2;
float innersize = 0.4;

vec3 vig = vec3(1);
float dist = distance(gl_TexCoord[0].xy, vec2(0.5, 0.5));
vig *= smoothstep(feather, innersize, dist);

gl_FragColor *= vec4(vig, 1.0);
gl_FragColor *= vec4(vig, 1.0);
//gl_FragColor *= vec4(vig, 1.0);

gl_FragColor = vec4(Gamma(gl_FragColor.rgb, 1.2), 1.0);

}

``````

what about making the outside area black? (using a overlay?)

will it inherent the curve?

You could have still posted a simple example blend file, though. If the issue is in the example file, then the problem’s in the script. If the issue’s not there, then you’re missing something in your blend file.

As for the image, you might want to considerably simplify the filter, as it’s not just a CRT curvature filter - it’s something else entirely, like a night-vision filter. This is what coding and bug-fixing is about - if possible, simplify things, rather than adding level upon level to an apparent bug (i.e. is it the crt function? Is it the uv alteration line?).

Finally, I’m not getting that “bug” that you pointed out in my simple example blend file I put together, so there might be something specific to your card that you need to tailor the filter to (i.e. ATI doing something differently from NVidia). What card are you using? Lastly, did you write the entire filter yourself? If not, where did you get it from?

Here is the example.blend
example.blend (462 KB)

I don’t really write this script by myself. I just converted some glsl filters I found through Google searching.
PS: I’ve modified the filter, and the problem persists.

Oh, and there’s one last thing…
The Filter behaves very strange when I run the game standalone.
Only the left and bottom sides are glitchy…

Here, add this after the “vec4 col = …”:

``````
for( int i=0; i&lt;2; i++ ){
if (abs(0.5-texcoord[i]) &gt;= 0.5){
col = vec4(0.0);
}
}
``````

As far as I can tell this is simply a new “bug” in Blender. When Blender reads a coordinate that’s off-screen, it just clips it to the edge of the screen and takes color data from there; thus, it extends the boundaries, as you see there.

This little thing just checks if the coordinate (for X and Y) is off-screen, and, if so, sets the color to black.

the game…River Raid 3d?

amuddypizzaHere, add this after the “vec4 col = …”:
Code:
for( int i=0; i<2; i++ ){
if (abs(0.5-texcoord[i]) >= 0.5){
col = vec4(0.0);
}
}
As far as I can tell this is simply a new “bug” in Blender. When Blender reads a coordinate that’s off-screen, it just clips it to the edge of the screen and takes color data from there; thus, it extends the boundaries, as you see there.

This little thing just checks if the coordinate (for X and Y) is off-screen, and, if so, sets the color to black.

Thanks! Now everything is rendering without ugliness xD