• Create Account

### #Actualderrace

Posted 23 November 2012 - 03:00 AM

Texture coordinates range between (0, 1), not (0, n). Divide your index by n, where n is the number of texels (4 in your case).

Also, if this is DX9, you need to apply the half texel offset so that you're sampling from the middle of the texel (sampling from the edge will be "unstable"). So add (0.5 / 4) to the index.

And make sure you're using point sampling.

Ah, 0 to 1. Got it. In my script, I don't think I need to do any division as it would probably have done it for me. When setting up my colourtable, I would just multiply it by 255 since I am using the bands of the pixel as my index.

Got my algo for pixel shader for palette swap sorta working.. but I am having some issues with it.

http://imgur.com/3pPnO

Bands aren't unique, so I am taking the average of RGB as my index. I don't get a whole number, but I made each lookup area 3x1 (i need to increase it to 3). I am not sure if it's the decimals that is causing the issue. I will need to debug further. Also, I have two default colours with the same value, but expecting different palette swaps.. How can this be achieved?

for now just assume my colour table is 255 x 10. I will hardcode the dividers as well as the y index for now.

[source lang="java"]float4 colour = tex2D(input, coords);float2 index = float2((colour.r + colour.g+colour.b)/3.0 , 4/10.0 + 0.5 / 10.0);float4 lookUp = tex2D(PaletteSampler,index);if(colour.a != 0) { colour.rgb = lookUp.rgb;} return colour;[/source]

sorry, what do you mean by point sampling? Isn't the above point sampling?

### #2derrace

Posted 23 November 2012 - 02:57 AM

Texture coordinates range between (0, 1), not (0, n). Divide your index by n, where n is the number of texels (4 in your case).

Also, if this is DX9, you need to apply the half texel offset so that you're sampling from the middle of the texel (sampling from the edge will be "unstable"). So add (0.5 / 4) to the index.

And make sure you're using point sampling.

Ah, 0 to 1. Got it. In my script, I don't think I need to do any division as it would probably have done it for me. When setting up my colourtable, I would just multiply it by 255 since I am using the bands of the pixel as my index.

Got my algo for pixel shader for palette swap sorta working.. but I am having some issues with it.

http://imgur.com/3pPnO

Bands aren't unique, so I am taking the average of RGB as my index. I don't get a whole number, but I made each lookup area 3x1 (i need to increase it to 3). I am not sure if it's the decimals that is causing the issue. I will need to debug further.

for now just assume my colour table is 255 x 10. I will hardcode the dividers as well as the y index for now.

[source lang="java"]float4 colour = tex2D(input, coords);float2 index = float2((colour.r + colour.g+colour.b)/3.0 , 4/10.0 + 0.5 / 10.0);float4 lookUp = tex2D(PaletteSampler,index);if(colour.a != 0) { colour.rgb = lookUp.rgb;} return colour;[/source]

sorry, what do you mean by point sampling? Isn't the above point sampling?

### #1derrace

Posted 23 November 2012 - 02:55 AM

Texture coordinates range between (0, 1), not (0, n). Divide your index by n, where n is the number of texels (4 in your case).

Also, if this is DX9, you need to apply the half texel offset so that you're sampling from the middle of the texel (sampling from the edge will be "unstable"). So add (0.5 / 4) to the index.

And make sure you're using point sampling.

Ah, 0 to 1. Got it. In my script, I don't think I need to do any division as it would probably have done it for me. When setting up my colourtable, I would just multiply it by 255 since I am using the bands of the pixel as my index.

Got my algo for pixel shader for palette swap sorta working.. but I am having some issues with it.

http://imgur.com/3pPnO

Bands aren't unique, so I am taking the average of RGB as my index. I don't get a whole number, but I made each lookup area 3x1 (i need to increase it to 3). I am not sure if it's the decimals that is causing the issue. I will need to debug further.

[source lang="java"]float4 colour = tex2D(input, coords); float2 index = float2((colour.r + colour.g+colour.b)/3.0 , 4/10.0 + 0.5 / 10.0);float4 lookUp = tex2D(PaletteSampler,index);if(colour.a != 0) { colour.rgb = lookUp.rgb;} return colour;[/source]

sorry, what do you mean by point sampling? Isn't the above point sampling?

PARTNERS