Vous êtes sur la page 1sur 69

Texture Shader Configuration

using NVPARSE
Chris Wynn
NVIDIA Proprietary

Where are we?


curved
surfaces
vertex
programs
You are
here

setup
rasterizer
tex-addr
ops
texture
blending
frame-buffer

NVIDIA Proprietary

per-vertex geometry
& shading programs

tex fetch
& filter

per-pixel shading

OpenGL Texture Fetching


Conventional Lookups

(GeForce class HW)

1D Projective
2D Projective
Cube Map

Texture Shader Lookups

(GeForce3 class HW)

Conventional (+ 3D Projective)
Special Modes
Simple Dependent
Dot Product Dependent

NVIDIA Proprietary

What is nvparse?
An easy way to use:
NV_vertex_program
NV_texture_shader
NV_register_combiners / NV_register_combiners2

Does NOT replace the existing API, but is merely


a layer on top of it
Parser and the existing API can be used in
concert (particularly when a parameter needs to
be tweaked)
NVIDIA Proprietary

What is nvparse?
NVPARSE is a library that defines two entry
points.
void nvparse( char *program_string )
used for parsing a program and setting the
corresponding OpenGL state

const char **nvparse_get_errors()


used for querying if any errors were found within a
particular program

NVIDIA Proprietary

What is nvparse?
NVPARSE supports 3 kinds of programs:
Vertex Programs
Register Combiner Programs
Texture Shader Programs

In this presentation we focus on Texture Shader


Programs programs that specify how the
texture shaders should be configured.

NVIDIA Proprietary

Texture Shader Program:


Program Format
Texture Shader Programs are of the form:
TS1.0
<instruction-stage0>;
[<instruction-stage1>;]
[<instruction-stage2>;]
[<instruction-stage3>;]
The last 3 stages are optional.
The format of the instruction stages will be
described shortly.
NVIDIA Proprietary

Texture Shader Program:


Registers and Mappings
Some instructions have register inputs.
Registers:
tex0, tex1, tex2, tex3

Register Mappings:
// identity mapping
tex0
expand(tex0) // 2 * tex0 1

NVIDIA Proprietary

Texture Shader Program:


Instructions
Instructions:
3 types of instructions
Single stage
Two stage
Three stage
Single stage instructions simple to use
Multi-stage instructions a bit more difficult
(must be invoked as a block w/o other instructions
inserted between each stage)

NVIDIA Proprietary

Texture Shader Program:


Instructions
Instructions:
Max. of 4 stages total in a program
Two 1 stage instructions with one 2 stage instruction
is valid (2+1+1 = 4)
Two 3 stage instructions is not valid (3+3 > 4)

Each stage fills one slot of the template.


TS1.0
<instruction-stage0>;
[<instruction-stage1>;]
[<instruction-stage2>;]
[<instruction-stage3>;]

Each stage corresponds to a texture unit


NVIDIA Proprietary

Single Stage Instructions:


No Operation
No Operation
Function:
This instruction does nothing. Useful for disabling
a texture unit.

Syntax:
nop();

NVIDIA Proprietary

Single Stage Instructions:


No Operation
No Operation Example:
nvparse( !!TS1.0
nop();
nop();
nop();
nop();
);
This corresponds to disabling all 4 texture units.

NVIDIA Proprietary

Single Stage Instructions:


Texture 1D
Texture 1D
Function:
This instruction corresponds to GL_TEXTURE_1D
enabling.

Syntax:
texture_1d();

NVIDIA Proprietary

Single Stage Instructions:


Texture 1D
Texture 1D Example:
nvparse( !!TS1.0
texture_1d();
texture_1d();
nop();
nop();
);
This corresponds to performing 1D texture lookups on
texture unit 0 and texture unit 1, disabling units 2 and 3.

NVIDIA Proprietary

Single Stage Instructions:


Texture 2D
Texture 2D
Function:
This instruction corresponds to GL_TEXTURE_2D
enabling.

Syntax:
texture_2d();

NVIDIA Proprietary

Single Stage Instructions:


Texture 2D
Texture 2D Example:
nvparse( !!TS1.0
texture_2d();
nop();
nop();
nop();
);
This corresponds to performing a 2D texture lookup on
texture unit 0.

NVIDIA Proprietary

Single Stage Instructions:


