concept vertex shader in category opencl

appears as: A vertex shader, vertex shader, The vertex shader, vertex shaders
OpenCL in Action: How to Accelerate Graphics and Computation

This is an excerpt from Manning's book OpenCL in Action: How to Accelerate Graphics and Computation.

This third point is important to appreciate. A vertex shader can access only one vertex at a time, and a fragment shader can access only one fragment at a time. But a kernel can access all the data on a device and synchronize its processing using barriers. This makes kernels much more flexible with regard to the types of operations that can be performed on the GPU.

In addition to vertex shaders and pixel shaders, the OpenGL 4.1 spec also defines geometry shaders, tessellation control shaders, and tessellation evaluation shaders.

Most vertex shaders perform more work than setting output coordinates equal to input coordinates. In many cases, vertex shaders use matrix-vector multiplication to update vertices’ positions. As explained in chapter 12, the multiplication of an n-element vector by an n-by-n matrix will produce a second n-element vector. If coded correctly, a matrix can be used to rotate, move, or scale vertices in a model. These operations are collectively called transformations, and their corresponding matrices are called transformation matrices.

For example, the AppB/three_squares application creates a model and rotates it so that the squares can be viewed from a specific viewpoint. This rotation is accomplished by the vertex shader, whose code is contained in the AppB/three_squares/three_squares.vert source file. Here’s what this code looks like.

Listing B.2. Vertex shader: three_squares.vert

Here, the host application provides the vertex shader with two attributes for each incoming vertex. The in_coords attribute identifies the position of the vertex, and in_color identifies the color of the vertex. The shader creates a 3-by-3 matrix called rot_matrix and multiplies it by the vertex’s coordinates, thereby transforming the vertex’s position.

The host application associates the color attribute with the name in_color. The vertex shader receives this attribute but doesn’t modify its value. Instead, it creates another vec3 variable called new_color and passes this to the next stage. In this simple application, the next stage is the fragment shader, which we’ll look at next.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage