>  Docs Center  >  Using IDL  >  Uniform Variable for LUT Example

Uniform Variable for LUT Example

Uniform Variable for LUT Example

In this example, a uniform variable named lut contains the values of the 256-element array of color table values. This can either be a custom LUT such as an enhanced greyscale color table, or one of the predefined IDL LUTs.

The following code creates a greyscale LUT defined by a curve rather than a linear ramp, making the dark areas darker and the light areas lighter. Notice that the 256- entry LUT is loaded into a one-dimensional image (an IDLgrImage object with IMAGE_1D property set). This IDLgrImage is automatically converted into a texture map for use by the shader. SetUniformVariable is called with the name of the uniform variable and the value (the image object) so the shader can access the texture map containing the LUT.

; Create enhanced grayscale LUT and store in 1-D IDLgrImage.
x = 2*!PI/256 * FINDGEN(256) ;; 0 to 2 pi
lut = BYTE(BINDGEN(256) - SIN(x)*30) ;; Create 256 entry
oLUT = OBJ_NEW('IDLgrImage', lut, /IMAGE_1D)
; Store LUT in uniform variable named lut.
self->SetUniformVariable, 'lut', oLUT

Note: The uniform variable name is case-sensitive, unlike most variable names in IDL.

The LUT is loaded into a texture map instead of a uniform variable array because it is more efficient to load and index the LUT when it is in a texture. In addition, under certain circumstances you can use bilinear filtering to interpolate between values in the LUT if it is in a texture map.

A side effect of using a texture map is it is limited by the maximum texture size (MAX_TEXTURE_DIMENSIONS in IDLgrWindow::GetDeviceInfo). On most hardware today this is 4096 by 4096 pixels, so if your LUT is larger than this you will need to work around this limitation (using a 2-D texture map is one possible solution). Also, as texture maps must be a power of 2 in size (128, 256, 512, 1024, etc.), ensure the size of your LUT is a power of 2 to keep it from being scaled to the next higher power of 2.

To display palletized images or to add color to greyscale images, load an RGB LUT into the 1D IDLgrImage rather than a greyscale LUT. The shader code remains exactly the same. (The shader_lut_doc__define.pro program lets you apply either the enhanced greyscale or one of IDL’s pre-defined colortables.)

© 2020 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us