Archived

This topic is now archived and is closed to further replies.

Robbo

Pixel shader to make alpha 0 if all r.g.b are zero?

Recommended Posts

Robbo    122
Hi there, I''m using ps 1_1 at the mo and need a way of forcing the alpha value of my texel to zero if all of the input r.g.b values are zero. I''m kind of wanting to colour key here. I cannot use the alpha channel on one of my textures because it needs to be written to by GDI and GDI doesn''t understand alpha too well. I can''t see how to do this. Any hints?

Share this post


Link to post
Share on other sites
MENTAL    383
okay, i don''t know the dx pixel language syntax, but something like this would work:

Temp = Pixel.R + Pixel.G + Pixel.B

Temp = Temp * 255
Pixel.A = Min (Pixel.A, 255)

Lets say RGB = 127, 3, 255

Temp = 127 + 3 + 255
Temp = 385

Temp = 385 * 255
Temp = 98175

Pixel.A = Min (98175, 255)

Pixel.A = 255

However, if a totally black pixel comes in

Temp = 0 + 0 + 0
Temp = 0

Temp = Temp * 255
Temp = 0;

Pixel.A = Min (0, 255)
Pixel.A = 0

As long as R+G+B isn''t black the pixel will always be full alpha. Otherwise it''ll be totally transparent. All it needs is for one of the RGB components to be 1 or more to ensure that Temp is 255 or more. If Temp is 255, the pixel shader will select the lowest (but as you''re comparing it to 255, the pixel will be fullbright).

I hope that helps. Not having an "if" and "else" sucks doesnt it

Share this post


Link to post
Share on other sites
Robbo    122

Hmmm - yes I can see how that would work, but the problem is, I can''t see how to do it with stupid pixel shader 1.1! I have a GeForce 3 here, doesn''t support ps 2 or 3! Sucky or what

Share this post


Link to post
Share on other sites
Robbo    122

I did it with a slight compromise. I can swizzle the blue component into the alpha channel with ps 1_1, so as long as a pixel has a blue colour value > 0 it will be displayed with alpha test enabled, else it won''t be. This works nicely!

Share this post


Link to post
Share on other sites