Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering lots of pixels 1 by 1 ?


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
15 replies to this topic

#1 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 10 April 2012 - 12:44 AM

Hi.

I need to do a couple of heavy writes pixel by pixel and i was wondering which could've been the most efficient approach , since from what i read draw/readPixels functions are deprecated and not supported by GLES which i eventually plan to port my code to.

Any recommendations on how to handle this case?

Sponsor:

#2 RobinsonUK   Members   -  Reputation: 108

Like
0Likes
Like

Posted 10 April 2012 - 01:10 AM

Shader? :-).

#3 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 10 April 2012 - 01:29 AM

Shader? :-).


Its a part of a particle system effect which i update every frame.
IIRC i'll have to set the position for the shader uniform(?) variable every frame to achieve this which will be very slow.

#4 mhagain   Crossbones+   -  Reputation: 8279

Like
1Likes
Like

Posted 10 April 2012 - 02:14 AM

Setting a uniform every frame isn't going to be slow. Can you describe in more detail exactly what you're doing? There are many potentially good approaches but without the full info it's hard to give you direction.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 10 April 2012 - 02:35 AM

Can you describe in more detail exactly what you're doing?


I have a 2d map , and im doing some effects to pixel level.ie if you destroy a part of the map , that particular part will be split into smaller particles for a small amount of time.

And the problem is that some parts are very big(512x512) that cause everything to run at 20fps from 1000(!) for a small amount of time.

Setting a uniform every frame isn't going to be slow

Are you sure that setting a uniform forevery particle every single frame won't cause a bottleneck?

#6 SimonForsman   Crossbones+   -  Reputation: 6306

Like
1Likes
Like

Posted 10 April 2012 - 02:41 AM

Hi. I need to do a couple of heavy writes pixel by pixel and i was wondering which could've been the most efficient approach , since from what i read draw/readPixels functions are deprecated and not supported by GLES which i eventually plan to port my code to. Any recommendations on how to handle this case?


The best way would probably be to make a texture the size of your framebuffer, keep one copy of it in RAM and one on the GPU, make the changes to the in RAM texture and then update the texture on the GPU ( using http://www.opengl.or...xSubImage2D.xml ) Updating the texture is fairly slow so you don't want to do it once per pixel, make all the changes first, mark the changed regions as dirty and only update the dirty regions. (you'll need to decide how to create the regions, one region per changed pixel will be extremely slow but if you have 1 pixel in the top left corner and one in the bottom right that is changed you probably don't want to put them in the same region as that region would become incredibly large)

Now since you are making a particle system you might want to consider increasing the size of the particles, reducing their numbers and just setting uniforms for them instead.

If you do need an insane number of particles then you pretty much have to run the entire particle simulation on the GPU (to avoid the transmission costs)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 10 April 2012 - 03:07 AM

Hi. I need to do a couple of heavy writes pixel by pixel and i was wondering which could've been the most efficient approach , since from what i read draw/readPixels functions are deprecated and not supported by GLES which i eventually plan to port my code to. Any recommendations on how to handle this case?


The best way would probably be to make a texture the size of your framebuffer, keep one copy of it in RAM and one on the GPU, make the changes to the in RAM texture and then update the texture on the GPU ( using http://www.opengl.or...xSubImage2D.xml ) Updating the texture is fairly slow so you don't want to do it once per pixel, make all the changes first, mark the changed regions as dirty and only update the dirty regions. (you'll need to decide how to create the regions, one region per changed pixel will be extremely slow but if you have 1 pixel in the top left corner and one in the bottom right that is changed you probably don't want to put them in the same region as that region would become incredibly large)

Now since you are making a particle system you might want to consider increasing the size of the particles, reducing their numbers and just setting uniforms for them instead.

If you do need an insane number of particles then you pretty much have to run the entire particle simulation on the GPU (to avoid the transmission costs)


Oh wow those sound really great ideas , thanks ! ..Now atleast i've got something to try out Posted Image

#8 mhagain   Crossbones+   -  Reputation: 8279

Like
1Likes
Like

Posted 10 April 2012 - 03:17 AM

Are you sure that setting a uniform forevery particle every single frame won't cause a bottleneck?


Well you didn't say that first time round. Posted Image
But yeah, that will be slow.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 RobinsonUK   Members   -  Reputation: 108

Like
1Likes
Like

Posted 10 April 2012 - 07:36 AM

Are you sure that setting a uniform for

every particle every single frame

won't cause a bottleneck?


I'm kind-of wondering why this parameter needs to be a uniform at all. Perhaps it could be an element in your or a vertex stream?

#10 Cornstalks   Crossbones+   -  Reputation: 6991

Like
2Likes
Like

Posted 10 April 2012 - 10:02 AM

Yeah, if I were you I'd be using attributes, not uniforms.

I'd use the vertex shader to position the particles (just draw each particle as a triangle or a quad). Then if post processing was needed I'd use the fragment shader.

But of course, I might be drawing a different particle effect than you. So far you haven't described what kind of particle effect you're implementing, and some effects may be better implemented in different ways than other effects.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#11 mhagain   Crossbones+   -  Reputation: 8279

Like
2Likes
Like

Posted 10 April 2012 - 10:27 AM

I'd use the vertex shader to position the particles (just draw each particle as a triangle or a quad). Then if post processing was needed I'd use the fragment shader.


This is more or less the way I'd do it too (the only thing I might change would be to add a geometry shader for the initial positioning and expand to a quad from there, but admittedly this won't fit with the requirement to move to GL ES).

The way I'd then set it up would be to calculate a bunch of properties for each particle in an emitter when the emitter is spawned; these might include initial position, velocity, direction, gravity, etc. They're stored out as vertex attributes one-time only here. Then for each emitter you would send a delta between the time now and the time when it was spawned as a uniform, using a combination of this delta and the properties (i.e. vertex attribs) to determine the particles current position. That should work well enough if you're not doing anything too fancy with them.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#12 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 11 April 2012 - 01:30 AM

I have implemented the buffer texture and it improved speed by over 40.00% which is great.There is a little flickering though but
i think that i will improve it over with a shader effect;)

