顶点着色器与片段着色器 [英] Vertex shader vs Fragment Shader

查看:264
本文介绍了顶点着色器与片段着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关Cg的教程,但是对我来说还不太清楚. 顶点着色器和片段着色器之间到底有什么区别? 在哪种情况下比另一种情况更合适?

I've read some tutorials regarding Cg, yet one thing is not quite clear to me. What exactly is the difference between vertex and fragment shaders? And for what situations is one better suited than the other?

推荐答案

片段着色器与像素着色器相同.

A fragment shader is the same as pixel shader.

一个主要区别是顶点着色器可以操纵顶点的属性.这是多边形的角点.

One main difference is that a vertex shader can manipulate the attributes of vertices. which are the corner points of your polygons.

另一方面,片段着色器负责顶点之间像素的外观.它们遵循特定规则在定义的顶点之间进行插值.

The fragment shader on the other hand takes care of how the pixels between the vertices look. They are interpolated between the defined vertices following specific rules.

例如:如果您希望多边形完全为红色,则将所有顶点定义为红色.如果要获得诸如顶点之间的渐变之类的特定效果,则必须在片段着色器中执行此操作.

For example: if you want your polygon to be completely red, you would define all vertices red. If you want for specific effects like a gradient between the vertices, you have to do that in the fragment shader.

采用另一种方式:

顶点着色器是图形管线早期步骤的一部分,我认为介于模型坐标转换和多边形裁剪之间.到那时,还没有真正完成任何事情.

The vertex shader is part of the early steps in the graphic pipeline, somewhere between model coordinate transformation and polygon clipping I think. At that point, nothing is really done yet.

但是,片段/像素着色器是栅格化步骤的一部分,在该步骤中,将计算图像并填充或着色"顶点之间的像素.

However, the fragment/pixel shader is part of the rasterization step, where the image is calculated and the pixels between the vertices are filled in or "coloured".

只需在此处阅读有关图形管道的内容,一切都会显示出来: http://en.wikipedia.org/wiki/Graphics_pipeline

Just read about the graphics pipeline here and everything will reveal itself: http://en.wikipedia.org/wiki/Graphics_pipeline

这篇关于顶点着色器与片段着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