简体   繁体   English

着色器的性能(顶点 VS 片段)

[英]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)?甚至对于具有超过 100.000 个多边形的高网格模型(假设有一堆独特的顶点)?

No it's not always better.不,它并不总是更好。

The best way to select the proper place of calculations is an experiment. select 正确计算位置的最佳方法是实验。 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.现代 GPU 对顶点着色器和片段着色器使用相同的处理单元,因此查看这些数字会让您了解在哪里进行演算。

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.在顶点着色器(如果不在 CPU 上)做所有事情的建议来自这样一个想法,即渲染的 3D model 的像素与顶点的比率应该始终很高。 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.如果您在非常远的距离看到 object,则不需要几何细节,这就是几何细节层次 (LOD) 的用途。 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.如果您不遵循它-您将独自一人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM