Thursday, May 23, 2019

hlsl - Pass large array to pixel shader


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)?



Answer



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 );

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...