Search Unity

Render sprite pixel perfect on rendertexture

Discussion in '2D' started by CineTek, Mar 10, 2016.

  1. CineTek

    CineTek

    Joined:
    Jul 12, 2013
    Posts:
    98
    Hey there,

    I am currently mixing up 2D and 3D levels together and want to render a pixel perfect sprite onto a monitor (plane).


    My 2D sprite has the following dimensions:
    256x229 (PixelsPerUnit=1)
    It looks perfectly fine if I render it with the normal camera but as soon as I specify a rendertexture as the target the problem is that the pixels of the rendertexture do not seem to be even... some of them are bigger, some smaller, etc.

    My rendertexture is setup like this:
    256x256 (there should be a little bit space to the bottom)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It sounds like you don't have your render camera set up correctly, so it's having to stretch the sprite into the destination texture.

    It's fixable, if you set everything up just right. But, FYI, PixelSurface makes this sort of thing really easy. :)
     
  3. Douvantzis

    Douvantzis

    Joined:
    Mar 21, 2016
    Posts:
    79
    You need to adjust the camera's orthographic size so that when your sprite gets rendered on the render texture, each sprite pixel gets rendered to an integer multiple of render texture pixels. In your case, (if pixels per unit are 1) the camera's orthographic size should be: 256/2 = 128

    You also have to make sure that the "normal" camera has the correct size to render the render texture in a pixel perfect way on screen.

    I have created a simple camera script that does this calculation for you. You can get it for free: https://www.assetstore.unity3d.com/en/#!/content/64563
     
    JoeStrout likes this.