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

Author Topic: Shader Problems.  (Read 6647 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Shader Problems.
« Reply #15 on: July 29, 2015, 01:14:07 pm »
Looks good!

The only problem I see with it is that the atmosphere should also be in shade.

My (slightly hacky) solution for the shadow would have been to create a radial gradient from white (inner) to black and use it as a blend mask, multiplying as you draw. Just offsetting that mask would change where the shadow was.
This would only work for when there is a majority of light. When there is a majority of shadow, the opposite would need to be done (radial black inner to white outer). Maybe it's possible to combine the two...
« Last Edit: July 29, 2015, 01:17:13 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Valleriani

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Shader Problems.
« Reply #16 on: July 29, 2015, 09:40:12 pm »
Would that involve using two circles with two different shaders? I am not 100% sure I follow on that. I would assume I would set the blend mode then to mix. There might be a way to mix the two as well, I am unsure yet. Will need to do some trial and error.

Updated an example of what I did. I am using one extra circle so far but at the moment you can kind of see the second circle on the right side so I am guessing I am doing something wrong.. Not sure if this is what you meant but there is issues with it blending atm.
« Last Edit: July 30, 2015, 12:52:52 am by Valleriani »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Shader Problems.
« Reply #17 on: July 30, 2015, 04:23:14 am »
That looks quite pretty  ;D

You're right, though; there is a hard edge on one side of a circle.
If you're using the radial gradient to overlay the shadow, make the object larger. They gradient shader itself takes window co-ordinates so it doesn't care where your shape is or how large it is, just as long as it's where it wants to draw (see the rectangle in the shader example).

I'm confused as to even what I was saying now so I've thrown together a few images to help say what I'm currently thinking.

Using a black circle with gradient edge, we can create crescents as in your picture. This would be done like so:

Here's the circle in (faded) red so you can see what I multiplied:


If you wanted to create a gibbous, which is the opposite, you need the opposite gradient like so:

Again, here's the same thing in red:

Or, instead of multiplying the ring in black, you can multiply the circle (the red on from the second picture earlier) in white.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Valleriani

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Shader Problems.
« Reply #18 on: July 30, 2015, 02:31:04 pm »
How do you set the blend mode properly to Multiply? When I do it I am doing something like this


   sf::RenderStates state;
   state.shader = &m_planetShadowShader;
   state.blendMode = sf::BlendMultiply;
   state.transform = sf::Transform::Identity;

But it's not working properly. The alpha ends up not being transparent, instead it becomes black.


Here is some other coding as well:

   m_planetshadowsphere.setRadius(275);
   m_planetshadowsphere.setFillColor(sf::Color::Transparent);
   m_planetshadowsphere.setOrigin(m_planetatmosphere.getRadius(), m_planetatmosphere.getRadius());
   m_planetshadowsphere.setPosition((window.getSize().x / 2) - 40.f, (window.getSize().y / 2) - 40.f);

   m_planetShadowShader.loadFromMemory(Vertex, RadialGradient);
   m_planetShadowShader.setParameter("color", 1.f, 0.f, 0.f, 0.2f);
   m_planetShadowShader.setParameter("center", m_planetshadowsphere.getPosition());
   m_planetShadowShader.setParameter("radius", m_planetshadowsphere.getRadius());
   m_planetShadowShader.setParameter("expand", 0.0f);

and being drawn as

   window.draw(m_planetshadowsphere, state);
« Last Edit: July 30, 2015, 02:37:21 pm by Valleriani »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Shader Problems.
« Reply #19 on: July 30, 2015, 04:07:44 pm »
If you're using multiple, don't use red and transparent black (remember that sf::Color::Transparent is in fact black with zero alpha); it would be better to use white (for parts you want to keep) and black (for parts that should turn black) and greys for the parts in between.
Basically, if you're multiplying a radial gradient shader, you could create a black rectangle the size of the window and place the white gradient where you want to appear. Conversely, you could create a white rectangle and place the black gradient where you want to remove.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Valleriani

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Shader Problems.
« Reply #20 on: July 30, 2015, 05:32:53 pm »
Ahh! Yeah, my mistake. Okay, will give that a shot then! Thanks!