Search Unity

How to decrease alpha value of pixel the farther out you go?

Discussion in 'Shaders' started by MartinOrtiz, Dec 11, 2018.

  1. MartinOrtiz

    MartinOrtiz

    Joined:
    Apr 12, 2018
    Posts:
    122
    I thought this would be easy...

    This is a 3D volume of a 1 x 1 x 1 dimensions cube.


    This is the 3D Volume, regular view....it's not too transparent, so it's hard to see "inside" of it.


    This is a slice of the 3D Volume, slices are about .05 units thick
    It's a slice about mid way through the volume....so you see there are structures



    Here is my "alpha-sized" 3D volume. The result is not what I thought it would be.
    Plus there is a cube corners artifact going on
     
  2. MartinOrtiz

    MartinOrtiz

    Joined:
    Apr 12, 2018
    Posts:
    122
    Here is what I do in the ray-stepping function...at the end of the function...

    float lenRay = 1 - length(prev_ray_pos - .5);
    ray_col.a = lenRay;
    ray_col = clamp(ray_col, 0, 1);
    return ray_col;

    When I do this, the third picture is the result I get....
    What I reasoned was, that the farther out the ray vector is, the more transparent it should be, thus the "1 - length(prev_ray_pos - .5)

    So the larger the vector, the more transparent it should get....

    Well, the results show that this approach does not seem to work.

    I know, it's a hard question, maybe somebody might have an idea of the best approach to go...
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I suspect you're thinking about this the wrong way. Really you should be applying some kind of scale and / or curve to each sample's opacity. Basically find where the tex3D() call is and multiply the results by 0.5.
     
  4. MartinOrtiz

    MartinOrtiz

    Joined:
    Apr 12, 2018
    Posts:
    122
    will try, thx
     
  5. MartinOrtiz

    MartinOrtiz

    Joined:
    Apr 12, 2018
    Posts:
    122
    Better results, the best value is actually a very low one, .05