Monday, December 3, 2018

directx - Bitwise operators in DX9 ps_2_0 shader


I've got the following code in a shader:


// v & y are both uints
nPixel = v;
nPixel << 8;
nPixel |= y;

and this gives me the following error in compilation:


shader.fx(80,10): error X3535: Bitwise operations not supported on legacy targets.
shader.fx(92,18): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression

ID3DXEffectCompiler: Compilation failed

The error is on the following line:


nPixel |= y;

What am I doing wrong here?



Answer



Bitwise operations and integer operations were new for SM 4.0/DX10. As your error says:



Bitwise operations not supported on legacy targets.




You'll have to target DX10.


Alternatively, this blog post suggests using a texture to map results of AND,OR,XOR to different color channels.


enter image description here


bitwise operators texture: AND,OR,XOR


Seems plausible, and might be faster than the alternative I suggested in the comments.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...