How to use GPU module to render camera to rectangle?

You can modify the texture coordinate and use to sample the texture and create a mask, it’s possible to pass the position and size of the square/rectangle (in pixels) as a vec4 uniform.
When testing, I kept getting a black texture, turns out it when scaling down the texture, it was trying to access the mipmaps, which appear to be enabled but not set. To avoid this, I used .capsize on the source to limit the size to that of the rectangle.

    # draw square/rectangle, in pixels
    rect = [25, 15, 250, 250] # left, bottom, width, height
...
    bge.tex.source.capsize = rect[2:4]
...
    filter.setUniform4f('rect', *rect)

rtt_test_with_filter1.blend (835.9 KB)

2 Likes