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

Making Voxel Terrain Textures Look Better

Discussion in 'Editor & General Support' started by JasonBricco, Sep 22, 2014.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Hi all!

    I posted a question about this on Unity Answers some time ago, and haven't really received any information I could use. I figured I'd try here.

    I'm making a voxel engine and currently I'm just using filler textures provided by others, which will work until I can get some legitimate art later on. The problems I'm having relate possibly to aliasing (as I was told in my Unity answers post), or possibly to something else entirely. Here's a picture to show what I mean:

    VoxelPic1.jpg

    This happens all over. As I move the camera I see these wavy patterns and lines are moving all over the place. And as I said in the picture, the edges tend to get quite pixelated.

    In short, it doesn't look how I want it to. I want smooth looking textures without pixelation and all these lines and patterns.

    What can I do? If it does relate to aliasing, I'm not sure how to fix that. I tried Unity's Antialiasing image effect and it didn't do anything. I imagine the solution is more complicated than that.

    I was given advice to turn on "HW Multi Sampling", and I'll be honest when I say I don't have a clue what that is nor how to turn it on. I'm fairly new to this stuff.

    I've also messed with anisotropic filtering, but changes I made usually resulted in odd coloration for distance blocks that certainly wasn't right.

    So any help is greatly appreciated!

    Edit: So I've figured out I can turn multi-sampling on from quality settings, and using 2x, 4x or even 8x doesn't seem to help at all. Doesn't do a thing.
     
    Last edited: Sep 23, 2014
  2. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
  3. e_Glyde

    e_Glyde

    Joined:
    Apr 20, 2013
    Posts:
    42
    What type of filtering are you using for your textures?
    And may I have a close up on the textures?
     
  4. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    This is classic texture aliasing. Enabling high quality anisotropic filtering on those textures will help some. However, you have a fundamental sampling issue that the hardware can't just magically fix for you. If you really want solutions like this to work well, you need to use some sort of multi-resolution approach. One way to do that is to hand edit the mip-maps of the texture. The other is a custom shader that blends between different textures and tiling rates at different distances. None of these are 5 second fixes so expect to spend some time working at it.
    You may also want to check out some classic computer graphics books as they go into this kind of aliasing in detail.
     
  5. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    PS - if you really want to understand this issue, read up on discrete sampling of continuous functions at different frequencies, especially Nyquist's theorem.
     
  6. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I don't even know how I ended up with problems like this. Is this something all game developers face and just know how to deal with?

    Feels like I've read very little about it in posts, etc.

    Yeah, I'm interested in learning about it if it will help me come to a solution for it. And I really want the simplest solution I can find, while still maintaining performance.

    (As you may be able to tell, I'm just entering this industry - I have much to learn!)
     
  7. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    It's a common problem, yes. It's probably especially bad in your case because the source texture is probably kind of pixel art looking which makes filtering harder. Still, you can see a problem in many commercial games, often if you look at something like a chain link fence from a distance.

    The main problem is that your screen can only display one color per pixel. Your texture also has only one color per pixel (we'll call these texture pixels texels). When you are up close, you have many pixels per texel so you see the texture clearly. When you are far from the object, you have many texels per pixel. It's hard for the GPU to choose the best color for the pixel, and sometimes small changes in camera position make large changes to the color of a given pixel. You also get those funny patters (called moire) where the sampling rate of the texture and the screen intersect in funny ways.
     
  8. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Are mip maps what are usually used to fix this problem? I really think you're right when you say there's no simple fix for this, so I'll definitely have to take some time to figure it out. I'm just not sure which approach I should aim for.

    When I try mip maps I end up with odd coloration (which may be due to the fact that my texture is many different tile textures in 1, like an atlas).

    VoxelPic23.jpg
     
  9. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The problem with the atlas is that the mip maps are just lured versions of the textures, and that means the whole atlas and not the single tile you are using of it.
     
  10. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    That's what I figured... so the question becomes: how would I get block-specific mip maps? This seems quite complicated!
     
  11. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    If you use an atlas, you can use mip maps just fine. The only requirement is that you have to have space between each of the textures in the atlas. The amount of space depends on the resolution of the texture, but it's basically 2 pixels per mip map, and most engines make mip maps down to 32x32. As an example, you'd need 12 pixels of gap for a 1024x1024 texture (mips at 512x512, 256x256, 128x128, 64x64, 32x32).