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

Author Topic: [Solved] Sprites and shadow overlapping  (Read 2648 times)

0 Members and 1 Guest are viewing this topic.

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
[Solved] Sprites and shadow overlapping
« on: June 13, 2017, 01:35:57 pm »
Hi,

I have game sprites with shadows like this: (1x texture / 4x sprites)


And during rendering there is classic problem:


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;  
 
« Last Edit: June 23, 2017, 07:45:03 pm by Paul »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprites and shadow overlapping
« Reply #1 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.
Laurent Gomila - SFML developer

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: Sprites and shadow overlapping
« Reply #2 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).
« Last Edit: June 23, 2017, 07:44:38 pm by Paul »

 

anything