?/TD>
Microsoft DirectX 9.0

cnd (Pixel Shader)


Conditionally chooses between src1 and src2, based on the comparison src0 > 0.5.

Syntax

cnd dst, src0, src1, src2

where

Remarks

Pixel shader versions1_11_21_31_42_02_x2_sw3_03_sw
cndxxxx

For versions 1_1 to 1_3, src0 must be r0.a.

// Version 1.1 to 1.3
if (r0.a > 0.5)
  dest = src1
else
  dest = src2

Version 1.4 compares each channel separately.

for each component in src0
{
   if (src0.component > 0.5)
     dest.component = src1.component
   else
     dest.component = src2.component
}

These examples show a four-channel comparison done in a version 1_4 shader, as well as a single-channel comparison possible in a version 1_1 shader.

ps_1_4
def c0, -0.5, 0.5, 0, 0.6
def c1,  0,0,0,0
def c2,  1,1,1,1

cnd r1, c0, c1, c2   // r0 contains 1,1,1,0 because
// r1.x = c2.x because c0.x <= 0.5
// r1.y = c2.y because c0.y <= 0.5
// r1.z = c2.z because c0.z <= 0.5
// r1.w = c1.w because c0.w >  0.5

Version 1_1 to 1_3 compares against the replicated alpha channel of r0 only.

ps_1_1
def c0, -0.5, 0.5, 0, 0.6
def c1,  0,0,0,0
def c2,  1,1,1,1
mov r0, c0
cnd r1, r0.a, c1, c2   // r1 gets assigned 0,0,0,0 because 
                       //   r0.a > 0.5, therefore r1.xyzw = c1.xyzw

This example compares two values, A and B. The example assumes A is loaded into v0 and B is loaded into v1. Both A and B must be in the range of -1 to +1, and since the color registers (vn) are defined to be between 0 and 1, the restriction happens to be satisfied in this example.

ps_1_1                // version instruction
sub r0, v0, v1_bias   // r0 = A - (B - 0.5)
cnd r0, r0.a, c0, c1  // r0 = ( A > B ? c0 : c1 )

// The result in r0 is c0 if A > B. Otherwise, the result in r0 is c1.

Instruction Information

Minimum operating systemWindows 98


© 2002 Microsoft Corporation. All rights reserved.