I am trying to write a Pixelshader for a curve effect in Direct2d.

A curve effect maps each color channel value to a different value by using a look up table.

For this effect I would need to pass 3 arrays to the effect. Each array has 256 entries to map the specific color channel.

How can I pass these arrays to a Pixel shader (i.e. Direct2d Effect)?


You can pass arrays as 1D textures (which usually are 2D textures with height set to 1). Or 2D, if you need to store more than 2048/4096/8192 items - depending on graphics card. A 1D texture look-up is done by dividing array index by array size and then aligned to pixel centers with the required offsets. A 2D texture look-up is about the same, the only difference being texture coordinate calculation from array index - it's something like this with 2D textures:

float2 texcoord = ( float2( array_index % texture_width, array_index / texture_height ) + texel_offset ) / float2( texture_width, texture_height );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.