Image Filter Shaders
Image shader programs are particularly easy to create, for a couple of reasons:
- The IDLgrImage object uses a texture-mapped polygon to draw the image. Most image filters do not change the size or the shape of the image, making it unnecessary to modify the vertices of the polygon. Therefore, a very trivial vertex shader component is all that is required.
- Each image pixel color is going to be completely determined by the image filter calculation, with no lighting or shading effects. Therefore, there is no need to worry about applying lighting and shading calculations in a shader program. This further simplifies the shader program.
There are several ways to incorporate shader functionality into an image processing application. You can either use one of the pre-built shader objects (IDLgrShaderBytscl or IDLgrShaderConvol3) or create a custom shader program. If you design your own shader, you have additional options that include using a IDLgrFilterChain object to link a number of shaders together and apply them successively to the image data. See the following topics for sample applications:
- Library of Pre-built Shader Objects — provides information on the pre-defined IDLgrShaderBytscl and IDLgrShaderConvol3 objects. These are excellent options if you need byte scaling or convolution filtering functionality, and do not want to write custom GLSL shader programs.
- Altering RGB Levels Using a Shader — creates a simple shader program that allows you to interactively alter the red, green or blue levels in an RGB image.
- Applying Lookup Tables Using Shaders — loads a LUT into a one-dimensional image object so that the shader program can efficiently accesses it as a texture map.
- High Precision Images — shows how to display 16-bit and 11-bit images using the full precision of the data and how to display an 11-bit image with a contrast adjustment LUT.
- Filter Chain Shaders — lets you apply a sequence of shaders to a single image object.
Providing a Software Alternative to Shaders
When the appropriate graphics hardware support is missing, a software-based alternative can be provided for image processing applications (when the shader program is associated with an IDLgrImage).
When IDL renders the image and hardware shader support is missing, the IDLgrShader::Filter method is automatically called when the image is drawn. (You never call this method directly.) In this method, add code that provides a software-based equivalent to the shader program functionality that will be used when there is insufficient hardware support for the shader program. See Hardware Requirements for Shaders for graphics card requirements.
Note
When developing a software fallback, use the FORCE_FILTER property during shader object initialization to force the system to test the software-based alternative even when sufficient hardware support is available.
If there is no software fallback specified, application execution simply continues as if there were no shader program. Also, no software fallback is available when a shader is associated with a non-image object.
Caching Shader Results
If a shader object is associated with an IDLgrImage object, you may set the IDLgrShader CACHE_RESULT property to determine whether a shader program is executed every time Draw is called. If this property is set to 1, the image is cached after running the shader program and the cached image is used in subsequent draws until shader program parameters are changed. If this property is set to 0 (the default), the result of running the shader program is not cached. See the property description for details on when each CACHE_RESULT setting may prove more useful. If a software fallback is used, the result is always cached.
Capturing Image Data During Shader Execution
When you apply one or more shader programs to image data, you can capture the results of the image filtering shader operation using the IDLgrImage ReadFilteredData method. Using this method, you can capture a portion of a tiled image, capture the image after applying a single shader, or capture the image after applying any number of shaders in a filter chain sequence. See "IDLgrImage::ReadFilteredData" (IDL Reference Guide) for details. After reading the data, you can place it in a new image object and print or display the result.