Archived

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

walkingcarcass

contrast and saturation type thing

Recommended Posts

I want my pixel shader to have a "greyscale" value where 1 is full unmodified colour [r,g,b] and 0 is grey in all channels [(r+g+b)/3,","]. Basically, once the pixel is computed, it is adjusted according to wether I want b/w, normal colour or something in between. How should I implement this? ******** A Problem Worthy of Attack Proves It''s Worth by Fighting Back

Share this post


Link to post
Share on other sites
If you use register combiners, then your contrast and saturartion type thing will be at its most portable, for even the GeForce 1 & 2 cards can have register combiner programs written for them. Thanks to nVidia, there''s a lot of beginner information for us, but it''s all in wasteful pdf space, so you''ll have to refer to it like an ebook. I think the most valuable thing about ''using register combiners'' would be that you don''t need anymore drivers than what you already have. I mean the basic state change functions are standard in OpenGL. Then only things different (different like a shader language is to the OpenGL library), are the GPU card-specific state variables. Don''t ask me anything about them, I only know where to read about them: nVidia Developers'' GeForce RegCom Resource
Oh! And nVidia also has working demos for you. Last week I dled the "saturation" one, I think. It was new and cool, like shaders are, but without being foreign to me.

Share this post


Link to post
Share on other sites
wtf are you talking about, Californium ? You know, changing your username will not change your troll status. Pfff... *shakes head*

Anyway.

quote:

I want my pixel shader to have a "greyscale" value where 1 is full unmodified colour [r,g,b] and 0 is grey in all channels [(r+g+b)/3,","].

Basically, once the pixel is computed, it is adjusted according to wether I want b/w, normal colour or something in between.

How should I implement this?


Hmm, how compatible do you want it to be ? The easiest (and generally fastest) way is to precompute the greyscale value of a texture texel, and store it in the alpha channel. In your shader, you then simply interpolate between the RGB part and the monochrome alpha part, routed to the RGB channels. This will of course only work, if your fragments primarily come from a texture (although lighting shouldn''t be a problem, if you also apply it to the alpha channel. Just treat your texture alpha channel as a fourth colour channel).

The next option is to compute the greyscale value from the RGB components in the shader. That''s no problem on DX9 type hardware, but on pre-DX9, there is unfortunately no easy way to add RGB components together. The only widely available perpixel operator that does that, is DOT3. The equation looks something like: grey = Red*Red_weight + Green*Green_weight + Blue*Blue_weight. You can store the 3 weights in a constant colour register. But be carefull about the range mappings, and wether the computations become negative or saturated. You might need to include a range compensation factor into the weighting, and perhaps rescale the result.

Once you have the greyscale value in the RGB channels, simply interpolate from your primary RGB colour to the monochrome one, using the alpha channel for example.

You might want to take a look at an OpenGL 3x3 perpixel colour matrix implementation. It can also be used to make an image monochrome, but it''s a bit overkill for that task alone (very resource hungry). But you can check out the source to get the DOT3 mapping ranges right (assuming you use OpenGL).

Share this post


Link to post
Share on other sites