Search Unity

Resolved [LWRP] Creating a simple gradient map shader

Discussion in 'Shader Graph' started by WendelinReich, May 20, 2019.

  1. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    Hi everyone,

    I'm trying to create a simple gradient map shader graph, basically a graphical version of the standard gradient map feature found in Photoshop. I've managed to create a working version but it creates artefacts (see below).

    The basic idea is very simple, explained here and here: take a BW texture, and use any of its r, g or b channels to define the u-coordinate of a gradient map texture, which allows us to look up the color.

    Here's an example BW texture that goes precisely from white to black:
    upload_2019-5-20_12-7-15.png

    And here's a 2x256 gradient lookup texture, going from blue to yellow (I'm showing the 4x512 version here so it's easier to see). Inside Unity, I set import settings to 'uncompressed' and 'no mipmaps' for both textures:
    upload_2019-5-20_12-8-42.png

    And here's my shader, which works but isn't precise:
    upload_2019-5-20_12-10-49.png

    As you can see on the preview sphere, close to the edges (where the UV coordinates of the sphere approach either 0 or 1) there are artefacts, and I have no idea where they come from or how to get rid of them. The outermost colors of the gradient texture are blue and yellow, yet in between the two there seem to be all sorts of colors. It's the same on other meshes. I've tried clamping the output from the BW-texture to 0...1 or even 0.01-.99, but that hasn't gotten rid of these artefacts.

    Any ideas what I'm doing wrong? I'll be happy to paste the final result here once it works...
     
    Last edited: May 20, 2019
    Vivien_Lynn likes this.
  2. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    Solved it - in the import settings of both textures, Wrap Mode must be set to 'Clamp'! And voilà, we have a working Gradient Map shader :D