Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Drawing 2D shadows with "pure" SDL2


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 PauliusM   Members   -  Reputation: 128

Like
2Likes
Like

Posted 15 April 2014 - 06:35 AM

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)

 

Attached Files



Sponsor:

#2 Phil123   Members   -  Reputation: 693

Like
0Likes
Like

Posted 17 April 2014 - 08:06 AM

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.



#3 PauliusM   Members   -  Reputation: 128

Like
1Likes
Like

Posted 18 April 2014 - 11:20 AM

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.



#4 ultramailman   Prime Members   -  Reputation: 1582

Like
0Likes
Like

Posted 18 April 2014 - 11:33 AM

Nice. Are you using surfaces for the shadows?



#5 PauliusM   Members   -  Reputation: 128

Like
0Likes
Like

Posted 18 April 2014 - 11:59 AM

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.



#6 ultramailman   Prime Members   -  Reputation: 1582

Like
0Likes
Like

Posted 18 April 2014 - 03:24 PM

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.



#7 Alundra   Members   -  Reputation: 891

Like
0Likes
Like

Posted 19 April 2014 - 06:38 AM

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.



#8 PauliusM   Members   -  Reputation: 128

Like
1Likes
Like

Posted 19 April 2014 - 08:38 AM

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, 19 April 2014 - 08:42 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS