Cg Toolkit Cg 3.1 Toolkit Documentation
Cg / Profiles / fp20

Name

fp20 - OpenGL fragment profile for NV2x (GeForce3, GeForce4 Ti, Quadro DCC, etc.)

Synopsis

  fp20

Description

This OpenGL profile corresponds to the per-fragment functionality introduced by GeForce3.

The capabilities of this profile are quite limited.

The compiler output for this profile conforms to the nvparse file format for describing NV_register_combiners and NV_texture_shader state configurations.

3D Api Dependencies

Requires OpenGL support for NV_texture_shader, NV_texture_shader2, and NV_register_combiners2 extensions. These extensions were introduced by GeForce3 and Quadro DCC GPUs.

Some standard library functions may require NV_texture_shader3. This extension was introduced by GeForce4 Ti and Quadro4 XGL GPUs.

Opengl Extension Specifications

 http://www.opengl.org/registry/specs/NV/register_combiners.txt
 http://www.opengl.org/registry/specs/NV/register_combiners2.txt
 http://www.opengl.org/registry/specs/NV/texture_shader.txt
 http://www.opengl.org/registry/specs/NV/texture_shader2.txt

Profile Options

None.

Data Types

fixed
The fixed data type corresponds to a native signed 9-bit integers normalized to the [-1.0,+1.0] range.
float
half
In most cases, the float and half data types are mapped to fixed for math operations.
Certain built-in standard library functions corresponding to NV_texture_shader operations operate at 32-bit floating-point precision.

Semantics

Input Semantics

The varying input semantics in the fp20 profile correspond to the respectively named varying output semantics of the vp20 profile.

Binding Semantics Name           Corresponding Data

COLOR                            Input primary color
COLOR0
COL
COL0

COLOR1                           Input secondary color
COL1

TEX0                             Input texture coordinate sets 0
TEXCOORD0

TEX1                             Input texture coordinate sets 1
TEXCOORD1

TEX2                             Input texture coordinate sets 2
TEXCOORD2

TEX3                             Input texture coordinate sets 3
TEXCOORD3

FOGP                             Input fog color (XYZ) and factor (W)
FOG

Output Semantics

COLOR                            Output color (float4)
COLOR0
COL0
COL

DEPTH                            Output depth (float)
DEPR

Standard Library Issues

There are a lot of standard library issues with this profile.

Because the 'fp20' profile has limited capabilities, not all of the Cg standard library functions are supported. The list below presents the Cg standard library functions that are supported by this profile. See the standard library documentation for descriptions of these functions.

dot(floatN, floatN)
lerp(floatN, floatN, floatN)
lerp(floatN, floatN, float)
tex1D(sampler1D, float)
tex1D(sampler1D, float2)
tex1Dproj(sampler1D, float2)
tex1Dproj(sampler1D, float3)
tex2D(sampler2D, float2)
tex2D(sampler2D, float3)
tex2Dproj(sampler2D, float3)
tex2Dproj(sampler2D, float4)
texRECT(samplerRECT, float2)
texRECT(samplerRECT, float3)
texRECTproj(samplerRECT, float3)
texRECTproj(samplerRECT, float4)
tex3D(sampler3D, float3)
tex3Dproj(sampler3D, float4)
texCUBE(samplerCUBE, float3)
texCUBEproj(samplerCUBE, float4)

Note: The non-projective texture lookup functions are actually done as projective lookups on the underlying hardware. Because of this, the 'w' component of the texture coordinates passed to these functions from the application or vertex program must contain the value 1.

Texture coordinate parameters for projective texture lookup functions must have swizzles that match the swizzle done by the generated texture shader instruction. While this may seem burdensome, it is intended to allow 'fp20' profile programs to behave correctly under other pixel shader profiles. The list below shows the swizzles required on the texture coordinate parameter to the projective texture lookup functions.

Texture lookup function       Texture coordinate swizzle

tex1Dproj                     .xw/.ra
tex2Dproj                     .xyw/.rga
texRECTproj                   .xyw/.rga
tex3Dproj                     .xyzw/.rgba
texCUBEproj                   .xyzw/.rgba

Texture Shader Operations

In order to take advantage of the more complex hard-wired shader operations provided by NV_texture_shader, a collection of built-in functions implement the various shader operations.

offsettex2D
offsettexRECT
offsettex2D(uniform sampler2D tex,
            float2 st,
            float4 prevlookup,
            uniform float4 m)

