SFML community forums

Help => Graphics => Topic started by: Paul on June 13, 2017, 01:35:57 pm

Title: [Solved] Sprites and shadow overlapping
Post by: Paul on June 13, 2017, 01:35:57 pm
Hi,

I have game sprites with shadows like this: (1x texture / 4x sprites)
(https://i.imgur.com/kxQDjWz.png)

And during rendering there is classic problem:
(https://i.imgur.com/iIYYYFu.png)

I tried combinations for blending in sf::BlendMode - factor and equation, also without changing alpha color or so but without any results. Is possible solve it simply with blendmode or shaders are needed?

Code for drawing sprites:
procedure spr_Draw_Alpha( renderWindow : PsfrenderWindow; sprite : PsfSprite; x, y : single; alpha : byte; RenderStates : PsfRenderStates = nil );
  var
    pos    : sfVector2f;
    color  : sfColor;
begin
  if not Assigned( sprite ) then exit;

  pos.x := x;
  pos.y := y;

  color.A := Alpha;

  sfSprite_setColor( sprite, Color );
  sfSprite_setPosition( sprite, pos );
  sfRenderWindow_drawSprite( renderWindow, sprite, RenderStates );
end;  
 
Title: Re: Sprites and shadow overlapping
Post by: Laurent on June 13, 2017, 02:35:09 pm
You can draw all your shadows to a transparent sf::RenderTexture (without blending), and then draw the render-texture with classic alpha blending on top of the ground tiles.
Title: Re: Sprites and shadow overlapping
Post by: Paul on June 13, 2017, 03:56:55 pm
Thank you, I will try it.

EDIT:
Well, it's working fine :) And I do not see any measurable difference in performance (tested in 1920 x 1080 pix, render texture have same size).