SFML community forums

Help => Graphics => Topic started by: SpacedCowboy on February 10, 2016, 07:37:50 pm

Title: Newbie GLSL question
Post by: SpacedCowboy on February 10, 2016, 07:37:50 pm
Hi :)

So, I'm trying to do a fog-of-war effect using GLSL shaders, and wanted some input on the best way to do it in SFML. Here's what I think I'll need:

Basic approach is to write a GLSL shader that renders the visible section of BG to the screen, where the pixel value at screen co-ords (x,y) has its alpha set to

 - I also want to have any previously-visited map pixels at alpha= (say)0.5, so I was planning on subsequently rendering back into BG, vis:

... which ought to mean as I move the PC away, the residual alpha remains in BG, up to a max value of 0.5 (this is arbitrary), so if I move far enough away, it'll be outside of the domain of V, but still somewhat visible - so the player can "remember" where they've been but it also indicates it's not being actively updated.

Now BG is going to be pretty big (say 7680 x 4320), so I don't want to be running this subsequent stage over all of BG every frame if I can help it. Is there a way to render a GLSL program only over a section of the target texture ? Does setting the view do this ?

Also, I'll be using BG as both source and destination - I'm guessing this is ok because you can create an sf::Sprite out of either an sf::RenderTexture or an sf::Texture, and the shader parameters take *sprite.getTexture() as their texture arguments. It'll be two separate renders (one for the background including the alpha > 0.5 values, and one to render the clip-at-0.5 alpha back into BG).
 
If anyone has any better ideas of how to do it, I'm all ears :)

Cheers
   Simon