I’ve come across a weird behavior of my code today, and I hope you can help me figure out this problem. I’m trying to implement a simple color swap code. Here’s the line responsible for swapping colors:
col.rgb = tex2D( _BookPallete, float2( pow( col.r, 1/2.2), 0.0));
Unfortunately, this line is causing some flickering in the pallet swap, as you can see right here:

I’ve spent hours trying to figure this out, and in one attempt I’ve tried to write this same line using a switch statement (going crazy trying to figure this out).
switch( ceil( pow( col.r, 1/2.2) * 5))
{
case 0:
col.rgb = tex2D(_BookPallet, float2( 0.0, 0.0)).rgb;
break;
case 1:
col.rgb = tex2D(_BookPallet, float2( 0.2, 0.0)).rgb;
break;
case 2:
col.rgb = tex2D(_BookPallet, float2( 0.4, 0.0)).rgb;
break;
case 3:
col.rgb = tex2D(_BookPallet, float2( 0.6, 0.0)).rgb;
break;
case 4:
col.rgb = tex2D(_BookPallet, float2( 0.8, 0.0)).rgb;
break;
case 5:
col.rgb = tex2D(_BookPallet, float2( 1.0, 0.0)).rgb;
break;
}

Weirdly enough this actually solves the problem, but I don’t want to keep a gigantic switch in my fragment shader, so, does anyone can explain the issue with my first line of code?
Additional information: This is a panel rendering a render texture, so the main camera is rendering into a render texture, not directly into the Display. Camera recording the game has ProCamera 2D pixel-perfect on it. I’m not sure any of this actually explains this weird code behaviour… but who knows.
Book original sprite
![]()
_BookPallet texture
![]()
Thanks in advance