#mapping UVs values from one texture to another
1 messages · Page 1 of 1 (latest)
This is the code I have so far, the output is green which is the first color of the palette
float x = UV.x * 255.0;
float y = UV.y * 255.0;
//float rng = (x + (TextureSize.y - y - 1) * TextureSize.x) * 4;
float rng = (x + y * TextureSize.x) * 4;
float rngMapped = rng / 255.0;
float2 idx = float2(rng,0);
half4 pc = tex2D(PaletteTexture,idx);
teste = pc;```
Since the palette is only horizontal, you don't really have to care about the Y coord.
And for X, I would also add a half pixel offset, just to be sure.
Also, you probably don't want to map the XY coord of the source texture to the palette, this doesn't really make sense ?
Usually, for paletting, sample the sprite, take the pixel value and use it as index of the palette.
It gives something like this :
half colorIndex = tex2D(MainTexture, UV).r;
float x = ( floor( colorIndex * 255.0) + 0.5 ) / 255.0;
float y = 0.5;
half4 pc = tex2D( PaletteTexture, float2( x, y ) );