title: Pixel perfect 2d camera in unity
body: <p>I have a very simple script that updates my orthographic camera on a given resolution so that it accurately scales the view to be pixel perfect.</p>
  
  <p>Here is some relevant code:</p>
  
  <pre><code>OrthographicSetting get_override(int size)
  {
      return Overrides.FirstOrDefault(x =&gt; x.OrthographicSize == size);
  }
  
  void update_ortho()
  {
      m_last_size = Screen.height;
  
      float ref_size = (OrthographicSize / PixelsPerUnit) * 0.5f;
  
      OrthographicSetting or = get_override(m_last_size);
      float ppu = or != null ? or.PixelsPerUnit : PixelsPerUnit;
      float ortho_size = (m_last_size / ppu) * 0.5f;
      float multiplier = Mathf.Max(1, Mathf.Round(ortho_size / ref_size));
  
      ortho_size /= multiplier;
  
      this.GetComponent&lt;Camera&gt;().orthographicSize = ortho_size;
  
      Debug.Log(m_last_size + " " + ortho_size + " " + multiplier + " " + ppu);
  }
  
  [System.Serializable]
  public class OrthographicSetting
  {
      public int OrthographicSize;
      public float PixelsPerUnit;
  }
  
  OrthographicSetting get_override(int size)
  {
      return Overrides.FirstOrDefault(x =&gt; x.OrthographicSize == size);
  }
  </code></pre>
  
  <p>With this, i can specify a set of overrides for every resolution. </p>
  
  <p>My current setup is using 100 pixels per unity unit. All of my sprites use point filtering with no compression. Yet i still get strange results. 90% of the sprites render fine, but some seem to be rendering incorrectly.</p>
  
  <p>Here's a screenshot to illustrate:</p>
  
  <p><img src="https://i.stack.imgur.com/P0sws.png" alt="BEEP BOOP COMPUTER"></p>