0
votes

For my project I'm using directx 9 C++. I'm using pixel shader in order to disply a large picture using couple texture in the method of index image (color image).

In order to save texture space, I'd like to store the image's pixes using look up table entries, in order to use the look up tables values as the image pixel values at the pixel shader phase.

I'm using 2 textures , first texture is the image texture, size of 2048^2. The variety of pixesl is 128 pixesl , second texture is the LUT (Look up table) size of 128*1.

I'm using the second texture as an index image (Look up table),

somehow, i find it difficult to sample the value from the first texture (image texture ) --> A[i,j] and sample the second texture at the same spot --> Pixel value = LUT[A[i,j]]

Then, output the pixel value to the screen.

Here is my pixel shader code:

sampler2D layoutSample : register (s0)
sampler2D LUTSampler   : register (s1)

 struct PS_INPUT
 { 
       float2 texture : TEXCOORD0;
       float2 LUT_Texture: TEXCOORD1;
   } 
 struct PS_OUTPUT
   {
         float4 color : COLOR0; 
   }

   PS_OUTPUT ps_main ( in PS_INPUT input )
    {
           PS_OUTPUT out; 
            ///  Sample the first texture - the image texture 
           float4 color = tex2D(layoutSampler, input.Texture); 

           float2 locationInLUT = float2(color.a , 0.0) ; 
           // I WOULD LIKE TO USE: But it's seems like a sampler is neccery for tex2D command 
           ///float4 realColor = tex2D(locationInLUT , input.LUT_Texture); 

           float4 realColor = tex2D(LUTSamplerm , input.LUT_Texture); 

           Out.color = float4(realColor.r, realColor.b, realColor.g, 1.0);

           return Out;
    }
2
Try float4 realColor = tex2D(LUTSampler, locationInLUT);.ErikEsTT
You are right - it's worked ! ThanksTripleS

2 Answers

1
votes

Try

float4 realColor = tex2D(LUTSampler, locationInLUT);

Next time, use FXC compiler and look at error output.

0
votes

Instead of

   float4 realColor = tex2D(LUTSamplerm , input.LUT_Texture); 

Use the following:

   float4 realColor = tex2D(LUTSampler, locationInLUT);