Can I access the render screen size in a custom filter 2D in the game engine? I am using Blender Game Engines Filter 2D to make a post effect with GLSL.
In an fragment shader applied on the frame buffer, I want to access the size in pixels of that buffer in GLSL.

uniform vec2 screensize;


This is possible for objects of the type BL_Shader

shader.setUniform2f("screensize", w, h)


The viewport size can be accessed in this way

import bge

w = bge.render.getWindowWidth()
h = bge.render.getWindowHeight()

print (w,h)


But I don't know how to get the BL_Shader object. The SCA_2DFilterActuator does not have any reference to such object.

co = bge.logic.getCurrentController()
distortion = co.actuators["riftDistortion"]
All the game properties stored in the object that calls the Filter 2D are passed to the shader as uniforms. So if you have a width and a height float game properties you can set their values at run-time to match the window size.

However, be aware that the window size (which you get from render.getWindowWidth() or render.getWindowHeight()) is not the buffer size. The buffersize is the closest power of two for that dimension (e.g., a window that is 1024 x 768 will have as buffers 1024 x 1024).