Search Unity

Resolved Power Node Preview is half pink

Discussion in 'Shader Graph' started by RBogdy, Sep 7, 2019.

  1. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Hi,

    The Power Node preview in ShaderGraph shows half pink.

    Tried in 2019.2.4f1 and 2019.3.0b2 and both are the same (LWRP or URP 6.9.1 or 7.0.1)

    Capture.JPG

    This is a simple unlit shader from a tutorial.

    I already opened a case like 2 weeks ago (Case 1179476) [ShaderGraph] Power Node is half pink, however no response there so far
     
  2. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Am I the only one with this problem or am I doing something wrong? Can't seem to get an answer anywhere...
     
  3. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    That pink shader is the error shader that renders when you are creating NaN (Not a number) errors. Looks like you're trying to do power of a negative number because position goes from -1 to 1. Trying removing the negative numbers first.
     
    RBogdy likes this.
  4. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    If you don't mind explaining to a novice ... how would you go about removing the negatives first? I tried using Negate nodes but now the other half is pink ... still looking though :)

    EDIT: I used Absolute node ... is that the correct one?
     
    Last edited: Sep 9, 2019
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Absolute or Clamp are both solutions depending on the result you want.
     
    RBogdy likes this.
  6. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Thank you all for your answers. Both Absolute and Clamp are doing what I wanted before the Power Node
     
  7. icamonu

    icamonu

    Joined:
    May 14, 2017
    Posts:
    2
    Preview in shader graph editor cannot render the powers of negative values but it works properly in the scene and the game. Mathematically speaking, there is no reason to get an error while multiplying a negative value with itself. Furthermore, when we use a multiplication node to multiply a negative value with itself, it works in the shader graph editor and the scene, properly.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    For graphics APIs the function pow(x,y) is implement as:
    val = exp(y * log(x));

    The log function is the natural logarithm or base-e logarithm of that number. The log of a negative number is an imaginary number, which GPUs don't support, so it returns a NaN (Not a Number).

    Any value * NaN = NaN.
    Almost any hlsl function given a NaN = NaN.
    So the result is a power of a negative number is always a NaN.

    In Shader Graph this shows as pink, presumably because someone was smart and decided to add a post process to shader graph and show NaN pixels as pink rather than black, which is what you'll see in a non HDR camera, or potential one with no post processing.

    But there is one oddity, which is pow(x, 2), if the 2 is hardcoded in the shader and not a property, usually gets compiled as x * x rather than using the pow function. That suggests the Shader Graph previews are being generated with a "disable shader optimizations" flag.
     
  9. icamonu

    icamonu

    Joined:
    May 14, 2017
    Posts:
    2
    Ah, I understand now. Thank you very much.