FR
games/rob-revisited / src / Revisited / Render / Atlas.php · commit f9a1307
<?phpnamespace App\Revisited\Render;/** * The props atlas (assets/revisited/props.png, made by tools/reborn/textures.py): 8 x 8 cells of 256 pixels * (2048 x 2048). Its alpha (cut-out of the foliage, hair, reeds...) is read through Graphics' fast loader: * see Shaders (opacity = 1 - a * 2.0078). */final class Atlas{    public const BARK = 0;    public const PALM = 1;    public const LEAVES = 2;    public const FROND = 3;    public const NEEDLES = 4;    public const BERRY = 5;    public const STONE = 6;    public const METAL = 7;    public const PLANKS = 8;    public const FABRIC = 9;    public const THATCH = 10;    public const FUR = 11;    public const SKIN = 12;    public const BLADES = 13;    public const BONE = 14;    public const PLAIN = 15;    public const BARK_JUNGLE = 16;    public const BIG_LEAVES = 17;    public const FERN = 18;    public const REEDS = 19;    public const TUFT = 20;    public const LIANA = 21;    public const HULL = 22;    public const CHAR = 23;    public const BASALT = 24;    public const ROPE = 25;    public const PATTERN = 26;    public const LEATHER = 27;    public const HAIR = 28;    public const FEATHERS = 29;    public const SCALES = 30;    public const CHITIN = 31;    public const SCREEN = 32;    public const MOSS = 33;    public const LEAVES_SMALL = 34;    public const FLOWERS = 35;    public const RUST = 36;    private const GRID = 8;    /** a margin inside each cell (filtering and mipmaps never read the neighbour much) */    private const INSET = 0.014;    /** @return array{0: float, 1: float} atlas coordinates of (u, v) inside $cell */    public static function uv(int $cell, float $u, float $v): array    {        $u = $u < 0 ? 0.0 : ($u > 1 ? 1.0 : $u);        $v = $v < 0 ? 0.0 : ($v > 1 ? 1.0 : $v);        $k = 1.0 / self::GRID;        return [            (($cell % self::GRID) + self::INSET + $u * (1 - 2 * self::INSET)) * $k,            (intdiv($cell, self::GRID) + self::INSET + $v * (1 - 2 * self::INSET)) * $k,        ];    }}