6. • Runs per input vertex.
• Transform 3D into 2D (screen space) position.
• Can perform vertex position , color , UV (texture coordinates)
manipulation.
• Cannot create new vertices.
• Cannot “see” other vertices.
8. • Runs per fragment.
• Computes fragment’s color.
• With fragment shader you can create: bump
mapping, shadows , lights , post processing effects and other
cool shit.
• See http://glsl.heroku.com/
11. • “C for graphics”
• High Level language.
Cg != C
• No classes ,pointers ,malloc ,IO etc.
• Cg has loops , conditionals , functions/overloads.
• Member variables ,local (temporary) variables constants.
• Data types: numeric primitives ,vectors , matrices
,arrays, structs and interfaces.
• Built-in trig and other math methods.
• Static & Dynamic compilation.
16. • CG Program inputs / outputs(Show code example):
Inputs
1. Varying inputs(Attributes) –streamed data VARYING per
processed element.(Vertex arrays ,UV arrays,normal arrays)
2. Uniform inputs(Uniforms)-separate from the main stream
values which don’t change each stream element.(Matrices
, vectors)
Outputs
1. Varying outputs – interpolated values sent from Vertex to
Fragment shader.
2. Binding Semantics for fragment program output: COLOR
semantic is must to have!
17. Per Frame varying data from CPU:
Uniform Uniform
variables variables
Variables
Variables
Variables
Variables
Output
Output
Input
Vertex
Input
Attributes
Vertex Shader Fragment Shader
Frame Buffer / Texture Attachment
19. Accessing vertex attributes
Vertex attributes structs are defined in UnityCG.cginc include file
• appdata_base: vertex consists of position, normal and one texture coordinate.
• appdata_tan: vertex consists of position, tangent, normal and one texture coordinate.
• appdata_full: vertex consists of position, tangent, normal, two texture coordinates and color.
We can define our own vertex attribute structs but must use the following names for the
members:
• float4 vertex is the vertex position
• float3 normal is the vertex normal
• float4 texcoord is the first UV coordinate
• float4 texcoord1 is the second UV coordinate
• float4 tangent is the tangent vector (used for normal mapping)
• float4 color is per-vertex color
26. • Used for advanced effects.
• Done using “pass” blocks.
//first pass
pass {
… shader program code here:
}
GrabPass{} //pass first pass output into second pass
//second pass//
pass{
… shader program code here:
}