• Advertisement
Sign in to follow this  

Drawing 2D shadows with "pure" SDL2

This topic is 1373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As the title say I want to draw 2d shadows only unsing sdl2 without openg, I have done it but the performence isnt the best,
I get like from 300fps+ to 90fps+ with 17 rectangles.

 

video:

Pc Spec:
Cpu i3-3110M
Gpu Nvidia 630M

Render everything in: 1280x720

 

when I get low fps My shadow drawing algorithm call 300+ drawing call to draw shadow for every object thats is on the screen;

to draw shadows I use triangles(still rectangle just the texture is triangle) and few rectangles pic:

xi7ayWi.png?1?5724

 

In the code I calculate the position from the mouse to the rectangle ant how much should the shadow go until it reaches the screen end,the calculation doesnt hit much in performence, but the drawing is just killing everything, I need somehow to lower the drawing calls.

 

Does anybody know any better way to draw without OpenGL?

 

Some tutorials that I saw draw the light itself, but I dont know how would I do it with out OpenGL for triangle drawing.

 

 

 

 

 

 

//EDIT:

Added source and executable (you can compile the code on android too)

 

Share this post


Link to post
Share on other sites
Advertisement

I don't have a solution for you but I'd love to see how you're currently doing it if you're interested in posting the source code.

Share this post


Link to post
Share on other sites

I don't have a solution for you but I'd love to see how you're currently doing it if you're interested in posting the source code.

Will do it, but its very bruteforce way(found a way to improve it), will post everything and try to add little comments in the code.

Share this post


Link to post
Share on other sites

Nice. Are you using surfaces for the shadows?

Well no, I use textures, will optimise the code later by drawing on the texture the shadows and only then render them.

Share this post


Link to post
Share on other sites

I see. I asked that because I remember something about textures being stored in hardware, and modifying them takes longer than modifying surfaces. But if you are not creating textures every frame, then never mind.

Share this post


Link to post
Share on other sites

I see. I asked that because I remember something about textures being stored in hardware, and modifying them takes longer than modifying surfaces. But if you are not creating textures every frame, then never mind.

Here the table of speed :

 

  CPU<->GPU = 1 GB/s
  CPU<->RAM = 10 GB/s
  GPU<->VRAM = 100 GB/s

 

I wonder the difference of FPS using compute shader.

The good point using compute shader is you never lock/unlock but if you need info you will have to lock/unlock the texture data.

Share this post


Link to post
Share on other sites

I take my words back the performance is really good, tried to draw like 60 small objects and get 2000+ draw calls the performance didnt drop below 60fps, it seems the more i draw the less the performence is impacted, if i add even more objects and draw more shadows, then the performence bearly drop.

 

Tested with 100 small object and I get nearly perfect 60, so if I make good level designe, the performence will be excellent always.

Edited by PauliusM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement