On Sun, 5 Feb 2012, thorsten.i.r...@jyu.fi wrote:

>
> I haven't really seen any guidelines about efficient shader coding, but
> I've come across a few statements here and in the forum now and then,
> which I so far assumed to be true. I've now spent the last few days
> benchmarking my lightfield/terrain haze framework to see if I can't
> squeeze a bit more performance out. Since the results somewhat
> contradicted things I have assumed to be true before, I thought I might
> share my observations.
>
> 1) vertex shader is fast and efficient, fragment and geometry shaders are
> comparatively slow and cost performance

Some thoughts here (bearing in mind that I'm no expert on the internals of 
GPUs):

The vertex shader is run for each vertex of the mesh each time it is 
rendered. The fragment shader is run for each fragment generated from the 
mesh - if the mesh covers a small part of the screen there will be few 
fragments - if the mesh covers a large part of the screen there will be 
many fragments (excluding the early Z-clipping of fragments that some GPUs 
may do).

Some implications:
- The amount of vertex shader work (to draw a mesh) ought to increase
   with the #vertices and the complexity of the vertex shader. For a
   particular mesh and shader the cost is the same each time it is drawn.

- The amount of fragment shader work ought to increase with the
   #fragments/pixels generated for the mesh and the complexity of the
   fragment shader. This changes online depending on how many pixels of the
   screen the mesh covers.

So, e.g. for effects used on (MP/AI) aircraft it would seem preferable to
push complexity to the fragment shader since, most of the time, most of 
the aircraft will be very small on the screen.

OTOH this would seem to suggest the opposite case for the sky-dome - 
relatively few vertices and often covering a significant part of the 
screen.

Pushing most of the haze shader computation from the vertex to the 
fragment level would seem to suggest an approximately constant cost for 
the haze for the same view regardless of scenery complexity since the 
number of hazy fragments remain about the same.

It would be interesting to see more measurements on this. One could 
account for the cost of the increased number of processed vertices by 
using the case with no haze at all as a base line.

Cheers,

Anders
-- 
---------------------------------------------------------------------------
Anders Gidenstam
WWW: http://gitorious.org/anders-hangar
      http://www.gidenstam.org/FlightGear/

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to