View Full Version : Replace texture colors in real-time

Mandar Dilip Sahasrabuddhe
06-10-2004, 01:02 AM
Hi all,

I am writing volume rendering s/w using 2D textures. In this I wish to implement a color filters. The functionality is to remove from final image, all the pixels with RGB values below / above certain threshold value. In another functionality the pixels above and below the upper / lower threshold are to be replaced with max / min color intensities respectively.

I have achieved this by modifying the original images and then regenerating the 2D textures. However this is time consuming. I would like to know if there is any facility to do this on the fly, in real-time, without re-generating the textures, whereby the user can change the filter values and get the response instantly.

Any guidance is highly appreciated.


06-10-2004, 02:54 AM
Any reason not to use a fragment program?

06-10-2004, 02:57 AM
With the filter values going in either as one of the standard inputs, like color, or secondary color, or perhaps as an explicit parameter to the fragment program?

Mandar Dilip Sahasrabuddhe
06-12-2004, 02:41 AM

Charliejay, thanks for the suggestion of using fragment programs. On those lines, I wrote two separate fragment programs on grayscale value of a pixel,
1. Band pass filter
2. Brightness-darkness thresholding

However, when I bind both programs one after the other, it seems that only the last one has effect and the earlier is lost! Drawing parallels with simple texture binding, it appears that only one fragment program can be bound at a time. But, on the lines of multitexturing, is there a facility to bind multiple fragment programs and have their effect at the same time?

For the time being, I have merged both the programs into one. Although I get effect of both the filters now, the performance has tremendously degraded. From various posts, I understand that this is a known drawback.

For optimization purpose, I find that there is no point in doing further processing on the fragment if it is rejected by the band pass filter (the 1st step). I plan to set the "w" component for this fragment to -ve value and reject it using instruction,

KIL frag.w

Can I expect end to the fragment program after execution of this instruction, just as it happens in an intermediate conditional return in C. Or does the program execution continue even after this instruction? If the later is true (as found in some posts on some forums), is there any way of aborting the further processing of the fragment / pixel, depending on certain conditions?

Also can any one suggest some methods of optimizing the fragment programs?

Thanks in advance,

06-12-2004, 08:14 AM
You must merge the fragment programs manually, there is no language facility to merge them automatically.

A fragment program will not run faster when you use KIL; the GPU will still execute all operations and discard the fragment at the end. This is to avoid pipelining problems in the hardware.

Note that using KIL will often negate any accelerated Z culling, so it may actually slow rendering down, depending on the hardware.