Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Do you render texture your pixel art?

Discussion in 'General Discussion' started by TylerPerry, Oct 27, 2013.

  1. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    So, presumably by using a render texture at the same pixel density of your pixel art you would get a pixel perfect game in regards to graphics, this would mean that characters can only move pixel by pixel and all animations would look like sprite movement even if they arnt... Is that how it works? I don't have Unity pro so I can't check, just wondering...
     
  2. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Damn, wrong section... Please move to gossip or something :) Thank you.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You don't need render textures at all. That doesn't solve a single thing and has nothing to do with it. If you want pixel perfect movement, it has to be done in the shader, as this will reliably align to int pixel positions. Assuming pixel perfect is even desired :)
     
  4. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    Render texture is required for a lot of things if you want to do things like rotate sprites and planes while maintaining pixel perfect behaviour.
     
  5. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Are most modern games that have a retro look pixel perfect? I can't seem to recall so I guess its not significant. Every way I have tried it ends up un smooth and not ideal(Moving in increments of the size of a pixel)

    This is part of what I was thinking, I would think a render texture would save a large amount assets by just rotating a low resolution asset? Again maybe it wont matter and will sacrifice the possibility of extremely fluid animations...
     
  6. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    I used a modified version of SimplePixelizer for this when I gave the pro version of Unity a go at home. All I had to do was add some code to where I was grabbing the texture. Thread here.
     
  7. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    How did it turn out MarigoldFleur? Were the results good?
     
  8. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    If you want your game to look exactly like Mode 7 stuff on the SNES? It's actually perfect! Though you need to make extra sure that you don't have any non-integer coordinates otherwise you can get some really awkward scaling issues.
     
  9. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    What do you mean by non-integer coordinates? Like position of transforms or something?
     
  10. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    x: 12, y: 45, z: 0 = GOOD
    x 11.853, y: 45.441, z: 0.11 = BAD
     
  11. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    But for what? As in the objects of the scene? If so, is that only because the colour is taken from the position and will leave some strange looking elements or is there another reason? I would have thought that whatever was the strongest colour within that pixel would have been taken as the colour?
     
  12. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    It'll do the latter in the original code, but this leads to a lot of colour blending and the destruction of sharp colour edges, which looks really gross in practice. I'm at home so this is just a photoshop mockup, but here's some dork from Final Fantasy XII: Revenant Wings:


    4x scale, integer values


    4x scale, float values

    This is exagerrated slightly for effect, but in the second image you can see how it's averaging the pixel colour, which means the pixel scale is still 4x, but everything manages to still look blurry. By using point value sampling for when you capture the render texture, it looks a lot more like the first one than the second.
     
  13. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    What does it look like when it's not "exaggerated slightly for effect"? I'd have thought that with point filtering you'd effectively be rounding to ints as far as sampling is concerned (because sampling pixel 42.111 would get the same value as sampling pixel 42.0) and thus there wouldn't be any difference?
     
  14. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821


    Being a Unity Indie user, I don't have access to Render Textures. What I have is a Sprite Animation script that knows how to get the frame I want to present, and replaces the sprite object's material's image with that texture. I usually use an Unlit/Transparent, but I'm experimenting with some others, at suggestion from others!

    Certainly a render texture would be significantly more efficient than this approach. I'm working up to it...
     
  15. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    I'm not sure why you'd say that or why this thread has even been brought up, RenderTextures are notoriously bad for performance.
     
  16. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    I'm also not sure why you'd need a Render Texture for pixel-art. Though, I LOVED Marigold's art depictions of non-integer positioning! Kudos!

    Gigi
     
  17. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    @Gigiwoo and Meltdown: The difference would primarily be convenience. As it stands, I wind up storing individual frames. When it is a frame's showtime, I pretty much wind up performing SetPixels on a new texture, until that new texture is filled. Then, I assign that texture to the sprite object's material's texture property.

    Again, I don't own Pro edition, so I'm not fully sure that this would necessarily be the case, but instead of having all that code, I would ideally just be able to assign the frame to the sprite object's material's texture property and leave that as that...right?

    Also, what is this about the performance being bad on rendertextures?
     
  18. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    I haven't noticed they were inherently slower than what I expect to see from doing several render passes.

    As for needing an extra texture, does rendering with a quad not cut it? Seems that setting the texture coordinates appropriately and rendering as Pixel (ie no-sample blending) would do the trick without copying into another texture or needing a render texture. As I don't use pixel art, I must be missing something fundamental.

    Gigi
     
  19. Mwsc

    Mwsc

    Joined:
    Aug 26, 2012
    Posts:
    189
    I am genuinely curious what on earth render textures have to do with pixel art, whether they be rotated or scaled or integer or floating point coordinates.
    Can't you just use your pixel art as a texture on a quad, with texture filtering turned off so it doesn't get smoothed out?
     
  20. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    My reasoning for using a render texture is that when my pixel art is on screen I have a virtual resolution and a physical resolution, my virtual resolution is usually much lower than the physical resolution, for example, with some 16x16 sprites a resolution might be 240x160 were my monitor is 1920x1080. The issue arises when I just scale the art up as while sometimes it is correct most of the time pixels can become out of sync with the art making it un authentic.
     
  21. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Can you further explain the pipeline? I imagine putting the sprite on a quad, and rendering that to a render texture and then... the problem starts all over again, you render the new texture to a quad. Where does the render texture help you solve the pixel blending/stretching?

    Gigi
     
  22. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Because the render texture displays in a 'native' 160 by 240 resolution, because that is its resolution objects can't possibly be halfway in a pixel because there are no pixels there for them to occupy.
     
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm still not sure why the obsession with this though. Is pixel perfect so important? Your customers don't notice if it isn't, and don't care if it's not pointed out to them. So long as it looks good.

    Quite a few old retro games weren't pixel perfect at all. It matters because programmers and artists working on games have said it matters, not gamers.

    Rendering to a texture doesn't qualify for pixel perfect either. Any rotation, scale and float inaccuracy will still ruin it. You still need to clamp quad positions to integer bounds to start. Rendering to a texture does not mean that a quad drawn to the texture can't be halfway between pixels.
     
    Last edited: Nov 2, 2013
  24. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Not really an obsession. I was just trying to explain my thoughts. Pixel perfectness at the time seemed like a nice thing to have and in quite a few respects it would still be like for example the rotation of a fired arrow.
     
  25. saddam751

    saddam751

    Joined:
    Nov 6, 2013
    Posts:
    41
    attach to main camera and u are done


    function Update () {

    if (!Input.GetMouseButton (0))
    return;

    var hit : RaycastHit;
    if (!Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit))
    return;

    var renderer : Renderer = hit.collider.renderer;
    var meshCollider = hit.collider as MeshCollider;
    if (renderer == null || renderer.sharedMaterial == null ||
    renderer.sharedMaterial.mainTexture == null || meshCollider == null)
    return;

    var sum=70*30;

    var colors = new Color[sum];
    for (var i = 0; i < sum; i++)

    {

    colors = Color.black;

    }


    var tex : Texture2D = renderer.material.mainTexture;
    var pixelUV = hit.textureCoord2;
    pixelUV.x *= tex.width;
    pixelUV.y *= tex.height;

    tex.SetPixels(pixelUV.x, pixelUV.y, 70, 30 , colors);

    tex.Apply();
    }