Tuesday, October 4, 2016

Define: Cg Tutorials Chapter 1. Introduction

[References]

Chapter 1. Introduction

This chapter has the following four sections:
  • "What Is Cg?" introduces the Cg programming language.
  • "Vertices, Fragments, and the Graphics Pipeline" describes the data flow of modern graphics hardware and explains how Cg fits into this data flow.
  • "Cg's Historical Development" provides some background on how Cg was developed.
  • "The Cg Environment" explains how applications go about using Cg programs through the Cg runtime and existing 3D application programming interfaces (APIs).
.....

Cg Semantics

In Cg, you use "semantics" to map data coming from the application (the C++ part) into stream variables in the shader. You can think of a semantics as an association between the vertex information sent to the rendering pipeline in C++ and the vertex data in the Shader.

In OpenGL, this mapping is performed by telling OpenGL to apply an "attribute ID" to a named parameter in a shader using the glBindAttribLocation() method.

  • You then modify the value of the attribute using either the glVertexAttrib() method, 
  • or specifying stream data (like a vertex stream) using glVertexAttribPointer() method. 
  • Cg doesn't require that you first bind the location of  variable to an attribute ID, but instead it defines some default ID's for different stream elements..

  • Cg defines the following default semantics and the default generic attribute ID’s that are bound to the semantic.

BINDING SEMANTICS NAMECORRESPONDING DATA
POSITION, ATTR0Input Vertex, Generic Attribute 0
BLENDWEIGHT, ATTR1Input vertex weight, Generic Attribute 1
NORMAL, ATTR2Input normal, Generic Attribute 2
DIFFUSE, COLOR0, ATTR3Input primary color, Generic Attribute 3
SPECULAR, COLOR1, ATTR4Input secondary color, Generic Attribute 4
TESSFACTOR, FOGCOORD, ATTR5Input fog coordinate, Generic Attribute 5
PSIZE, ATTR6Input point size, Generic Attribute 6
BLENDINDICES, ATTR7Generic Attribute 7
TEXCOORD0-TEXCOORD7, ATTR8-ATTR15Input texture coordinates (texcoord0-texcoord7), Generic Attributes 8-15
TANGENT, ATTR14Generic Attribute 14
BINORMAL, ATTR15Generic Attribute 15
.....

No comments:

Post a Comment