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

Grass artifacts

Discussion in 'Editor & General Support' started by Vert, Jul 8, 2010.

  1. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    I am getting these artifacts from the grass and weeds in Unity and the Terrain Assets. Does anyone know how to get rid of them or why they are there?

    I modified the texture to make it look toonish which is why it looks different. Nothing more than a few filters on the layer in Photoshop. The Alpha layer went untouched. The artifact is at the top of the textured plane, but the alpha shows that it should be transparent.
     

    Attached Files:

  2. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    I get them too :(
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    This has been brought up many times. Do a search.
     
  4. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    From what I gather here:
    http://forum.unity3d.com/viewtopic.php?t=8779

    Its either a psd error or its something from the texture map that brokenpoly mentioned. I will try to change the native file type tomorrow when I have time to play in Unity again. Hopefully a file type change will fix it.
     
  5. solid

    solid

    Joined:
    Jan 15, 2010
    Posts:
    132
    Try to change your texture setting "Wrap Mode" to Clamp.

    when you have transparent textures, the "repeat" wrap mode often cause artifacts to the corners. else it could be a texture compression artifact.
     
  6. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    Ok, here is something strange. I changed the texture size from Max Size of 1024 to 256(the actual texture size) and the line went away. I bumped it back up to 1024 to see if the line would come back and it did not. I am very confused. I saved as a tiff and line still stayed. Also changing wrap mode to clamp. Only when I changed texture size did it go away but changing back to the original size did not create the problem again. :? So it seems its at least temporarily fixed.

    I would like to note that the lines appear only when I add a detail mesh and change its rendering mode from grass to vertex. Then changing the mesh back to grass does not get rid of the lines. I had a whole field of grass get lines above it previously when I added a detail mesh(rock mesh from the terrain assets pack). Deleting the detail mesh got rid of the lines in the grass too. :? Just some more info on how I have worked with this problem before.
     
    luuktito likes this.
  7. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    On a somewhat off topic, where did you get your grass from? Is that a in the standard or terrain assets and I just missed it? I am in need of more "prairie-looking" grass.
     
  8. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    I modified the textures from the standard grass in Unity and the Terrain Assets pack. The golden "grass" in the image is actually the "weed" texture but I changed the color balance to make it yellow instead of green. :)

    Edit: Here is an image of my modified default grass texture. Played with the healthy and dry colors and grass tinting. This is the result. The default grass can look rather good. Mine is more toony though, ran it through some cutout and pallet knife filters in Photoshop. I also don't billboard the grass as I think that takes out much needed depth.
     

    Attached Files:

  9. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    436
    this is an old problem from an art perspective.

    this is one problem and one problem only:

    the upper extents of your uv unwrap are RIGHT at the top of the texture. the shader will attempt to repeat the texture, and what you're seeing there is the VERY BOTTOM of the grass texture repeating up to the top of the plane.

    frankly, clamp might (shoud?) have fixed it, but if you want to be certain, the best way is to simply edit the uvs of the plane that you're using in a 3d program, and pull down the top uv-verts so that they are away from the top of the texture. if you have a 3d program you can play with this manually and see what i'm talking about.

    btw, i certainly HOPE that you are using a 3d program, and these textures aren't projected onto unity plane objects.. which have an insanely high polygon density....
     
  10. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    The grass is just a plain PSD with RGB layers and an alpha layer. I am using the default terrain->add grass. So I am unsure of how to change the UV wrap as there is none, its just the terrain grass with uses two triangles to create a plane to project the grass onto. Also, its the grass textures that come with the standard assets and terrain assets with only modifications to the RGB layers, not the alpha. So I am assuming that there textures were tested by the Unity team before release.

    I think I was able to solve it. Unity defaulted to my larger texture import size of 1024 and the grass textures were 256x256. Once I changed the size the lines have disappeared and haven't come back yet. Perhaps the lines are artifacts from up-scaling the image? Either way it seems that is the issue as changing to clamp from repeat and playing with having mipmaps and all other various settings didn't change a thing. Once I changed to 256 it went away but then I changed it back to 1024 and it didn't come back yet.

    I am rather confused. The lines only first showed up when I added detail meshes and changed their rendering from grass to vertex lighting. Deleting the mesh usually makes the lines go away, but I need detail meshes in my scene. It seems for now, changing the max texture size is the solution.
     
  11. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    436
    yeah, the reason that upping the size of the texture is fixing the problem is that there's more space for the geometry to sample from, so it's less likely to bleed over to the bottom again. you could also make sure that you turn off mip-mapping on your texture import settings for the grass. that might very well solve the problem as well

    it's your project, but using a 1024 image for grass is pretty much totally unacceptable, as it's a gargantuan waste of resources.

    if you can't edit the geometry, you could try adding some transparency to the bottom of the texture... so on the texture, the grass starts just an inch off the bottom.

    there is some crazy chance that this is something else, but I've seriously run into the problem about 50 times in my career.
     
  12. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    I think you misread me. I have 256x256 grass textures and upsizing was causing the problem it seems. Which seems rather strange.
     
  13. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    MakerOfGames, where is the option to not billboard the grass? I think your image looks great. Also, did you just match the tinting to the terrain texture that you were using?
     
  14. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    Thanks!
    The option to not billboard the grass is under edit grass->scroll to the bottom of the small grass properties window and uncheck Billboard. Billboarding grass also takes some resources so by turning off bilboarding you will increase FPS by a few frames(at least on my system it did). And yes I tried my best to match healthy and dry colors of the grass to match it with my grass texture on the terrain.
     
  15. Deicoon

    Deicoon

    Joined:
    Sep 25, 2010
    Posts:
    1
    All the maps for grass and detail objects are compiled into one map. If you have detail textures without alphas or with all white alphas they'll bleed into your grass textures! If you don't need alphas in your detail textures just go into Photoshop and add a channel in the channels panel and make sure it's black.
    Turn on all of your channels including the alpha.
    Your texture should have a red tint to it but don't worry it wont look like that in Unity.
    Save it as a 32 bit alpha and make sure when you bring it into Unity it interprets it with an alpha.
    Replace the old texture with the new one in your detail mesh.
    Once all your detail meshes have alpha, edit one of your detail meshes or grass textures and it should update.
    Now the lines in the grass textures should be gone!
     
  16. moctezumagames

    moctezumagames

    Joined:
    Jun 9, 2009
    Posts:
    395
    Hello.
    I am getting this artifact in the grass, at certain distance from the viewer, and angle. White pixels around the alpha channel.
    It's not an alpha problem because:

    1. I am using TGA (no PSD or PNG alpha problem)
    2. The tga background is green (no white pixels)
    3. It's just with grass under realtime shadows at certain distance and a bit random.

    I tried turning off mipmaps, changing texture size, even the filtering mode. Nothing solves the problem.

     
  17. moctezumagames

    moctezumagames

    Joined:
    Jun 9, 2009
    Posts:
    395
    I discovered this only hapens emulating Shader Model 3. With Shader Model 2 that doesn't happens...
    I will update my drivers just in case.
     
  18. BjoUnity3d

    BjoUnity3d

    Joined:
    Jul 24, 2012
    Posts:
    59
    Deicoon is correct. This is not clamping or mip maps. It's an artifact from Unity putting all the detail textures into one map internally. You have to imagine all the detail textures layed out in the same images packed as close together as possible. Whether you have an issue will just depend on how Unity decides to lay things out. The poster who changed the max size of the grass texture caused Unity to change the layout and the grass texture was no longer bordering a non-alpha texture. I solved it by removing the Rock mesh from my list of detail objects. Now I only have textures with alpha maps in my detail object list and the artifacts are gone. If I want to add the rock I guess I'll have to make a texture for it with a border having alpha 0.
     
    Oskni likes this.
  19. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Maybe it could be added to the documentation? Forums are a poor substitute for that...
     
  20. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
    Cyberben3d is right. The artifacts disappears only if change detail objects (ie rocks) texture.
     
  21. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    the artifacts do not dissapear with any of the solutions given in any thread on this forum about this issue.
    i tried everything they said in every thread, the issue persists, it is a grasssprite/shader bug that needs to be resolved.

    personally i think it's quite bad that this issue can persist for years in a gameengine and people just say either set the texture to clamp or the texture atlas sometimes does this and try to make a black border on the alpha, i tried with all black alpha's, so you won't see any grass at all, but i still have these lines, nothing said here and in other threads works, with all black alpha's one should not be seeing anything at all, so i don't know what's wrong here.

    i literally searched for 4 days, 8 hours a day to try to find a solution.
    i read all threads, it simply is a BUG.

    after reading all the threads about this issue i have come to the conclusion that probably the
    programming or programming in the shader that is responsible for creating the sprite grass atlas sometimes overlaps different (unused/nonreferenced) textures, so that is a case of a faulty programming routine, if your code is sound this CANNOT happen, 1+1=2, it is simply a bad piece of coding, no more, no less.
     
    Last edited: May 29, 2014
  22. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    After yet another entire day of trying things out i found a real solution to this problem.

    1. The folder that holds your grasstextures should be free of any texture without alpha layer.

    2. all the textures in the folder need to have a big black border (6px for 256px textures,12px for 512px, 24px for 1024, 48px for 2048px) all the way around.
    if there is 1 texture in your grass textures folder that does not comply to these rules the line could reappear.
    i'm not sure why a texture that is not refered to sometimes does this, but it happened with me and almost
    drove me crazy.

    so the routine that makes the atlas (probably the shader) indeed has a placement calculation error in it.

    it doesn't matter if your textures are set to repeat or clamp, you will have lines either way if you do not comply to these two rules.
     
    andreiagmu and turboscalpeur like this.
  23. Brainbite

    Brainbite

    Joined:
    Jul 9, 2014
    Posts:
    1
    I had the same transparency problems using terrain with detail meshes and grass textures.

    My fix:

    1. All textures should be in TIF-Format.

    1. The alpha channel of the grasses needs a 1 pixel border. So this border will always be transparent

    2. Every texture needs an alpha-channel. INCLUDING the texture of the detail meshes!!!
    So save the textures of the detail meshes in TIF with an alpha channel purely black.

    3. Remember to use "Vertex Shading" on the detail meshes in their terrain option, or they will be invisible because of the alpha channel.



    To the Unity-Team. Fix this bug please. I can handle it now, but its totally confusing to people new in Unity.
     
  24. KevinTriton_

    KevinTriton_

    Joined:
    Jul 7, 2012
    Posts:
    18
    I have found a solution to this problem The issue is, whichever grass texture has a line above it, it is being caused by the next and/or previous texture in the details list of your terrain: http://puu.sh/b4O1P/5013da3e84.jpg

    What you need to do is go into every grass texture that is in the Details list under terrain, and make sure there are only transparent pixels on the bottom couple of lines, about 3 or so pixels.

    Also, make sure you have clamping on under wrap mode in import settings
     
  25. george_00

    george_00

    Joined:
    Oct 23, 2015
    Posts:
    19
    Thank you for this - I have also been having a lot of frustration with this! Got a bit sick of the "do a search" solutions that didn't make any difference and wasted a lot of my time. Changing the size of the textures helped in some cases, but I agree - the artifacts seem to be an outcome of the combinations of textures in the list.
     
  26. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    This artifact is the result of texture atlas pixel bleeding (example).

    Say, you have 4 grass textures. Unity's terrain engine automatically packs them into one texture atlas that contains these 4 grass subtextures. At any mip level greater than zero the edge pixels of the subtextures will bleed into the adjacent subtextures.

    Solution: make sure that all your grass textures have fully transparent borders a couple of pixels wide.
     
  27. karelium

    karelium

    Joined:
    Oct 11, 2014
    Posts:
    5
    That IS the real cause and workaround for it !!! 5 stars for you!
     
    implosiondevelopment likes this.
  28. pixeldoll

    pixeldoll

    Joined:
    Jan 2, 2018
    Posts:
    1
    8 years later... ran into the same grass texture problem. Found answer here. Thank you. :)
     
    Last edited: Feb 28, 2018
  29. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    68
    Got the same "border artifacts" for grass billboards.
    Solved by
    1. manually erasing all grass texture borders to clear alpha. Artifact on one of the grass billboard was caused by artifact in another grass texture (described in one of the comments above)
    2. made all grass textures square (had one 512x256)
     
    Last edited: Oct 19, 2020