Upbge - 2D Filter on only one object?

Pretty simple question

I want to use the custom 2D filter to render in pixels - by Matías Fernández---->Found here

I need it to only affect ONE object in my shot.

I’m guessing this could work by separating the object within the filter code, then rendering the image and subtracting the “mask” from it? Sort of like a bias?

I’m more on the art side, not much a programmer :sweat_smile:

All and any ideas would be a lifesaver <3

// Pixelate 2D Filter by MattFrnndz
// It produces sharp edges, without anti-aliasing effect

// on UPBGE 0.3, uncomment the following line (remove //)
//#define UPBGE3

int pixelSize = 4;


uniform sampler2D bgl_RenderedTexture;

uniform float bgl_RenderedTextureWidth;
uniform float bgl_RenderedTextureHeight;

#ifndef UPBGE3
vec2 texCoord = gl_TexCoord[0].st;
#else
in vec4 bgl_TexCoord;
vec2 texCoord = bgl_TexCoord.xy;
out vec4 fragColor;
#define gl_FragColor fragColor
#endif

void main(void)
{
    float pS = float(pixelSize);
    
    vec2 pixelRes = vec2(bgl_RenderedTextureWidth  / pS,
                         bgl_RenderedTextureHeight / pS);
                         
    float offset = 1.5 / pS;
    
    vec2 pixCoords = vec2((floor(texCoord.x * pixelRes.x) + offset) / pixelRes.x,
                          (floor(texCoord.y * pixelRes.y) + offset) / pixelRes.y);
    
    gl_FragColor = texture2D(bgl_RenderedTexture, pixCoords);
}


(Example Rendered in UpBge with filter)

1 Like

need to pay attention to observe that your picture is crafted by putting next to other with and without the 2d filter → without paying attention one will think u had found the solution …

I had the same wondering … I think 2d filters apply to a specific camera (not sure). So if you have an overlay scene with its own camera (a bit like we usually do for UI’s) you will apply the filter only on the objects in that scene.

So if you want to 2dfilter only 1 character, make sure that that scene has some glass floor to not make him fall down lol

In UPBGE 0.2, a render attachment can be used to create a mask for the desired object(s).


pixelated_render_attachment_mask.blend (105.2 KB)

2 Likes