I am writing I SlimDX application to test color contrast sensitivity thresholds of the human visual system. The subject is presented with a large letter that is at low contrast with with the background and asked to identify the letter. However I need the ability to display more colors then is available with a simple 8bit per channel color depth. (i.e. rgb values 0-255). The way I plan to due this is through a simple "dithering" algorithm implemented as an HLSL pixel shader. Basically if request slimDX to render the text to a surface with a color of Color4( 0.55f, 0.55f, 0.55f ) which corresponds to a rgb value of ( 140.25 , 140.25 , 140.25 ) I want each color channel of each pixel to have a 25% chance of being set to 141 and a 75% chance of getting set to 140. This should (in the limit of many pixels) lead to a letter that appears as a shade of gray one 1/4 of the way in-between 140 and 141.I am however getting errors in my prototype shader code when trying to compile with fxc. I am getting an Illegal character code when I compile and I don't know why. Also if you are a HLSL guru please look over my code and make any comments that strike you. Note I got the HLSL random function from an answer to this question. http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader

Below is my shader code. Please forgive me if there a many mistakes as its my first HLSL code:

I'm not sure why you'd get an "illegal character" error. Perhaps the encoding of the file you saved is incorrect? I think fxc can only work with plain ANSI text files.

Anyway I had to make a few changes to get your shader to compile. You need to declare a sampler2D named s0, since you try to use one. The random function needs to be declared before DitherByChance, since that function uses it. Also the random code you got was in GLSL, and had to be converted. Here's a new version:

I'm not sure why you'd get an "illegal character" error. Perhaps the encoding of the file you saved is incorrect? I think fxc can only work with plain ANSI text files.

Anyway I had to make a few changes to get your shader to compile. You need to declare a sampler2D named s0, since you try to use one. The random function needs to be declared before DitherByChance, since that function uses it. Also the random code you got was in GLSL, and had to be converted. Here's a new version:

Thank you so much! My file was indeed encoded in UTF-8 which does blow up fxc. Your conversion of the GLSL code fixed the rest of my problems. I am struggling right now with figuring out how to use my effect when rendering 2d textures with spritebatch but if I can't figure it out I will post my problems here again. Thanks you again for your help.