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

Author Topic: SFML Shader Gradients  (Read 1874 times)

0 Members and 1 Guest are viewing this topic.

SomeWhatHappyDuk

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML Shader Gradients
« on: June 14, 2020, 09:22:05 pm »
I have been working on a dynamic lighting system for my game, I use ray marching to collect points around the screen then generate triangles to make my lightmap but I'm wondering how I can use shaders to make my lightmap transparent and then fade out as it gets further away from my light source. I haven't used shaders before but I hope to learn. Thanks in advance.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Shader Gradients
« Reply #1 on: June 15, 2020, 09:08:51 pm »
If you're comfortable working with triangles (and geometry in general) then you could achieve this without having to use shaders.

If you have, say, a sector (of a circle), this is clearly multiple triangles (since the edge is curved). If they are all have a point in the centre of the circle, you can simply give the light's colour to that point and the same colour with alpha of zero to the other two points. This will create a linear gradient.

If you require more control over the gradient, you can split the sector into multiple "pieces" and create gradients for each part.

Obviously, if they are just triangles instead sectors, there's no need to split.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

unlight

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: SFML Shader Gradients
« Reply #2 on: June 18, 2020, 04:01:01 pm »
That is actually a pretty creative solution..

 

anything