Search Unity

Question Strange noise when sample texture3D

Discussion in 'Shaders' started by Bordeaux_Fox, May 21, 2022.

  1. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Hi,

    I'm trying to sample a 3d texture on a simple cube. However, I get really strange noise artefacts when the filter mode is set to Point. When I set this to bilinear or trilinear, this is not the case. However I want to see the sharp pixel not a blurred result.
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The interpolated values the fragment shaders receive are going to have a small amount of noise for any value not 0.0 on all vertices. This is just the nature of interpolating floating point values. This means if a value is 1.0 on all vertices, the value the fragment gets will be slightly less than 1.0, slightly more than 1.0, and sometimes 1.0. And for your case if the y is slightly above 1.0 it’ll go to the texel above the one you want.
     
    Bordeaux_Fox likes this.
  3. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Thanks. So there is no way to get the 3d texture sampled correctly on all sides in the fragment? Or how can I get rid off the noise?
     
    Last edited: May 23, 2022
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The "best" option is probably to inset the sample position slightly. Like subtract the surface normal * 0.001 from the position.
     
    Bordeaux_Fox likes this.