Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Filtering for modern pixel-art graphics

Discussion in 'General Graphics' started by JustCore, Jul 24, 2023.

  1. JustCore

    JustCore

    Joined:
    Jan 22, 2023
    Posts:
    4
    Hello! I'm trying to create a modern style pixel art game so that every sprite on the screen is drawn in pixel art, but can rotate without deformation, etc. So I imported a couple of sprites into unity, turned off bilinear interpolation, turned off compression, and set 32 pixels per unit. And after that, when I move the character, it becomes visible that some of its pixels become rectangles due to non-integer screen resolution.

    I searched some information it the internet and found 9DTony's smooth pixel-art shader (its quite famous) So, this shader uses Unity's buildin bilinear interpolation and adds a pixel-art friendly filter to the sprite. But it has several problems. First of all, i have to set bilinear interpolation for every sprite, so in the inspactor they looks blury. Also, this shader can produce artifacts sometimes and it can create gaps between tiles and some sprites that close to each other. So, that shader is not the solution.

    Now I'm searching for some way to filter my pixel-art graphics to get rid of rectangular pixels and also without using pixel perfect camera because it doesn't suit my wished game look. I'm using URP and I'm ready to start digging into custom renderers and other stuff, but in the internet there's a pretty small amount of information, so i would like to know, form what point should i start to get the desired result
     
  2. Deatonjc

    Deatonjc

    Joined:
    Apr 22, 2017
    Posts:
    25
    I know it might be something chatgpt might not exactly get being it doesn't have as much perspective as a human but just throwing it out there that AI could help you if as you say the internet has a small amount of information
     
  3. JustCore

    JustCore

    Joined:
    Jan 22, 2023
    Posts:
    4
    I already have tried to use chatgpt. It rather can't understand me properly, or can't explain what he means.

    Also i have a video that shows which kind of look i want to achieve:

    Ability to have smooth rotation with some filtering against rectangular pixels and ability to make some sprites pixel-perfect, to be clear

    So, from what point should I even begin to make something like this by myself? Author of the attached video hasn't any specific tutorial that shows how he made all of this renderer stuff
     
  4. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,719
    I think the video presents the idea pretty clearly: snap the camera to closest pixel coordinate, then offset the rendered image by the difference between the snapped and the un-snapped camera coords.

    The only muddy bit here is how to offset the rendered image, you can do that in a variety of ways in Unity. Simplest is probably to setup your camera to render into a RenderTexture, then slap the RenderTexture on a viewport-sized plane and offset the position of that plane.
     
  5. JustCore

    JustCore

    Joined:
    Jan 22, 2023
    Posts:
    4
    I messed around with RenderTextures and got pixel-perfect effect. Then a realized that rectangular-pixels issue just disappeared. I thought about filtering but now I see that there's no need in it because of clear pixel perfect Camera snapping. Now everything seems working! Thank you for your reply!
     
  6. JustCore

    JustCore

    Joined:
    Jan 22, 2023
    Posts:
    4
    One more question. I had two cameras. One renders the game on a downscaled RenderTexture and the other captures that RenderTexture which is rendered in front of it as a rawImage. Now i find this solusion too bad because i cant use mouse events and i just tired to see another camera on every scene.
    So, I tried to use ScriptableRendererPass to take a RenderTexture from my mine camera, downscale it and then return it to the screen so now my game will be pixelated, but i faced quite many issues because of my poor SRP understanding. So, i'd like to know how to display my renderTexture on the screen without additional camera. Theres too few information in the internet about Unity's SRP so any help welcome!