INPUT REGISTERS

The input registers are how data gets passed to the pixel shader. All registers consist of a four-element vector, with at least 8 bits of precision per component in some of the earlier hardware implementations, which may cause round-off to be a problem in long, complicated shaders. In PS 1.4 class hardware or later, if you need more precision, then you can use texture coordinate registers to pass in higher precision values. See the Texture Registers subsection later in this section for more information.

Input to the pixel shader consists of the vertex color registers, the texture registers, and the constant registers. The vertex color registers are the direct output of the vertex shader, the values in oD0 and oD1, or if no vertex shader was used, the diffuse and specular colors are generated by the fixed function pipeline. The float constant registers are constants that are set up prior to the shader being called or are set inside the shader code itself. The texture registers are interpolated values taken from the vertex data.

v[n]: The Vertex Color Registers

Pixel shader vertex color registers consist of two read only registers that are generated as output from the vertex shader or the fixed function pipeline. If the current render state is flat shading D3DSHADE_FLAT, then the vertex color registers use only the vertex shader color data from the first vertex in the triangle. If Gouraud shading is enabled (i.e., D3DSHADE_GOURAUD), then the pixel values will be a linear interpolation of the three vertex color values used in the current triangle's vertices. The vertex color registers (potentially) have the lowest precision of all the registers, but a minimum of 8 unsigned bits of precision (Table 8.3).

Table 8.3: Vertex Color Register Properties

PS VERSION

1.0

1.1

1.2

1.3

1.4

2.0

NUMBER

2

2

2

2

2[*]

2

PORT LIMITS

1

2

2

2

2

1

READ/WRITE?

RO

RO

RO

RO

RO

RO

RANGE

0,1

0,1

0,1

0,1

0,1

0,1

[*]In PS 1.4, you can use the vertex color register only in phase two.

c[n]: The Constant Registers

The pixel shader float constant registers are similar to the ones we used for vertex shaders. Just like those vertex shader constant registers, the pixel shader constant registers are read only. There are at least eight constant registers in DirectX 8 and 32 in DirectX 9, but generally only one can be used at a time in a single pixel shader instruction (Table 8.4).

Table 8.4: Constant Register Propertis

PS VERSION

1.0

1.1

1.2

1.3

1.4

2.0

NUMBER

8

8

8

8

8

32

PORT LIMITS

2

2

2

2

2

2

READ/WRITE?

RO

RO

RO

RO

RO

RO

RANGE

1,1

1,1

1,1

1,1

1,1

16- or 32- bit float precision

Because of the limited precision of DirectX 8 pixel shader math (the register values might be represented internally by a fixed point representation), pixel shader constant registers can only have a range of [1, 1].

 

DirectX 9 pixel shader constants are at least 16-bit floating point values. You set pixel shader constant registers either by using the def instruction in the shader or by using SetPixelShaderConstant(). Unlike vertex shaders, the def instruction requires no other effort from the programmer; the constant values are set when the shader is loaded. You can override values set in the shader using the def instruction after the shader is loaded by a subsequent call to SetPixelShaderConstant().

 

In DirectX 9 pixel shader the def instruction will push the previous value of the constant and pop it when the shader exits.

You generally cannot use constant registers with the texture instructions—the exception being the texm3x3spec instruction.

t[n]: the Texture Registers

Unlike vertex shaders (which have texture coordinate registers), pixel shaders up to PS 1.4 have texture color registers. For PS 2.0 they are texture coordinate registers. The number of texture registers is shown in Table 8.5.

Table 8.5: Texture Register Properties

PS VERSION

1.0

1.1

1.2

1.3

1.4

2.0

NUMBER

4

4

4

4

6

8

PORT LIMITS

1

2

3

3

1

1

READ/WRITE?

[*]

RW

RW

RW

RO

RO

RANGE

±Max

±Max

±Max

±Max

±Max

±Max

 

Pixel-

Pixel-

Pixel-

Pixel-

Texture-

Texture-

 

Shader

Shader

Shader

Shader

Repeat

Repeat

 

Value

Value

Value

Value

  

[*]For PS 1.0, the texture registers are read/write for texture addressing instructions, but read only for arithmetic instructions.

There is a significant difference between the way that the texture registers are used between pixel shaders 1.0 though 1.3 and pixel shaders 1.4, and again at pixel shaders 2.0.

For Pixel Shaders 1.1 Through 1.3

The value in the texture register is a sample of the texture at the interpolated point—that is, it's a color value. The interpolated value consists of (u, v, w, q) data, as interpolated from the current texture stage attributes. There is a one-to-one association between the texture stage and the texture coordinate declaration order. This means that the texture selected in stage n will provide the color values passed into the pixel shader in the texture registers. Texture coordinates are read/write, which means that you can use them as temporary registers if necessary.

For Pixel Shaders 1.4

The texture registers for 1.4 pixel shaders should be thought of as texture coordinate registers since they can contain only read-only texture coordinates. This means that the data in the texture register is not color data as in previous pixel shader versions. The texcrd instruction is used to pass texture coordinates, and the texld instruction is used to sample a texture. Texture samples will end up in temporary registers.

The texture stage that is used to sample from is no longer associated with the texture coordinate declaration order, but is determined by the destination register number. Thus when you actually load a texture value using texld, the texture register used as the source register will contain the texture coordinate information, while the destination register number will correspond to the texture to sample.

Initialized texture registers contain the output from the texture-sampling units after any filtering modes set for that texture stage. Unused, uninitialized texture registers have a setting of opaque black (0,0,0,1). It also means that you can no longer use them as temporary registers.

Loading a texture coordinate will place only three components into the register, even though a texture coordinate starts out as a four element register. Thus you have to use a destination register write mask when using the texld or texcrd instruction.

If you want to perform a perspective divide in a PS 1.4, the D3DTTFF_PROJECTED flag is ignored. You can perform a perspective divide on the .x and .y texture coordinates using the _dw modifier, and the results require a .xy write mask.

For Pixel Shaders 2.0

In order to end confusion about texture coordinates vs. texture sampling using the texture registers, the PS 2.0 model breaks these into two separate sets of registers.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net