Sunday, October 19, 2008

The Optimization of the Month

There is this character which is composed of about 2200 objects. Most being small gemstones.
Because those gemstones are animated individually, there is no simple way for me to merge all of them into a single object.
So I'm left with about 2000 objects made of 100-200 vertices that at some point are rendered so far away that one can't see them.

I optimized by simply not rendering them if their area is smaller than one pixel 8)

For the area I consider the screen-projected bounding box of an object. It's a it's fast estimate, but it's not the proper way of doing it.

Let's say that I have a wall made of bricks, with each brick being an individual object with its own bounding box.
This wall could be located so far away that the area of each brick would be smaller than one pixel.
In this case, my assumption/optimization would simply not render any of the bricks.. and the the wall would disappear !

The  proper way of rendering the wall, would be to collect all bricks belonging to a pixel and to use the average of the color of every one of those bricks. This is clearly overkill to do in real-time.

The less accurate but more efficient way of rendering the wall, would be to calculate the bounding boxes' extremities as they would get rasterized. Not simply taking the area of a brick's bounding box, but taking the area of the bounding box whose extremities are snapped to the pixel grid at fixed integer intervals.
When snapping those bounding boxes, some would end up collapsing on the same edge giving a 0 area, while some others would snap at opposite edges and conquer a whole pixel worth of screen real-estate.

..now, Imagine if those bricks were actually texels from a texture map. In that case one would obviously use precalculated mip-maps. Very easy, because of the regular nature of texture maps: samples distributed at regular intervals, unlike for polygonal geometry, where samples (vertices) are distributed irregularly in space.

..that's when one starts realizing that rasterizing 2D polygons at every frame doesn't have much of a future.

zzzzzzzzzzzzzzzzzzzzzzzzz

P.S. I wanted to draw something, but it's very hard to draw things by hand, let alone using a computer  ...Sometimes I really miss Deluxe Paint !!

9 comments:

  1. hhmmm sounds like too much artistic freedom there. Give artists a finger and they will take the whole arm!!!

    ReplyDelete
  2. Well, the assets are made for movies to be rendered with MentalRay and RenderMan.

    Those models are sometimes optimized as well: lots of billboards and geometry that has been culled away for a specific shot. Sometimes quite different geometry, shaders and textures just for a specific camera view !

    Those optimizations tend to be based on the rendering time feedback that comes from one renderer and its specific quirks.

    For example in some cases there are objects that could have been instantiated but whose geometry has instead been duplicated because a specific version of Maya at the time would perform worse when too many objects were instanced...

    ..I like the idea to be able to work with messy assets 8)

    ReplyDelete
  3. I just sent you email... but let me copy/paste it here, because I am not sure if you even read emails... probably not!

    Here it is:

    So I went to blogger site MF! And how the fuck can I post on blog?
    fuckyoufuck.wav
    And comments open in popup window? Like from my ass? Geez MF, you have choosen the worst shit ever...

    PS. China unblocked blogger on Great Firewall of China... and I start to regret that :( The worst thing I ever seen

    ReplyDelete
  4. I do read emails 8)

    You can post if I add you as a collaborator, I just did that and you should be receiving an email now.

    Comments in a pop-up window is a feature. I'm using the "draft" version of blogger that should allow to post comments in the same page of the blog post, but that stopped working, so I opted for comments in a pop-up window, which is better than the usual "comments in a separate window" that blogger usually allowed.

    Good to know that China is making steps towards freedom of speech !

    ReplyDelete
  5. yeah those pop-up windows suck.

    makes you feel like a 2nd class citizen!!!

    ReplyDelete
  6. ..sensitive contributors !!
    I did a little research and I found how to enable posting from the same page. A little tweaking required !
    http://www.bloggerbuster.com/2008/06/how-to-add-comment-form-beneath-your.html

    ..followed the "Updated" change where one has to find a line and add another line at the bottom.. tricky !!

    ReplyDelete
  7. "Good to know that China is making steps towards freedom of speech !"

    And I cannot wait to see the comments when they will unblock flickr as well. It'll be something like "Ohhhh, this thing makes a lot more sense with the images..." :)

    ReplyDelete
  8. > Freddy
    Flickr is blocked too ? ..ouch !

    > Paul
    Yet, some people are more equal than others !

    ReplyDelete