Hello Guest

Author Topic: Pixel perfect in a perspective camera (or combining 3D with 2D)  (Read 9735 times)

Malharhak

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hello
« Last Edit: February 24, 2023, 08:46:45 pm by Malharhak »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Pixel perfect in a perspective camera (or combining 3D with 2D)
« Reply #1 on: May 18, 2013, 10:10:20 pm »
An easy way to go about this, just create the sprites in 3d with the rest of the objects, and then call sprite.MakePixelPerfect() every frame. This will rescale the sprite to appear pixel perfect on the main camera.

The alternative is to have a second camera (orthographic) -
use camera.WorldToScreenPoint on the first camera to get where your 3d point will be on screen, then update the position of the sprite using camera.ScreenToWorldPoint on the second (orthographic) camera. The nice thing about this method is you don't need to adjust scale.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Pixel perfect in a perspective camera (or combining 3D with 2D)
« Reply #2 on: May 19, 2013, 12:39:23 pm »
1. Your sprite collection? Doesn't matter - since you're calling make pixel perfect on it, it doesn't matter what the size is set. The sprite going big/small is expected - the further away it is from the camera the bigger it must be to be pixel perfect, no?

2. You should rotate it. Again - this isn't necessary if you do option #2 from before, as you'll be drawing the sprite into a different camera.

3. You requested a way of making the sprite pixel perfect - it would be the same size everywhere on screen if it was pixel perfect, wouldn't it? i.e. 1 pixel in texture = 1 pixel on screen. Thats why it gets bigger and smaller with the perspective camera.