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)?
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.
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.)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With