Accessing "SCREEN" texture in Fragment Shader, for cool effects

Started by
4 comments, last by Thaumaturge 1 year, 11 months ago

Some game engines allow access to the "screen" texture in fragment shaders, which allows for some really cool effects.

For example, GODOT allows this. Having read the documentation, I see it says:

Detect when shaders read from screen texture and automatically copy screen to back-buffer on demand.

I use Libgdx, and would like to do something similar. However, I want to be sure that I'm doing it in the most performant way possible.

Currently, the only way I can think to do this is as follows:

  1. Create an additional two screen-sized FBOs (FBO1, FBO2)
  2. Instead of rendering the game to the screen, render everything to FBO1
  3. When I want to use a shader that needs access to the screen texture, before using the shader, copy FBO1 to FBO2. Pass FBO2 to the shader as a varying.
  4. Finally, render FBO1 to the screen.

However, this seems like rather a lot of extra copying/rendering.

Is there a better way? - for example, is there some way to access the screen buffer itself, so that I don't have to create FBO1, and can then skip step 4?

Advertisement

There may be some more modern ways to do this anymore, but generally yes one of those two things must happen.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

I think that I recall seeing it suggested that one approach is to alternate between two buffers: On one frame, render to buffer one, and use buffer two as a shader-input; on the next frame, render instead to buffer two, and use buffer one as a shader-input; and so on.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

@Thaumaturge Depends what techniques but yes you can use the last frame and the last frames camera matrix to take a texel from current frame into where it was rendered in the previous frame and use that coordinate to lookup where the texel would have been rendered in the prior frame. Depending on how fast the camera is moving or other possibilities, it might not work in all cases.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

dpadam450 said:
Depends what techniques but yes you can use the last frame and the last frames camera matrix to take a texel from current frame into where it was rendered in the previous frame and use that coordinate to lookup where the texel would have been rendered in the prior frame.

I wasn't suggesting anything quite that involved! I was simply saying that one can, I gather, swap buffers each frame such that the previous frame's rendering is available for whatever purpose one has for it in the current frame--even if that purpose is a simple one.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement