Search Unity

Mip Maps Preserve Coverage equivalent for 3D textures? (textures fading alpha with distance)

Discussion in 'General Graphics' started by forteller, Aug 21, 2019.

  1. forteller

    forteller

    Joined:
    Jun 15, 2019
    Posts:
    55
    I have some materials which use 3D textures and have alpha transparency and the renders seem to fade out to nothing as they get further away from the camera. I heard that as mip map levels become lower for some reason the net alpha values tend to decrease (I don't understand why but it's explained here: https://docs.unity3d.com/ScriptReference/TextureImporterSettings-mipMapsPreserveCoverage.html) and usually enabling the "mipMapsPreserveCoverage" toggle of a texture2D would resolve this issue but unfortunately Unity's 3D textures have no such fancy options.

    Is there anyway I could reduce this fading with distance effect on a 3D texture? In other words, are there any "mipMapsPreserveCoverage" equivalent for 3D textures?

    Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Preserve coverage is specifically for alpha tested transparency, not alpha blending. Naive box mipmapping, like that done automatically by the GPU when you call Apply(), should be perfectly accurate for traditional alpha blending. However if you're doing any manipulation to the alpha values, like subtracting from them, you'll have similar issues as alpha testing.

    For a 3D texture you'd have to implement the alpha coverage preservation yourself. The technique Unity uses is described here:
    http://the-witness.net/news/2010/09/computing-alpha-mipmaps/

    I also proposed a hacky alternative here (look for preserve coverage):
    https://medium.com/@bgolus/anti-aliased-alpha-test-the-esoteric-alpha-to-coverage-8b177335ae4f

    Basically calculate the mip level, or get it using CalculateLevelOfDetail if you're using DX11 style hlsl notation, and scale the alpha by some factor.
     
  3. forteller

    forteller

    Joined:
    Jun 15, 2019
    Posts:
    55
    Thanks for clearing up my misconceptions as to the cause of my problem, I am indeed manipulating alpha values in my Shader.
    Also the links you sent me are exactly what I need!
    :)