Skip to main content
GameDev.net gamedev.net
🔒 Locked

Drawing 2D shadows with "pure" SDL2

Started by Polas22 Apr 15, 2014 at 12:35 PM 6 replies 5.7k views
Original Post
Polas22
Polas22

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)

Phil123
Phil123

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.

Polas22
Polas22

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.

ultramailman
ultramailman

Nice. Are you using surfaces for the shadows?

Polas22
Polas22

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.

ultramailman
ultramailman

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.

Alundra
Alundra

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.

Polas22
Polas22

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.