I'm kind-of wondering why this parameter needs to be a uniform at all. Perhaps it could be an element in your or a vertex stream?


But of course, I might be drawing a different particle effect than you. So far you haven't described what kind of particle effect you're implementing, and some effects may be better implemented in different ways than other effects.


Some particle effects that i need , are :

-Building explosions
-Power up type that follow the player
-Item pick up type that follow the player

And i don't think that using a shader is a good idea , unless of course if its possible to texture map points(gl_points) since then i would
need 1point/particle and my vertice array would have 1/6 or 1/4 the size of my old implementation(1quad or 2tris / texture) (Would work with GLES too!) or not use vertices at all and use a client side array if that's possible?

#13 RobinsonUK   Members   -  Reputation: 108

Like
1Likes
Like

Posted 11 April 2012 - 01:44 AM

Instancing might help. At least it will cut down the number of draw calls. Have a google for it.

#14 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 11 April 2012 - 02:53 AM

Instancing might help. At least it will cut down the number of draw calls. Have a google for it.


Very interesting but won't work with GLES unless there are portable implementations.

#15 mhagain   Crossbones+   -  Reputation: 8279

Like
1Likes
Like

Posted 11 April 2012 - 04:52 AM

There's a GL_OES_point_sprite extension which may be available, and looks like it can coexist relatively peacefully with regular point sprites. Personally I'd still just use textured quads, at least initially, and not worry too much about size of geometry and/or vertex shader ops until such a time as I had determined for certain that it would be a problem. Reason why is because in a particle system your primary bottleneck is far more likely to be fillrate, so focussing on the other stuff is a case of micro-optimizing something that probably isn't even a huge problem to begin with.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#16 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 11 April 2012 - 06:34 AM

There's a GL_OES_point_sprite extension which may be available, and looks like it can coexist relatively peacefully with regular point sprites. Personally I'd still just use textured quads, at least initially, and not worry too much about size of geometry and/or vertex shader ops until such a time as I had determined for certain that it would be a problem. Reason why is because in a particle system your primary bottleneck is far more likely to be fillrate, so focussing on the other stuff is a case of micro-optimizing something that probably isn't even a huge problem to begin with.


Thanks i'll have a look.
Posted Image




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