Texture Rectangle
Texture Rectangle
Function:
This instruction corresponds to enabling
GL_TEXTURE_RECTANGLE_NV for performing texture
lookups using s and t texcoords in the range [0,width]
and [0,height] instead of [0,1] and [0,1].

Syntax:
texture_rectangle();

NVIDIA Proprietary

Single Stage Instructions:


Texture Rectangle
Texture Rectangle Example:
nvparse( !!TS1.0
texture_rectangle();
nop();
nop();
nop();
);
This corresponds to performing a 2D texture lookup on
texture unit 0 using non-normalized texcoords.

NVIDIA Proprietary

Single Stage Instructions:


Texture 3D
Texture 3D
Function:
This instruction corresponds to GL_TEXTURE_3D
enabling.

Syntax:
texture_3d();

NVIDIA Proprietary

Single Stage Instructions:


Texture 3D
Texture 3D Example:
nvparse( !!TS1.0
texture_3d();
texture_1d();
nop();
nop();
);
This corresponds to performing 3D texture lookup on
texture unit 0 and a 1D texture lookup on texture unit 1.

NVIDIA Proprietary

Single Stage Instructions:


Texture Cube Map
Texture Cube Map
Function:
This instruction corresponds to
GL_TEXTURE_CUBE_MAP_ARB enabling.

Syntax:
texture_cube_map();

NVIDIA Proprietary

Single Stage Instructions:


Texture Cube Map
Texture Cube Map Example:
nvparse( !!TS1.0
texture_cube_map();
);
This corresponds to performing a cube map lookup on
texture unit 0 using the interpolated (s,t,r) texture
coordinates.

NVIDIA Proprietary

Single Stage Instructions:


Cull Fragment
Cull Fragment
Function:
This instruction subjects each of the four
interpolated texture coords (STRQ) to conditions
passed as arguments. Each condition may be either:
LESS_THAN_ZERO or GEQUAL_TO_ZERO
If any of the conditions is satisfied, the fragment is
eliminated from further processing.

Syntax:
cull_fragment(condEnum s, condEnum t,
condEnum r, condEnum q);
NVIDIA Proprietary

Single Stage Instructions:


Cull Fragment
Cull Fragment Example:
nvparse( !!TS1.0
cull_fragment( LESS_THAN_ZERO,
GEQUAL_TO_ZERO,
LESS_THAN_ZERO,
GEQUAL_TO_ZERO);
);
This corresponds to culling (aka killing) a fragment
from further processing if any of the conditions is true.
*Can be used to implement user clip planes.
NVIDIA Proprietary

Single Stage Instructions:


Pass Through
Pass Through
Function:
This instruction takes the four interpolated texture
coordinates (STRQ), clamps them to the range [0,1],
and then converts them to an RGBA color.
clamp(S,0,1) red

clamp(T,0,1) green

clamp(R,0,1) blue

clamp(Q,0,1) alpha

Syntax:
pass_through();
NVIDIA Proprietary

Single Stage Instructions:


Pass Through
Cull Fragment Example:
nvparse( !!TS1.0
pass_through();
pass_through();
);
This corresponds to passing texture coordinates
through as a color for texture units 0 and 1.
*Useful for additional iterated colors.

NVIDIA Proprietary

Single Stage Instructions:


Offset Texture 2D
Offset Texture 2D
Function:
This instruction utilizes a previous texture unit and
a 2x2 matrix. The previous texture unit is assumed to
be of type DSDT and the matrix is used to transform its
filtered results. The transformed results are added to
the current stages S and T texcoords, the sum of which
is used to lookup into a 2D texture.

Syntax:
offset_2d( Reg prev, float m00, float m01,
float m10, float m11 );
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture 2D
Offset Texture 2D Example:
nvparse( !!TS1.0
texture_2d(); // must of DSDT format
offset_2d(tex0,.5,0,0,.5);
);
This corresponds to computing texture coordinates for
texture unit 1 as:
S1 = S1 + .5 * ds + 0 * dt
T1 = T1 + 0 * ds + .5 * dt
then using (S1,T1) to perform a 2D texture lookup on
texture unit 1.
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture 2D Scale
Offset Texture 2D Scale
Function:
This instruction is the same as Offset Texture 2D
except that the magnitude component of the previous
texture unit is used to scale and bias the unsigned
RGBA texture 2D lookup result.

Syntax:
offset_2d( Reg prev, float m00, float m01,
float m10, float m11,
float scale, float bias );
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture 2D Scale
Offset Texture 2D Scale Example:
nvparse( !!TS1.0
texture_2d(); // must be of DSDT_Mag
// format
offset_2d_scale(tex0,.5,0,0,.5,
.5,.25);
);
This corresponds to computing (S1,T1) as before and
using (S1,T1) to do an RGBA 2D texture access. The
final RGBA result is:
(R*M, G*M, B*M, A) where M = (.5 * mag + .25)
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture Rectangle
Offset Texture Rectangle
Function:
This instruction is the same as Offset Texture 2D
except that the texture access is into a rectangular
texture instead of a 2D texture.

Syntax:
offset_rectangle( Reg prev, float m00, float m01,
float m10, float m11 );

NVIDIA Proprietary

Single Stage Instructions:


Offset Texture Rectangle
Offset Texture Rectangle Example:
nvparse( !!TS1.0
texture_2d(); // must be of DSDT
// format
offset_rectangle(tex0,.5,0,0,.5);
);
This corresponds to computing texture coordinates for
texture unit 1 as:
S1 = S1 + .5 * ds + 0 * dt
T1 = T1 + 0 * ds + .5 * dt
then using (S1,T1) to perform a rectangle texture
lookup on texture unit 1.
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture Rectangle Scale
Offset Texture Rectangle Scale
Function:
This instruction is the same as Offset Texture
Rectangle except that the magnitude component of the
previous texture unit is used to scale and bias the
unsigned RGBA texture rectangle lookup result.

Syntax:
offset_rectangle_scale( Reg prev,
float m00, float m01, float m10, float m11,
float scale, float bias );
NVIDIA Proprietary

Single Stage Instructions:


Offset Texture Rectangle Scale
Offset Texture Rectangle Scale Example:
nvparse( !!TS1.0
texture_2d(); //must be of DSDT_Mag
//internal format
offset_rectangle_scale(tex0,
.5,0,0,.5,.5,.25);
);
This corresponds to computing (S1,T1) as before and
using (S1,T1) to do an RGBA texture rectangle access.
The final RGBA result is:
(R*M, G*M, B*M, A) where M = (.5 * mag + .25)
NVIDIA Proprietary

Single Stage Instructions:


Dependent AR
Dependent AR
Function:
This instruction converts the alpha and red
components of a previous instruction into an (s,t)
texture coordinate set and is used to access a 2D
texture.

Syntax:
dependent_ar( Reg prev );

NVIDIA Proprietary

Single Stage Instructions:


Dependent AR
Dependent AR Example:
nvparse( !!TS1.0
texture_2d();
dependent_ar(tex0);
);
This corresponds to using the filtered alpha and red
components from texture unit 0 as (s,t) texture
coordinates for a 2D texture access on texture unit 1.
Alpha s
NVIDIA Proprietary

Red t

Single Stage Instructions:


Dependent GB
Dependent GB
Function:
This instruction converts the green and blue
components of a previous instruction into an (s,t)
texture coordinate set and is used to access a 2D
texture.

Syntax:
dependent_gb( Reg prev );

NVIDIA Proprietary

Single Stage Instructions:


Dependent GB
Dependent GB Example:
nvparse( !!TS1.0
nop();
texture_2d();
dependent_gb(tex1);
);
This corresponds to using the filtered green and blue
components from texture unit 1 as (s,t) texture
coordinates for a 2D texture access on texture unit 2.
Green s
NVIDIA Proprietary

Blue t

Two Stage Instructions:


Dot Product Texture 2D
Dot Product Texture 2D
Function:
This two-stage instruction block computes the dot
product of the first stages STR coordinate set with
some mapping of the components of a previous texture
result. The component mapping depends on the type
(RGBA or HILO) and signedness of the stages previous
texture input. The second stages STR coordinate set is
similarly dotted with a previous mapped texture result.
The two dot products make up a (s,t) coordinate set and
are used to access a 2D texture.
NVIDIA Proprietary

Two Stage Instructions:


Dot Product Texture 2D
Dot Product Texture 2D
Syntax:
dot_product_2d_1of2( MapReg prev1 );
dot_product_2d_2of2( MapReg prev2 );
The texture unit corresponding to the second stage of
the instruction must have a 2D texture bound.
prev1 and prev2 dont necessarily need to be the same.

