Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Per vertex shading vs per fragment shading on large models

Tags:

opengl

glsl

I am new to GLSL and writing a small application that will show a 3d model and has some user input to rotate, zoom etc. The models are rather big ( e.g. 6 million vertices, 15million faces). Right now, I am using per vertex shading and performance is ok on my personal pc. But I might need to use larger models ( with 10-15 million vertices).

The question I have is related to the performance comparison between per-vertex and per-fragment shading. From severeal resources, as well as searching the net, I have come to the conclusion that per-fragment is shading has better output especially for specular highlights however its performance is lower since it makes calculations for each pixel of the polygons instead of each vertex ( as in per vertex shading).

Maybe I am thinking completely wrong, but if the vertex count is large , should I expect per fragment shading to run faster for example in my case ( 6-10 million vertex) ? Isthe perforamnce of per fragment shading dependent on the number of pixels that is being drawn to the screen whereas per vertex shading is not?

like image 637
bahti Avatar asked Oct 10 '13 10:10

bahti


1 Answers

The performance of fragment shading depends on the number of fragments drawn on screen, including those that are drawn twice or more often because some triangles overlap others and overdraw occurs. Z-buffering can somehow reduce overdraw, but not perfectly. Deferred (or light prepass) shading may still have overdraw during the relatively cheap Z pass, but more or less makes the actual shading part strictly proportional of the screen area, irrespective of whether some triangles overlapped (or how many of them were there).

The performance of vertex shading (and following stages) depends mainly on the number of vertices (and some other details if you have a geometry shader or tesselation shader active). Generally, most applications are not limited by vertex processing nowadays. Some millions of vertices as such are normally not a problem (though of course not drawing what can't be seen is always better).
However, as triangles become smaller (approaching the size of 2x2 fragment quads), a higher vertex count induces, as a secondary effect, additional fragment shading work (and, of course, assembly/rasterization work, and ROP) without any improved visual quality, sometimes even with inferior quality due to temporal aliasing.
This is not so much related to the actual number of vertices processed, but to the screen area of individual triangles becoming smaller.

Therefore, you should have a LOD (level of detail) system which makes sure that there are not too many too small triangles (for example on far away features), and if those large models are buildings or such you might consider a portal system to clip away entire hierarchies of geometry that don't contribute to the visible result anyway.

like image 175
Damon Avatar answered Oct 12 '22 07:10

Damon