Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Newbie GLSL question  (Read 1241 times)

0 Members and 1 Guest are viewing this topic.

SpacedCowboy

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Newbie GLSL question
« 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:
  • Start off with a background texture of size (X,Y), alpha=0 across all pixels. Call this BG
  • Have a what-the-pc-can-see texture of size (512,512) where alpha values are 255 (= full alpha) at the center, going outwards in a circle for a bit, then tailing off to alpha=0, call this V for visible

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
  • if (x,y) is outside the range of V, the current {r,g,b,a} of BG(x,y)
  • if (x,y) is inside the range of V, the {r,g,b} of BG(x,y) and the max alpha of {V(x,y), BG(x,y)}

 - 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:
  • if (x,y) is outside the range of V, the current {r,g,b,a} of BG(x,y)
  • if (x,y) is inside the range of V, the {r,g,b} of BG(x,y) and the max alpha of {0.5, V(x,y)}

... 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