This function is pretty complicated, I don't understand it entirely but wouldn't it be simpler to give a view id to whatever function needs this modified pass index,  rather than trying to compute the modified pass index?