{"action":"created","issue":{"url":"https://api.github.com/repos/pixijs/pixi.js/issues/5218","repository_url":"https://api.github.com/repos/pixijs/pixi.js","labels_url":"https://api.github.com/repos/pixijs/pixi.js/issues/5218/labels{/name}","comments_url":"https://api.github.com/repos/pixijs/pixi.js/issues/5218/comments","events_url":"https://api.github.com/repos/pixijs/pixi.js/issues/5218/events","html_url":"https://github.com/pixijs/pixi.js/pull/5218","id":380680406,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwODIxMTcw","number":5218,"title":"UV precision bug","user":{"login":"ivanpopelyshev","id":695831,"node_id":"MDQ6VXNlcjY5NTgzMQ==","avatar_url":"https://avatars2.githubusercontent.com/u/695831?v=4","gravatar_id":"","url":"https://api.github.com/users/ivanpopelyshev","html_url":"https://github.com/ivanpopelyshev","followers_url":"https://api.github.com/users/ivanpopelyshev/followers","following_url":"https://api.github.com/users/ivanpopelyshev/following{/other_user}","gists_url":"https://api.github.com/users/ivanpopelyshev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivanpopelyshev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivanpopelyshev/subscriptions","organizations_url":"https://api.github.com/users/ivanpopelyshev/orgs","repos_url":"https://api.github.com/users/ivanpopelyshev/repos","events_url":"https://api.github.com/users/ivanpopelyshev/events{/privacy}","received_events_url":"https://api.github.com/users/ivanpopelyshev/received_events","type":"User","site_admin":false},"labels":[{"id":434340100,"node_id":"MDU6TGFiZWw0MzQzNDAxMDA=","url":"https://api.github.com/repos/pixijs/pixi.js/labels/Priority:%20Critical","name":"Priority: Critical","color":"b60205","default":false},{"id":175480669,"node_id":"MDU6TGFiZWwxNzU0ODA2Njk=","url":"https://api.github.com/repos/pixijs/pixi.js/labels/Renderer:%20WebGL","name":"Renderer: WebGL","color":"bfe5bf","default":false},{"id":25645768,"node_id":"MDU6TGFiZWwyNTY0NTc2OA==","url":"https://api.github.com/repos/pixijs/pixi.js/labels/Type:%20Bug","name":"Type: Bug","color":"fc2929","default":false},{"id":447633425,"node_id":"MDU6TGFiZWw0NDc2MzM0MjU=","url":"https://api.github.com/repos/pixijs/pixi.js/labels/Version:%20v4.x","name":"Version: v4.x","color":"5319e7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-14T12:41:30Z","updated_at":"2018-11-15T22:51:16Z","closed_at":"2018-11-14T18:34:19Z","author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/pixijs/pixi.js/pulls/5218","html_url":"https://github.com/pixijs/pixi.js/pull/5218","diff_url":"https://github.com/pixijs/pixi.js/pull/5218.diff","patch_url":"https://github.com/pixijs/pixi.js/pull/5218.patch"},"body":"# We lose one binary digit in UV's and its critical\r\n\r\nThis thing exists through all the life of pixi-v4, since 6 jan 2016, it leads to wrong rendering of sprites with LINEAR scaleMode (it is default!).\r\n\r\nThe thing is, for numbers like `1/1024` we always lose 1 digit, when we actually dont have to lose anything.\r\n\r\n```\r\n1/1024 - Math.round(1 / 1024 * 65535) / 65535 === -1.4901388570992546e-8\r\n1/1024 - Math.floor(1 / 1024 * 65535) / 65535 === 1.5244120508125375e-5\r\n```\r\n\r\nFor center pixel loss is the same for both algorithms:\r\n```\r\n0.5 - Math.round(0.5 * 65535) / 65535 === -7.629510948348184e-6\r\n0.5 - Math.floor(0.5 * 65535) / 65535 === 7.629510948348184e-6\r\n```\r\n\r\nSize of pixel 1/1024 is `1e-3`  , one point of color is `2e-2` , if we multiply it we'll get `2e-5`, too close to our precision loss. Experiments show that 1 binary digit in the case is critical. We have to get rid of `1.5e-5`.\r\n\r\nLets put single pixel inside an atlas of size 1024 and render it: https://www.pixiplayground.com/#/edit/sr8e~10Ueu1aaaVlj~Rsd\r\n\r\nWe got alpha=247 and that number is even worse for size=2048. If we put the pixel to (1024,1024) instead of (1,1) we will get 251, which is still wrong!\r\n\r\nWe even lose on size=256!\r\n\r\nYou can also notice the shift in coords if we enlarge the pixel:\r\n\r\n![image](https://user-images.githubusercontent.com/695831/48483182-d3389400-e823-11e8-9c3e-038424002e3e.png)\r\n\r\nThis is the bug we tried to fix with `PRECISION_FRAGMENT=HIGHP`. Docs say that on MEDIUMP we always have 16 binary digits which is exactly how much we use when we pack numbers in uint16. \r\n\r\nMEDIUMP (16 bits) is enough for sprite rendering, while 15 is not."},"comment":{"url":"https://api.github.com/repos/pixijs/pixi.js/issues/comments/439219309","html_url":"https://github.com/pixijs/pixi.js/pull/5218#issuecomment-439219309","issue_url":"https://api.github.com/repos/pixijs/pixi.js/issues/5218","id":439219309,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTIxOTMwOQ==","user":{"login":"ivanpopelyshev","id":695831,"node_id":"MDQ6VXNlcjY5NTgzMQ==","avatar_url":"https://avatars2.githubusercontent.com/u/695831?v=4","gravatar_id":"","url":"https://api.github.com/users/ivanpopelyshev","html_url":"https://github.com/ivanpopelyshev","followers_url":"https://api.github.com/users/ivanpopelyshev/followers","following_url":"https://api.github.com/users/ivanpopelyshev/following{/other_user}","gists_url":"https://api.github.com/users/ivanpopelyshev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivanpopelyshev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivanpopelyshev/subscriptions","organizations_url":"https://api.github.com/users/ivanpopelyshev/orgs","repos_url":"https://api.github.com/users/ivanpopelyshev/repos","events_url":"https://api.github.com/users/ivanpopelyshev/events{/privacy}","received_events_url":"https://api.github.com/users/ivanpopelyshev/received_events","type":"User","site_admin":false},"created_at":"2018-11-15T22:51:16Z","updated_at":"2018-11-15T22:51:16Z","author_association":"MEMBER","body":"Also, bad news. Take my pixi-playground example and try put `px=894` there. It'll give you 253, and for `px=600` it'll be 251.\r\n\r\nLets try bigger texture: `size=8192`. The most extreme case, `px=4090` i've got 224. \r\n`size=4096`, `px=2040` , result is 239.\r\n\r\nWe still got slight precision loss, but for our old code i've got 195."}}
{"actor":{"display_login":"ivanpopelyshev"}}