NVIDIA Proprietary

Two Stage Instructions:


Dot Product Texture 2D
Dot Product Texture 2D Example:
nvparse( !!TS1.0
texture_2d(); // RGB8 normal map
dot_product_2d_1of2(expand(tex0));
dot_product_2d_2of2(expand(tex0));
);
If the texcoords for unit 1 are a light vector (L) and the
texcoords for unit 2 are a halfangle vector (H), this
corresponds to doing two dot products to produce
coordinates (N L, H L) and using these (s,t) results to
lookup into a 2D texture.
NVIDIA Proprietary

Two Stage Instructions:


Dot Product Texture Rectangle
Dot Product Texture Rectangle
Function:
This two-stage instruction block computes the dot
product of the first stages STR coordinate set with
some mapping of the components of a previous texture
result. The component mapping depends on the type
(RGBA or HILO) and signedness of the stages previous
texture input. The second stages STR coordinate set is
similarly dotted with a previous mapped texture result.
The two dot products make up a (s,t) coordinate set and
are used to access a rectangle texture.
NVIDIA Proprietary

Two Stage Instructions:


Dot Product Texture Rectangle
Dot Product Texture Rectangle
Syntax:
dot_product_rectangle_1of2( MapReg prev1 );
dot_product_rectangle_2of2( MapReg prev2 );
The texture unit corresponding to the second stage of
the instruction must have a rectangle texture bound.
prev1 and prev2 dont necessarily need to be the same.

NVIDIA Proprietary

Two Stage Instructions:


Dot Product Texture Rectangle
Dot Product Texture Rectangle Example:
nvparse( !!TS1.0
texture_2d(); // RGB8 normal map
dot_product_rectangle_1of2(expand(tex0));
dot_product_rectangle_2of2(expand(tex0));
);

If the texcoords for unit 1 are a light vector (L) and the
texcoords for unit 2 are a halfangle vector (H), this
corresponds to doing two dot products to produce
coordinates (N L, N H) and using these (s,t) results to
lookup into a rectangle texture.
NVIDIA Proprietary

Two Stage Instructions:


Dot Product Depth Replace
Dot Product Depth Replace
Function:
This two-stage instruction is used to alter the depth
of a fragment. It computes the dot product of the first
stages STR coordinate set with some mapping of the
components of a previous texture result. The
component mapping depends on the type (RGBA or
HILO) and signedness of the stages previous texture
input. The second stages STR coordinate set is
similarly dotted with a previous mapped texture result.
The first dot product is divided by the second, and this
value replaces the fragments window space depth
value. The RGBA result is (0,0,0,0).

NVIDIA Proprietary

Two Stage Instructions:


Dot Product Depth Replace
Dot Product Depth Replace
Syntax:
dot_product_depth_replace_1of2( MapReg prev1 );
dot_product_depth_replace_2of2( MapReg prev2 );
prev1 and prev2 dont necessarily need to be the same.

NVIDIA Proprietary

Two Stage Instructions:


Dot Product Depth Replace
Dot Product Depth Replace Example:
nvparse( !!TS1.0
texture_2d(); // probably unsigned HILO format
dot_product_depth_replace_1of2(tex0);
dot_product_depth_replace_2of2(tex0);
texture_2d(); // probably a decal texture
);

If the texture bound to unit 0 is a 32-bit depth map,


texcoords for unit 1 are (zscale, zscale/216, zbias), and
texcoords for unit 2 are (wscale, wscale/216, wbias), then the
fragments depth will be:
depth = (Z (HI,LO,1)) / W (HI,LO,1)
*Useful for depth-correct sprites.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture 3D
Dot Product Texture 3D
Function:
This three-stage instruction block is very similar to
the Dot Product Texture 2D. The main difference is that
a texture fetch is not performed in the second stage.
Instead, a third stage computes the dot product of its
corresponding units STR coordinates set with some
mapping of the components of a previous texture
result. The three dot products make up an (s,t,r)
coordinate triple and are used to access a 3D texture.

NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture 3D
Dot Product Texture 3D
Syntax:
dot_product_3d_1of3( MapReg prev );
dot_product_3d_2of3( MapReg prev );
dot_product_3d_3of3( MapReg prev );
The texture unit corresponding to the third stage of the
instruction must have a 3D texture bound.

NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture 3D
Dot Product Texture 3D Example:
nvparse( !!TS1.0
texture_2d();
dot_product_3d_1of3(tex0);
dot_product_3d_2of3(tex0);
dot_product_3d_3of3(tex0);
);
If the texcoords for unit 1, 2, and 3 are considered to
compose a matrix, this corresponds to transforming the
filtered result from texture unit 0 by a 3x3 matrix and
using the resulting 3-component vector to access a
3D texture.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture Cube Map
Dot Product Texture Cube Map
Function:
This three-stage instruction block is the same as
the Dot Product Texture 3D block except that the vector
made up of the three dot products is used to access a
cube map texture instead of a 3D texture.

NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture Cube Map
Dot Product Texture Cube Map
Syntax:
dot_product_cube_map_1of3( MapReg prev );
dot_product_cube_map_2of3( MapReg prev );
dot_product_cube_map_3of3( MapReg prev );
The texture unit corresponding to the third stage of the
instruction must have a cube map texture bound.

NVIDIA Proprietary

Three Stage Instructions:


Dot Product Texture Cube Map
Dot Product Texture Cube Map Example:
nvparse( !!TS1.0
texture_2d();
dot_product_cube_map_1of3(tex0);
dot_product_cube_map_2of3(tex0);
dot_product_cube_map_3of3(tex0);
);
If the texcoords for unit 1, 2, and 3 are considered to
compose a matrix, this corresponds to transforming the
filtered result from texture unit 0 by a 3x3 matrix and
using the resulting 3-component vector to access a
cube map texture.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map (Constant
Eye)
Dot Product Reflect Cube Map (Constant Eye)
Function:
This three-stage instruction block is the same as
Dot Product Texture Cube Map except that after the
three dot products are computed they are considered to
form a normal (Nx, Ny, Nz). An eye vector (Ex, Ey, Ez),
passed as arguments to the first stage, is used to
compute a reflection vector as:
R=

2N(NE)
E
(NN)

The resulting reflection vector is then used to


access a cube map bound to the third stage.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map (Constant
Eye)
Dot Product Reflect Cube Map (Constant Eye)
Syntax:
dot_product_reflect_cube_map_const_eye_1of3(
MapReg prev, float Ex, float Ey, float Ez );
dot_product_reflect_cube_map_const_eye_2of3(
MapReg prev );
dot_product_reflect_cube_map_const_eye_3of3(
MapReg prev );
The texture unit corresponding to the third stage of the
instruction must have a cube map texture bound.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map (Constant
Eye)
Dot Product Reflect Cube Map (Constant Eye)
Example:
nvparse( !!TS1.0
texture_2d();
dot_product_reflect_cube_map_const_eye_1of3(
tex0, 0,0,1);
dot_product_reflect_cube_map_const_eye_2of3(
tex0);
dot_product_reflect_cube_map_const_eye_3of3(
tex0);
);

Transforms a vector and computes R. Uses R to


perform a cube map lookup.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map
from Q coords)

(Eye

Dot Product Reflect Cube Map (Eye from Q)


Function:
This three-stage instruction block is the same as
Dot Product Reflect Cube Map (Constant Eye) except
that the eye vector is not constant. Instead, the eye
vector (Ex, Ey, Ez) is composed from the q texture
coordinate from the three stages.
(Ex, Ey, Ez) = (q1, q2, q3)
The R vector is computed in the same manner and
used to access a cube map lookup.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map
from Q coords)

(Eye

Dot Product Reflect Cube Map (Constant Eye)


Syntax:
dot_product_reflect_cube_map_eye_from_qs_1of3(
MapReg prev );
dot_product_reflect_cube_map_eye_from_qs_2of3(
MapReg prev );
dot_product_reflect_cube_map_eye_from_qs_3of3(
MapReg prev );
The texture unit corresponding to the third stage of the
instruction must have a cube map texture bound.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Reflect Cube Map
from Q coords)

(Eye

Dot Product Reflect Cube Map (Constant Eye)


Example:
nvparse( !!TS1.0
texture_2d();
dot_product_reflect_cube_map_const_eye_1of3(
tex0);
dot_product_reflect_cube_map_const_eye_2of3(
tex0);
dot_product_reflect_cube_map_const_eye_3of3(
tex0);
);

Transforms a vector and computes R. Uses R to


perform a cube map lookup.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Constant Eye)
Dot Product Cube Map and Reflect Cube Map
(Constant Eye)
Function:
This three-stage instruction block is the same as
Dot Product Reflect Cube Map (Constant Eye) except
that in addition to accessing a cube map using the
reflection vector, an additional cube map is accessed
using the (Nx, Ny, Nz) vector resulting from the three
intermediate dot products.

NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Constant Eye)
Dot Product Cube Map and Reflect Cube Map
(Constant Eye)
Syntax:
dot_product_cube_map_and_reflect_cube_map_const_eye_1of3(
MapReg prev );
dot_product_cube_map_and_reflect_cube_map_const_eye_2of3(
MapReg prev );
dot_product_cube_map_and_reflect_cube_map_const_eye_3of3(
MapReg prev );

The texture units corresponding to the second and


third stages of the instruction must have cube map
textures bound.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Constant Eye)
Dot Product Cube Map and Reflect Cube Map
(Constant Eye) Example:
nvparse( !!TS1.0
texture_2d();
dot_product_cube_map_and_reflect_cube_map_const_eye_1of3(
tex0);
dot_product_cube_map_and_reflect_cube_map_const_eye_2of3(
tex0);
dot_product_cube_map_and_reflect_cube_map_const_eye_3of3(
tex0);
);

Transforms a vector to obtain N. Also computes R.


Uses N to access the cube map bound to unit 2 and
uses R to access the cube map bound to unit 3.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Eye from Q coords)
Dot Product Cube Map and Reflect Cube Map
(Eye from Q coords)
Function:
This three-stage instruction block is the same as
Dot Product Cube Map and Reflect Cube Map (Constant
Eye) except that the eye vector is not constant. Instead,
the eye vector (Ex, Ey, Ez) is composed from the q
texture coordinate from the three stages.
(Ex, Ey, Ez) = (q1, q2, q3)
The R vector is computed in the same manner and
both R and N are used to access cube maps.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Eye from Q coords)
Dot Product Cube Map and Reflect Cube Map
(Eye from Q coords)
Syntax:
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_1of3(
MapReg prev );
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_2of3(
MapReg prev );
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_3of3(
MapReg prev );

The texture units corresponding to the second and


third stages of the instruction must have cube map
textures bound.
NVIDIA Proprietary

Three Stage Instructions:


Dot Product Cube Map and Reflect Cube
Map (Eye from Q coords)
Dot Product Cube Map and Reflect Cube Map
(Eye from Q coords) Example:
nvparse( !!TS1.0
texture_2d();
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_1of3(
tex0);
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_2of3(
tex0);
dot_product_cube_map_and_reflect_cube_map_eye_from_qs_3of3(
tex0);
);

Transforms a vector to obtain N. Also computes R.


Uses N to access the cube map bound to unit 2 and
uses R to access the cube map bound to unit 3.
NVIDIA Proprietary

More nvparse TS1.0 Information


Always check for errors after calling nvparse()
Putting newlines (i.e. \n) at the end of each line
of the program will ease debugging.
Parser will give line numbers

Use display lists to cache state changes and


eliminate run-time parsing.
Remember to use input mappings.
Nvparse configures texture shaders but doesnt
bind textures.
You must bind textures yourself

NVIDIA Proprietary

Complete Example
// Create display list once.
glNewList(dlist,GL_COMPILE);
nvparse(
!!TS1.0\n
texture2d();\n
dot_product_2d_1of2(expand(tex0);\n
dot_product_2d_2of2(expand(tex0);\n
texture2d();\n
);
glEndList();
// Now check for errors.
for (const char** errors= nvparse_get_errors(); *errors;
errors++)
fprintf(stderr, *errors);
NVIDIA Proprietary

Complete Example
void display()
{
// Setup the texture shader state.
glCallList(dlist);
// Turn on texture shaders.
glEnable(GL_TEXTURE_SHADER_NV);
// Bind the textures.
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, normalMap);
glActiveTextureARB(GL_TEXTURE2_ARB);
glBindTexture(GL_TEXTURE_2D, diffuseSpecularMap);
glActiveTextureARB(GL_TEXTURE3_ARB);
glBindTexture(GL_TEXTURE_2D, decalMap);
// Draw the geometry.

NVIDIA Proprietary

Questions?
Send to cwynn@nvidia.com

NVIDIA Proprietary

Vous aimerez peut-être aussi