Cg Tutorial Pdf

Then hardware engineers can arrange, in parallel, the ever-greater number of transistors available to execute all these various chunks of work. This means that the processing of a particular vertex or fragment has no effect on other vertices or fragments processed at the same time. For example, Cg programs can perform physical simulation, compositing, and other nonshading tasks. On the other hand, if you are not familiar with C or even programming languages in general but you enjoy computer graphics and want to learn something new, read on anyway.

Your program not only must be correct, but it also must limit itself to the restrictions imposed by the particular profile used to compile your Cg program. Finally, a frame buffer write operation replaces the pixel's color with the blended color.

Doing justice to all these contributions in the context of this tutorial is not always practical. Having finished this introduction to the Cg programming language, you are now ready to take on the tutorial chapters, which will teach you how to write Cg programs. Further functionality, such as relative addressing of constants and flow-control support for branching and looping, measurement worksheets pdf is also available in more recent programmable vertex processors.

1.1 What Is Cg

This constant redoubling of computer power, historically known as Moore's Law, means cheaper and faster computer hardware, and is the norm for our age. The exercises at the end of each chapter help you review your knowledge and develop practical programming skills.

For example, a triangle made up of just three vertices could take up the entire screen, and therefore generate millions of fragments! This section explains how graphics hardware is evolving and then explores the modern graphics hardware-rendering pipeline. Figure shows a flow chart for a typical programmable vertex processor. Cg natively supports vectors and matrices because these data types and related math operations are fundamental to graphics and most graphics hardware directly supports vector data types. Cg is different because it encourages dynamic compilation, although static compilation is also supported.

The process starts with the transformation and coloring of vertices. The inspiration for the RenderMan Shading Language came from an earlier idea called shade trees. Most vertex processing uses a limited palette of operations.

We will explain many of these tasks in subsequent chapters. First, the primitive assembly step assembles vertices into geometric primitives based on the geometric primitive batching information that accompanies the sequence of vertices. This process is known as culling. The Cg language bases itself on C as well. Every vertex has a position but also usually has several other attributes such as a color, a secondary or specular color, one or multiple texture coordinate sets, and a normal vector.

Where do vertex and fragment programs fit into the pipeline? Cg has a library of functions, called the Standard Library, that is well suited for the kind of operations required for graphics. The vertex processor then repeatedly fetches the next instruction and executes it until the vertex program terminates. Figure is a small portion of a complex assembly language fragment program used to represent skin. Figure The Graphics Hardware Pipeline.

Cg Programming/Unity

In addition to being specialized for graphics, Cg and other shading languages are different from conventional programming languages because they are based on a data-flow computational model. After the tests, a blending operation combines the final color of the fragment with the corresponding pixel's color value. Once compiled, your program does not need to be recompiled, unless you change the program code. Texturing operations enable the processor to access a texture image using a set of texture coordinates and then to return a filtered sample of the texture image. Exponential, logarithmic, and trigonometric approximations facilitate lighting, fog, and geometric computations.

Unfortunately, PixelFlow was too expensive and failed commercially. This generation provides vertex programmability rather than merely offering more configurability. Another reason for limiting program size and scope is that the smaller and more efficient your Cg programs are, the faster they will run. In contrast, the Cg language is fully dedicated to this task. What operating systems does each programming interface support?

If you are familiar with C or one of the many languages derived from C, then Cg will be easy to learn. Think of a Cg program as a black box into which vertices or fragments flow on one side, are somehow transformed, and then flow out on the other side. Researchers at Pixar and elsewhere recognized that each shade tree is a limited kind of program.

Cg Programming/Unity

Distinguish a fragment from a pixel. Fragment program instructions include texture fetches.

Cg Programming/Unity - Wikibooks open books for an open world

In fact, all of the previously described stages can be broken down into substages as well. There are no side effects to the execution of a Cg program.

Before the advent of programmable graphics hardware, there was no point in providing a programming language for it. However, the Reyes algorithm used by PhotoRealistic RenderMan is not very suitable for efficient hardware implementation, primarily due to its higher-level geometry handling. The raster operations stage checks each fragment based on a number of tests, including the scissor, alpha, stencil, and depth tests.

The Cg Tutorial - Chapter 1. Introduction

Earlier, we told you to think of a fragment as a pixel if you did not know precisely what a fragment was. We call this static compilation. Cg programs describe the vertex or fragment processing that takes place in a single rendering pass, but some complex shading algorithms require multiple rendering passes. It marries programmatic control of these attributes with the incredible speed and capabilities of today's graphics processors. Other effects, such as blending and stencil-based shadowing, also occur during this stage.

We are unlikely ever to reach a point where computer graphics becomes a substitute for reality. At this point, however, the distinction between a fragment and a pixel becomes important. Polygons, lines, and points are each rasterized according to the rules specified for each type of primitive.

The Cg Tutorial

Figure Visualizing the Graphics Pipeline. The RenderMan Interface Standard describes the best-known shading language for noninteractive shading. The results of rasterization are a set of pixel locations as well as a set of fragments. The data-flow model for vertex processing begins by loading each vertex's attributes such as position, color, texture coordinates, and so on into the vertex processor. Figure The Programmable Graphics Pipeline.

There is no relationship between the number of vertices a primitive has and the number of fragments that are generated when it is rasterized. In what order are the stages arranged?

Figure shows this sequence of operations. In general, future profiles will be supersets of current profiles, so that programs written for today's profiles will compile without change using future profiles. Specialized instructions can make lighting and attenuation functions easier to compute.

1.2 Vertices Fragments and the Graphics Pipeline