[project1dev] Re: Roads rendering slowly

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: project1dev@xxxxxxxxxxxxx
  • Date: Thu, 10 Jun 2010 09:19:22 -0700

ok well heres the details lol...

Whenever you render a 3d object, you send vertices with information about
each vertex to the GPU.

The vertex information is stuff like..
  * 3d position
  * texture coordinates (a 2d coordinate that says where this vertex lies on
the 2d image used to texture it)
  * a normal (used for lighting)
  * color of vertex (for tinting)
  * other stuff

anyhow you can also make programs that run on the GPU called shaders.

There are vertex shaders and pixel shaders.

Vertex shaders run once for each vertex in your 3d model

Pixel shaders run once for each pixel in each triangle of your 3d model.

Whats neat is that pixel shaders take as input parameters the outputs of
your vertex shaders. but those parameters are interpolated across the
triangle that the pixel lives on.

Anyhow, as a side note this just means the more that you can do in vertex
shaders instead of in the pixel shader, the better it will run - but this
isn't the cause of our preformance problem :P

Something else though is you have only so much data bandwidth between the
CPU and the GPU so you want to minimize the data you send to the GPU.  That
means if you send too many verts (ie the model is too high poly) it will
slow down the game.  This is essentially what our problem was, but it wasnt
because of models being too high poly, it was a side effect of decals.

In our game, and in a lot of games, how they do decals (bullet holes on
walls, scratches on things, etc) is by re-rendering the model that the decal
is on a 2nd time, and having a special vertex / pixel shader that paints the
decal art onto the model.

In our game our terrain model is what the roads are applied to.

It used to be one big 5500 triangle model so each time you applied a decal
to the world (either by a lightning bolt or a road), it would have to
re-render 5500 triangles.

I helped this by making the game chop the terrain into an 8x8 grid so that
on average each terrain tile only had like 350 triangles instead of 5500.

This made it so a decal only needed to re-render the tiles that it actually
affected, instead of the full 5500 tiles.  This really sped up the game
quite a bit.

However!  There are a lot of roads, and most of the roads reside on more
than one terrain tile.

This means that there is a TON of re-drawing of terrain tiles.. some are
re-drawn like 10 times each just to paint all the decals, which is a lot of
vertices to send to the GPU again, and a lot of verts for the GPU to process
again (and run vertex and pixel shaders on).

My fix is going to be to make it so for decals that stick around a long time
(such as these roads) that they are actually going to craft their own models
that have only the verts on them that actually matter to the decal (ie only
the triangles that the decal actually paints on to).

This will make it so that decals use a lot less triangles to render
themselves, and have to re-process a lot less of the screen (that's also a
performance problem) and it should render WAY fast again.

You might ask why we don't do that for ALL decals.

The reason is, things like the lightning bolt scorch mark, or the lightning
bolt lightning light decal (tongue twister) only exist for a short period of
time, and the process of making the models for these guys would take long
enough that they aren't worth the savings we'd get.

So yeah, that's whats wrong and that's how i plan on fixin it.  I think it
will be blazingly fast after this :P

On Thu, Jun 10, 2010 at 9:02 AM, Nick Klotz <roracsenshi@xxxxxxxxx> wrote:

> that's really awesome. I'd be really interested to hear whats causing
> the rendering issues and where the process is hanging.
>
> On Thu, Jun 10, 2010 at 11:59 AM, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote:
> > I think i found out why they are taking so long to render, and i have an
> > idea about how to fix it.
> >
> > I'm going to try to get that working, hopefully ill be able to get it
> done
> > by the end of this weekend (:
> >
> > A friend of mine at work pointed me at 2 programs, one profiles your code
> on
> > the CPU and the other profiles it on the GPU so you can see what things
> are
> > taking the most time which really helps in figuring out how to make your
> > game run faster.
> >
>
> ==============================
> Project 1 Dev mailing list
> to unsubscribe, please send an email request to demofox@xxxxxxxxxxx
> Project 1 website: http://project1.demofox.org
> Project 1 SVN repository: http://pyotek.com/project1
>

Other related posts: