Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

sampler3D color correction produces odd outline

Discussion in 'Shaders' started by kiraki, Nov 5, 2019.

  1. kiraki

    kiraki

    Joined:
    Aug 25, 2014
    Posts:
    2
    I've been playing around with 3D textures to produce color effects, but the edges of 2D textures with a 3D texture pass produce odd extra coloring artifacts, especially when not horizontal or vertical. Attached I have an image of two shaders with the same texture, the first one the default texture unlit and the second the same texture sampled through the identity 3D texture.
    unlitAnd3DPass.png
    This seems to be also the case with the PostProcessing 3D LUT, ShaderGraph, and on a second tested computer. shaderGraph.png

    Does anyone know how to fix this?
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,265
    Nothing wrong with the shader. But you need to disable the mipmaps on your 3D texture.

    GPUs determine the appropriate mipmap to use when sampling a texture by how much its UVs change within each 2x2 pixel group. At the edge of a color change, the color value from the original texture is changing significantly, thus the “UVs” for the 3D texture are changing significantly, and it’s dropping to a lower mip map. Since you’re going from white (1,1,1) to a solid color or black (0,0,0), ands UVs use the largest change within the pixel quad to determine the mip map, you’re always sampling from the smallest mip. So basically a 1x1 middle grey.
     
    kiraki likes this.
  3. kiraki

    kiraki

    Joined:
    Aug 25, 2014
    Posts:
    2
    That worked! Just had to change that boolean in the constructor. Thanks for your help and for all your other posts helping other people (that also later helped me)