Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shaders' Performance (Vertex VS Fragment)

Is ALWAYS better make the hard calculations inside the Vertex Shader rather than in Fragment Shader? Even to high mesh models, with more than 100.000 polygons (assuming there are a bunch of unique vertices)?

like image 542
user464230 Avatar asked May 23 '11 21:05

user464230


People also ask

What is the difference between a vertex and fragment shaders?

There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders. Vertex Shaders transform shape positions into 3D drawing coordinates. Fragment Shaders compute the renderings of a shape's colors and other attributes.

Are compute shaders faster than fragment shaders?

This turns out to be 50% faster than the fragment shader! (It can be embiggened, which you may wish to do if you're having trouble reading the text.)

Do you need a fragment shader?

Fragment shaders are technically an optional shader stage. If no fragment shader is used, then the color values of the output Fragment have undefined values. However, the depth and stencil values for the output fragment have the same values as the inputs.

What are Vertex Shaders used for?

Vertex shaders typically perform transformations to post-projection space, for consumption by the Vertex Post-Processing stage. They can also be used to do per-vertex lighting, or to perform setup work for later shader stages.


1 Answers

No it's not always better.

The best way to select the proper place of calculations is an experiment. Try both and see what is better for your constraints and hardware.

Theoretically though, you can estimate the number of fragments processed and compare it to the number of vertices. Modern GPUs use the same processing units for vertex and fragment shaders, so looking at these numbers will give you an idea of where to do the calculus.

Advices to do everything in vertex shader (if not on CPU) come from the idea that your pixel-to-vertex ratio of the rendered 3D model should always be high. There is no need for geometry detail if you see an object at a very high distance, that's what geometry Levels Of Detail (LODs) are used for. So if you do it in the "good" way - you'll need to calculate on a vertex level. If you don't follow it - you are on your own.

like image 200
kvark Avatar answered Sep 24 '22 06:09

kvark