Search code examples
unity-game-engineshadercg

Cant understand CG semantic


I am beginner in CG and do simple shader. I can't understand what means this code

float4 vert(float4 vertexPos : POSITION) : SV_POSITION {
  ...
}

Rather this moment: We announced parameter with type float4.Question: what do this

": POSITION" and this ": SV_POSITION"

Or give reference for this

Thanks in advance!


Solution

  • Just thought the following might be helpful to understand.

    Source: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter02.html

     struct C2E1v_Output {
    
      float4 position : POSITION;
    
      float4 color    : COLOR;
    
    };
    
    C2E1v_Output C2E1v_green(float2 position : POSITION)
    
    {
    
      C2E1v_Output OUT;
    
      OUT.position = float4(position, 0, 1);
    
      OUT.color    = float4(0, 1, 0, 1);  // RGBA green
    
      return OUT;
    
    }
    

    2.1.6 Semantics

    A colon and a special word, known as a semantic, follow the position and color members of the C2E1v_Output structure. Semantics are, in a sense, the glue that binds a Cg program to the rest of the graphics pipeline. The semantics POSITION and COLOR indicate the hardware resource that the respective member feeds when the Cg program returns its output structure. They indicate how the variables preceding them connect to the rest of the graphics pipeline.

    The POSITION semantic (in this case, in an output structure used by a Cg vertex program) is the clip-space position for the transformed vertex. Later graphics pipeline stages will use the output vector associated with this semantic as the post-transform, clip-space position of the vertex for primitive assembly, clipping, and rasterization. You will be introduced to clip space later in this chapter, and more formally in Chapter 4. For now, you can think of a 2D vertex's clip-space position simply as its position within a window.

    The COLOR semantic in this context is what Direct3D calls the "diffuse vertex color" and OpenGL calls the "primary vertex color." Color interpolation for a triangle or other geometric primitive during rasterization depends on the primitive's per-vertex colors.