Vertex shader vs fragment shader

I read several Cg tutorials, but one is not entirely clear to me. What is the difference between vertex and fragment shaders? And for what situations is the other best suited?

+99
opengl fragment-shader vertex-shader cg
Dec 12 '10 at 10:41
source share
5 answers

The fragment shader is the same as the pixel shader.

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

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

For example: if you want your polygon to be completely red, you would define all the vertices in red. If you want to use certain effects, such as the gradient between the vertices, you must do this in the fragment shader.

Put another way:

The vertex shader is part of the early steps of the graphics pipeline, somewhere between the model coordinate transformation and the polygon clipping. At this point, nothing has been done.

However, the fragment / pixel shader is part of the rasterization step where the image is computed and the pixels between the vertices are filled or “painted”.

Just read about the graphics pipeline here and it will open: http://en.wikipedia.org/wiki/Graphics_pipeline

+169
Dec 12 '10 at 10:48
source share

Vertex shader runs on each vertex, and a fragment shader runs on each pixel. The fragment shader is applied after the vertex shader. Read more about the shader GPU pipeline link text

+27
Dec 12 2018-10-12
source share

Nvidia Cg Tutorial :

Vertex conversion is the first processing step in the graphics equipment pipeline. The vertex transformation performs a sequence of mathematical operations on each vertex. These operations include converting the vertex position to the screen position for use by the rasterizer, generating texture coordinates for texturing, and lighting the vertex to determine its color.

Rasterization results in a set of pixels, as well as a set of fragments. There is no correlation between the number of vertices that a primitive has and the number of fragments that are generated when it is rasterized. For example, a triangle consisting of only three vertices can occupy the entire screen and, therefore, generate millions of fragments!

We said earlier that you should consider a fragment as a pixel if you do not know exactly what the fragment is. However, at this point, the difference between the fragment and the pixel becomes important. The term "pixel" means "image element". A pixel represents the contents of a frame buffer at a specific location, such as color, depth, and any other values ​​associated with that location. A fragment is the state needed to update a specific pixel.

The term “fragment” is used because rasterization breaks each geometric primitive, such as a triangle, into pixel-sized fragments for each pixel that covers the primitive. A fragment has an appropriate pixel location, depth value, and a set of interpolated parameters, such as color, secondary (mirror) color, and one or more sets of texture coordinates. These various interpolated parameters are derived from the transformed vertices that make up the particular geometric primitive used to generate the fragments. You can think of the fragment as a “potential pixel”. If a fragment passes various rasterization tests (at the stage of raster operations, which will be briefly described), the fragment updates the pixel in the frame buffer.

+20
Aug 13 '11 at 16:20
source share

Vertex shaders and fragment shaders are a three-dimensional implementation function that does not use fixed-pipeline rendering. In any three-dimensional rendering, vertex shaders are applied before fragment / pixel shaders.

A vertex shader works with each vertex. If you have a fixed polygon mesh and you want to deform it in the shader, you must implement it in the vertex shader. Those. any physical change in the appearance of vertices can be done in vertex shaders.

The fragment shader receives the output of the vertex shader and associates the colors, pixel depth value, etc. After these operations, the fragment is sent to Framebuffer for display on the screen.

Some operations, such as lighting calculations, can be performed both in the vertex shader and in the fragment shader. But the fragment shader gives a better result than the vertex shader.

+5
May 31 '13 at 15:53
source share

When rendering images using 3D equipment, you usually have a grid (point, polygons, lines) that are defined by vertices. To control the vertices individually, usually for model movements or waves in the ocean, you can use vertex shaders. These vertices can have a static color or the color assigned by the textures to manipulate the colors of the vertices that you use Freud shaders. At the end of the pipeline, when the view goes to the screen, you can also use fragmented shaders.

+3
Dec 12 '10 at 10:50
source share



All Articles