I have about 150 sprites in the scene and the half of them are static and share the same sprite. Now what happens here is that I get about 50 draw calls along with the gui elements and my main camera which draws those sprites cannot draw them without decreasing the performance. I get about 38 fps when I'm supposed to get at least 59 and boy, isn't it significant. The profiler indicates that Main camera has a hard time drawing "Render.TransparentGeometry" which breaks down to 3 more elements, the one with the hightest percentage says "RenderForwardAlpha.Render".
I'm guessing it's because %30 of each sprite is transparent? If that's the case how can I fix it? I mean this engine is not that weak I know there's a way to solve it.
It's probably a good idea to look at atlasses in Unity's "Sprite Packer" to help reduce draw calls: http://docs.unity3d.com/Manual/SpritePacker.html
Related
Ive wrote a simple 3d dungeon generator using Threejs, but since i use alot of spotlights for torches in the dungeon im starting to get a FPS drop.
I know the light is the problem but before i tackle the light issue, i was thinking it could be possible to optimize the level. The level is made only by using a plane 200x200 with a wall texture. Ive read about instancing, is that what i want in this scenario ? Walls wont move. If they move i can make separate meshes for the moving ones.
For the lights im using LambertMaterial, should be the fastest one, but besides that ive done nothing to improve performance on that matter. Ive tryed to bake the room lights into the textures with this https://github.com/mem1b/lightbaking but failed.
So in the end, Is instancing the aproach to optimize the level polygons ? I read lttle bout it could not fully understand.
Say you have 100 torches distributed on a flat wall. Each one of them pretty much only affects the part of the wall that it's closest to, area wise this would be 1/100th of the wall.
Now what if you divide this wall into a struct wall segment + torch. Instead of giving the global scene all 100 lights, you'd give each light segment a single local light.
Cool, now if you render the entire wall, you get 100 lights at the cost of one... computationally, but you also introduce 100 draw calls instead of one.
Instancing would help here. You could instance your wall segment geometry, and then for each instance set a light attribute instead of a uniform.
This way you could draw 100 lights on 100 light segments in one draw call. This would be much faster than drawing stuff 100 times.
I'm using Unity 4.6 to develop a 2D game. I want to know if having a lot of GameObjects in the scene (out of the camera's sight) has a considerable influence on performance.
For example, is it efficient to make an scrollable list of names (like 1000 of them)? (each one is a GameObject and has a text, a button etc.)
I mask them in a specified area (for example 10 of them are visible at the same time).
Thanks in advance!
Depends on whether or not the objects have visible components. If they do, the engine will draw them even if they are 'off-camera'. A game object by itself has a pretty light load - a tile based game could have thousands in memory. You'll want to toggle the visibility of sprites if you plan on drawing a large number to the scene off-camera. This is where a SpriteManager comes in. It'll check to see if the sprite is in the camera's rectangle and disabled sprites that aren't. There is a semi-offical exmaple here that is good if a little complicated:
http://wiki.unity3d.com/index.php?title=SpriteManager
OpenGL Question:I have something to ask about clip space transformation. I am reading an online tutorial and it says that everything you draw outside the clip space will be clipped. When it come to this, does the elements outside the clip space affects the performance or not? Because it will not be drawn and thus it doesn't affect.
Assuming that it will affect performance and in case of 2d game like super mario, I am thinking about not to draw the elements outside the clip space to achieve better performance. Please clarify. Thanks.
OpenGL has only a certain amount of knowledge about your scene and will clip very late in the pipeline. It can't apply a broad phase test. Assuming you can, you should.
Supposing you had a model with 30,000 triangles, OpenGL would transform each and every one of those 30,000 triangles before considering clipping. If you know something as simple as the bounding sphere for the model it's possible you could see that the whole thing is completely outside of the frustum in a single test and save almost 30,000 extra bits of effort.
In a 2d game like Mario what this usually means is using the scroll position to index into the map and to generate geometry only for potentially visible tiles and sprites that are within the visible area.
For the map that will generally just men figuring out the (x, y) of one corner and then generating geometry for the known width and height of the screen so it means discarding the vast majority of the geometry with zero processing.
For the sprites, this is generally why in those sort of games you often see enemies reset to their starting position if you walk a little way from them and then walk back: they're added to the active list based on a map location trigger and removed when you walk far enough away. While not active, no mutable storage is afforded to them.
I've written a couple of methods in my Quad class to draw quads and also to rotate.
Currently, the draw sprite method does just that - renders the quad to the screen.
However, the rotation method, rotates and also renders the quad.
I've got another couple of methods written, one that just rotates but doesn't render, and another render routine that takes the rotation matrix into account when doing it's matrix multiplications. So, instead of doing this:
Quad sprite = new Quad();
Quad sprite.rotate(0,0,45,mMVPMatrix); //rotate by 45 degrees and render at 0,0
I can do this:
Quad sprite = new Quad();
sprite.rotate(45); //Rotate sprite by 45 degrees
sprite.draw(0,0,mMVPMatrix); //Render sprite at 0,0
Although the latter is somewhat more flexible when writing my main code it does mean that even if I don't want to rotate a sprite, the draw routine, still has to take the rotation matrix and combine it with the projection matrix.
When I have 50+ sprites going, will this cost me? I know there is always a trade-off between 'more code' and 'better performance' but realistically, would this be a huge problem?
Write the code first. Then see if performance is an issue. Far too many things can affect performance for anyone to give you even a hint, especially without any real code (other than the tiny fragment you've posted) to judge by.
Someone else here said that the biggest sin in code development is early optimization. You can spend a lot of time early on optimizing code that never would have been a problem. You can always optimize after the fact and after the fact you'll have actual information about where your bottlenecks are instead of early optimizations that will result in tweaked code that never would have become a bottleneck, but is now less readable because of the optimizations.
I couldn't post the image, but I use the "CGContextDrawRadialGradient" method to draw a shaded blue ball (~40 pixel diameter), it's shadow and to make a "pulsing" white ring around the ball (inner and outer gradients on the ring). The ring starts at the edges of the blue ball and expands outward (radius grows with a timer). The white ring fades as it expands outward like a radio wave.
Looks great running in the simulator but runs incredibly slow on the iPhone 4. The ring should pulse in about a second (as in simulator), but takes 15-20 seconds on the phone. I have been reading a little about CALayer, CGLayer and reading some segments on a some gradient animation, but it isn't clear what I should be using for best performance.
How do I speed this up. Should I put the ball on a layer and the expanding ring on another layer? If so, how do I know which layer to update on a drawrect?
Appreciate any guidance. Thanks.
The only way to speed something like that up is to pre-render it. Determine how many image frames you need to make it look good and then draw each frame into a context you created with CGBitmapContextCreate and capture the image using CGBitmapContextCreateImage. Probably the easiest way to animate the images would be to set the animationImages property of a UIImageView (although there are other options, like CALayer animations).
The newest Apple docs finally mention which pixel formats are supported in iOS so make sure to reference those when creating your bitmap context.