3 Replies - 666 Views - Last Post: 22 November 2012 - 01:05 PM Rate Topic: -----

#1 derrace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

HLSL Pixel Shader that does palette swap

Posted 21 November 2012 - 08:41 PM

Hi there,

I have implemented a simple pixel shader which can replace a particular colour in a sprite with another colour.

It looks something like this:


sampler input : register(s0);
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0 
{  
    float4 colour = tex2D(input, coords); 

    if(colour.r == sourceColours[0].r &&
    colour.g == sourceColours[0].g &&
    colour.b == sourceColours[0].B)/> return targetColours[0];

    return colour; 
} 



What I would like to do is have the function take in 2 textures, a default table, and a lookup table (both same dimensions).

Grab the current pixel, and find the location XY (coords) of the matching RGB in the default table, and then substitute it with the colour found in the lookup table at XY.

I have figured how to pass the Textures from C# into the function, but I am not sure how to find the coords in the default table by matching the colour.

Could someone kindly assist?

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: HLSL Pixel Shader that does palette swap

#2 derrace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

Re: HLSL Pixel Shader that does palette swap

Posted 22 November 2012 - 01:04 AM

View Postderrace, on 21 November 2012 - 08:41 PM, said:

Hi there,

I have implemented a simple pixel shader which can replace a particular colour in a sprite with another colour.

It looks something like this:


sampler input : register(s0);
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0 
{  
    float4 colour = tex2D(input, coords); 

    if(colour.r == sourceColours[0].r &&
    colour.g == sourceColours[0].g &&
    colour.b == sourceColours[0].B)/>/> return targetColours[0];

    return colour; 
} 



What I would like to do is have the function take in 2 textures, a default table, and a lookup table (both same dimensions).

Grab the current pixel, and find the location XY (coords) of the matching RGB in the default table, and then substitute it with the colour found in the lookup table at XY.

I have figured how to pass the Textures from C# into the function, but I am not sure how to find the coords in the default table by matching the colour.

Could someone kindly assist?

Thanks in advance.



Hmm, think I got it,

It involves using a for loop to cycle through the a variant of the above code but I am getting this silly error now =(

Shader uses texture addressing operations in a dependency chain that is too complex for the target shader model (ps_2_0) to handle.
Was This Post Helpful? 0
  • +
  • -

#3 derrace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 12

Re: HLSL Pixel Shader that does palette swap

Posted 22 November 2012 - 02:07 AM

Ok, I have removed the use of loops and am now using one of the 3 RGB channels as my index.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: HLSL Pixel Shader that does palette swap

Posted 22 November 2012 - 01:05 PM

Is it working?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1