offsettexRECT(uniform samplerRECT tex,
              float2 st,
              float4 prevlookup,
              uniform float4 m)
Performs the following
float2 newst = st + m.xy * prevlookup.xx + m.zw * prevlookup.yy;
return tex2D/RECT(tex, newst);
where 'st' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation, and 'm' is the offset texture matrix. This function can be used to generate the 'offset_2d' or 'offset_rectangle' NV_texture_shader instructions.
offsettex2DScaleBias
offsettexRECTScaleBias
offsettex2DScaleBias(uniform sampler2D tex,
                     float2 st,
                     float4 prevlookup,
                     uniform float4 m,
                     uniform float scale,
                     uniform float bias)

offsettexRECTScaleBias(uniform samplerRECT tex,
                       float2 st,
                       float4 prevlookup,
                       uniform float4 m,
                       uniform float scale,
                       uniform float bias)
Performs the following
float2 newst = st + m.xy * prevlookup.xx + m.zw * prevlookup.yy;
float4 result = tex2D/RECT(tex, newst);
return result * saturate(prevlookup.z * scale + bias);
where 'st' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation, 'm' is the offset texture matrix, 'scale' is the offset texture scale and 'bias' is the offset texture bias. This function can be used to generate the 'offset_2d_scale' or 'offset_rectangle_scale' NV_texture_shader instructions.
tex1D_dp3(sampler1D tex, float3 str, float4 prevlookup
tex1D_dp3(sampler1D tex,
          float3 str,
          float4 prevlookup
Performs the following
  return tex1D(tex, dot(str, prevlookup.xyz));
where 'str' are texture coordinates associated with sampler 'tex' and 'prevlookup' is the result of a previous texture operation. This function can be used to generate the 'dot_product_1d' NV_texture_shader instruction.
tex2D_dp3x2
texRECT_dp3x2
tex2D_dp3x2(uniform sampler2D tex,
            float3 str,
            float4 intermediate_coord,
            float4 prevlookup)

texRECT_dp3x2(uniform samplerRECT tex,
              float3 str,
              float4 intermediate_coord,
              float4 prevlookup)
Performs the following
float2 newst = float2(dot(intermediate_coord.xyz, prevlookup.xyz),
                      dot(str, prevlookup.xyz));
return tex2D/RECT(tex, newst);
where 'str' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation and 'intermediate_coord' are texture coordinates associated with the previous texture unit. This function can be used to generate the 'dot_product_2d' or 'dot_product_rectangle' NV_texture_shader instruction combinations.
tex3D_dp3x3
texCUBE_dp3x3
tex3D_dp3x3(sampler3D tex,
            float3 str,
            float4 intermediate_coord1,
            float4 intermediate_coord2,
            float4 prevlookup)

texCUBE_dp3x3(samplerCUBE tex,
              float3 str,
              float4 intermediate_coord1,
              float4 intermediate_coord2,
              float4 prevlookup)
Performs the following
float3 newst = float3(dot(intermediate_coord1.xyz, prevlookup.xyz),
                      dot(intermediate_coord2.xyz, prevlookup.xyz),
                      dot(str, prevlookup.xyz));
return tex3D/CUBE(tex, newst);
where 'str' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation, 'intermediate_coord1' are texture coordinates associated with the 'n-2' texture unit and 'intermediate_coord2' are texture coordinates associated with the 'n-1' texture unit. This function can be used to generate the 'dot_product_3d' or 'dot_product_cube_map' NV_texture_shader instruction combinations.
texCUBE_reflect_dp3x3
texCUBE_reflect_dp3x3(uniform samplerCUBE tex,
                      float4 strq,
                      float4 intermediate_coord1,
                      float4 intermediate_coord2,
                      float4 prevlookup)
Performs the following
float3 E = float3(intermediate_coord2.w, intermediate_coord1.w,
                  strq.w);
float3 N = float3(dot(intermediate_coord1.xyz, prevlookup.xyz),
                  dot(intermediate_coord2.xyz, prevlookup.xyz),
                  dot(strq.xyz, prevlookup.xyz));
return texCUBE(tex, 2 * dot(N, E) / dot(N, N) * N - E);
where 'strq' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation, 'intermediate_coord1' are texture coordinates associated with the 'n-2' texture unit and 'intermediate_coord2' are texture coordinates associated with the 'n-1' texture unit. This function can be used to generate the 'dot_product_reflect_cube_map_eye_from_qs' NV_texture_shader instruction combination.
texCUBE_reflect_eye_dp3x3
texCUBE_reflect_eye_dp3x3(uniform samplerCUBE tex,
                          float3 str,
                          float4 intermediate_coord1,
                          float4 intermediate_coord2,
                          float4 prevlookup,
                          uniform float3 eye)
Performs the following
float3 N = float3(dot(intermediate_coord1.xyz, prevlookup.xyz),
                  dot(intermediate_coord2.xyz, prevlookup.xyz),
                  dot(coords.xyz, prevlookup.xyz));
return texCUBE(tex, 2 * dot(N, E) / dot(N, N) * N - E);
where 'strq' are texture coordinates associated with sampler 'tex', 'prevlookup' is the result of a previous texture operation, 'intermediate_coord1' are texture coordinates associated with the 'n-2' texture unit, 'intermediate_coord2' are texture coordinates associated with the 'n-1' texture unit and 'eye' is the eye-ray vector. This function can be used generate the 'dot_product_reflect_cube_map_const_eye' NV_texture_shader instruction combination.
tex_dp3x2_depth
tex_dp3x2_depth(float3 str,
                float4 intermediate_coord,
                float4 prevlookup)
Performs the following
float z = dot(intermediate_coord.xyz, prevlookup.xyz);
float w = dot(str, prevlookup.xyz);
return z / w;
where 'str' are texture coordinates associated with the 'n'th texture unit, 'intermediate_coord' are texture coordinates associated with the 'n-1' texture unit and 'prevlookup' is the result of a previous texture operation. This function can be used in conjunction with the 'DEPTH' varying out semantic to generate the 'dot_product_depth_replace' NV_texture_shader instruction combination.

Examples

The following examples illustrate how a developer can use Cg to achieve NV_texture_shader/NV_register_combiners functionality.

Example 1

 struct VertexOut {
    float4 color     : COLOR0;
    float4 texCoord0 : TEXCOORD0;
    float4 texCoord1 : TEXCOORD1;
};

float4 main(VertexOut IN,
            uniform sampler2D diffuseMap,
            uniform sampler2D normalMap) : COLOR
{
    float4 diffuseTexColor = tex2D(diffuseMap, IN.texCoord0.xy);
    float4 normal = 2 * (tex2D(normalMap, IN.texCoord1.xy) - 0.5);
    float3 light_vector = 2 * (IN.color.rgb - 0.5);
    float4 dot_result = saturate(dot(light_vector, normal.xyz).xxxx);
    return dot_result * diffuseTexColor;
}

Example 2

struct VertexOut {
    float4 texCoord0 : TEXCOORD0;
    float4 texCoord1 : TEXCOORD1;
    float4 texCoord2 : TEXCOORD2;
    float4 texCoord3 : TEXCOORD3;
};

float4 main(VertexOut IN,
            uniform sampler2D normalMap,
            uniform sampler2D intensityMap,
            uniform sampler2D colorMap) : COLOR
{
    float4 normal = 2 * (tex2D(normalMap, IN.texCoord0.xy) - 0.5);
    float2 intensCoord = float2(dot(IN.texCoord1.xyz, normal.xyz),
                                dot(IN.texCoord2.xyz, normal.xyz));
    float4 intensity = tex2D(intensityMap, intensCoord);
    float4 color = tex2D(colorMap, IN.texCoord3.xy);
    return color * intensity;
}

See Also

vp20


Cg Toolkit | Cg Toolkit | Download | Release Archive | Profiles | Reference | Books | Discussions |


Cg Profiles

arbfp1
arbvp1
ds_5_0
fp20
fp30
fp40
glslf
glslg
glsl
glslv
gp4fp
gp4gp
gp4
gp4vp
gp5fp
gp5gp
gp5
gp5tcp
gp5tep
gp5vp
gs_4_0
gs_5_0
hlsl10
hlsl11
hlslf
hlslv
hs_5_0
ps_1_1
ps_1_2
ps_1_3
ps_2_0
ps_2_sw
ps_2_x
ps_3_0
ps_4_0
ps_5_0
vp20
vp30
vp40
vs_1_1
vs_2_0
vs_2_sw
vs_2_x
vs_3_0
vs_4_0
vs_5_0