Search Unity

Properly 2-color textures?

Discussion in 'Formats & External Tools' started by allworknoplay, Sep 15, 2021.

  1. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    This might sound like a shader graph question, but it isn't -- it's about making proper (simple) textures and/or import settings in unity. Thanks for bearing with me :)

    A few images here show my issue: https://imgur.com/a/z3UbR6d

    I'm trying to use shader graph to make some nice vegetation, and (at least for development), I wanted to do all the coloring with the shaders, rather than with textures -- using textures just for the cutout shapes, and then applying the colors via shader properties. So as you might expect, I'm taking the alpha channel of the image and multiplying it by my shader's color properties, as well as using it for the material's alpha clipping.

    The problem is, everything has a tiny outline around it. You can see this in the first image in the gallery, where the grass and other plant textures all have that faint outline. I was pretty sure this was due to the alpha in my image not being exactly zero or one, so I tested the theory by checking the value and forcing either a zero or a one in my shader (second image), and that solved the problem (third image).

    Sure I might want the line in some instances, and I *can* solve it with the shader, but I think I should probably just make the textures correctly, or figure out the right import settings, if that's the problem.

    The sample grass texture is the last image, if you're curious. It's made in photoshop by using a 100% opacity brush and a color overlay for the white, so I just can't figure out how not to have translucency. I'm sure this is a standard thing, but I haven't been able to google the right thing. Should I be using an image with different channels, or is there a setting in unity or photoshop I can't find?

    Thanks in advance! Please pardon the look, I'm just getting into a visual overhaul!
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    If you don't want an outline than why are multiplying the color by the alpha?

    Edit: Oh, I think it must be to get different values of green on different grass clumps? You'll always get these outlines due to filtering. Your texture will be slightly blurred, so if your clump's alpha is 0.7 and your background is 0.0, then all around the edge you're going to get something in-between. The solution that you already identified is to use a different color channel for your value.

    Edit: Although, I think the outlines actually look good. They make the edges stand-out.
     
    Last edited: Sep 15, 2021
  3. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    Thanks for responding.

    I'm using the alpha because it *ought* to be either zero or one, based on what I can see from my image -- then I can apply whatever color I want without worrying about the other color channels (though in this case they're all also 1). I don't have to do this, I actually did it at first because it was simply easier to see the textures I was making when working in a different color than white, and later changed the textures to white with an overlay in PS, just to see if that worked better (it didn't).

    My alpha is never 0.7 -- or never supposed to be -- my intent is to have either 1 (the white parts of the texture) or 0 (the transparent parts). an alpha of 0.7 would of course give me a different, darker color, and that's what I'm trying to avoid.

    I also think the outlines look good in some cases, but not others, and yeah I can control them and already showed how -- just trying to do this properly, performantly, and understand what's going on ¯\(°_o)/¯
     
  4. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    Sorry if it wasn't clear before -- basically, I showed with my current fix (the conditional check I did in shader graph) that there's blurring happening around the edge of my image somewhere (when my intent is to create a texture that has either zero or 1 in the alpha channel), and I can't figure out if I'm missing something either in photoshop or unity, with regard to maybe import settings, scaling/interpolation, anti-aliasing, etc. The current image in question is the last one in the imgur link I included above.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
  6. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    Interesting! It might be, I'll have to do some testing, thank you for the pointer!
    I'm not sure I'm totally convinced yet, because I'm not sure why my fix in shader graph would have worked if it was this, but I don't fully have my head wrapped around it yet either.

    Thanks!

    Updated: Don't think so -- anti-aliasing changes/removal don't appear to have much of an impact aside from what you'd expect with a thin line.

    Updated Again:
    Actually, I didn't read far enough to full understand the article before, and I think you might be right! Needs more exploring.

    Separate:
    I did find that since the only color in my current textures is white, using a different channel (e.g. red) also solves the problem -- the color channels are all values of 1, even if the alpha channel isn't for some reason I can't tell. Note that just multiplying the whole color value doesn't work, since that includes the alpha channel, but picking just one does. Or, probably, splitting them up and picking just the colored ones, which I might do so that not every texture I use the shader with has to be totally white.
     
    Last edited: Sep 15, 2021
  7. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    I think @mgear's answer is definitely correct -- the "Mip Maps Preserve Coverage" checkbox doesn't appear to help in my use case, but notably, turning mip maps off has a big impact.

    I think I'll probably use my solution of just taking the other three color channels -- running a check in the shader may also be fine -- but it doesn't seem like there's a better easy solution to this particular problem without doing even more work.

    Thanks for the help!