crashinvaders / gdx-vfx

libGDX post-processing visual effects
https://crashinvaders.github.io/gdx-vfx
Apache License 2.0
191 stars 25 forks source link

gdx-vfx + Viewports #22

Closed rafaskb closed 1 year ago

rafaskb commented 1 year ago

Heya! I'm having trouble getting gdx-vfx to work with FitViewports in my game, admittedly I don't understand much of viewports, but I tried a bunch of different combinations and made some progress, but not without some issues left.

The issue I'm having is that gdx-vfx doesn't seem to be capturing the correct area of the window when black bars / viewport gutters are present. The more black borders I have, the more offset gdx-vfx renders.

Video

Here's a video that demonstrates the issue: (Note: One of the resize lines in the video says Game.graphics.getWidth/Height, these are identical to Gdx.graphics.getWidth/Height)

https://user-images.githubusercontent.com/2331058/230236935-91fb3456-6094-4e29-a3d0-cad47ac1a97f.mp4

What I tried

As far as I understand there are two places where I can set the viewport in gdx-vfx:

  1. The resize method, and here's where changes seem to affect the input region,
  2. and renderToScreen with parameters. I believe I got these values correct, as the final FBO is being rendered exactly where it should.

I tried to call resize with multiple values, such as the real window dimensions (Gdx.graphics.getWidth/Height), I tried to pass my logical game size (1920x1080), and I also tried to pass the viewport width/height, the viewport values are by far the most accurate ones, resulting in the correct capture size, however there's an offset I can't figure out how to solve.

I appreciate any directions on how to fix this issue, and great job for creating such an amazing library! ♥

rafaskb commented 1 year ago

Solved! The issue was the programmer (also known as me). I was applying the viewport too many times in places I shouldn't have, which was causing the issue. Simply applying the viewport before binding gdx-vfx and before drawing its FBO to the screen fixed the issue.