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. Dismiss Notice

Question Why my power node returns pink?

Discussion in 'Shader Graph' started by Chahorain, Aug 15, 2023.

  1. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    I am trying to create a heart shape function inside shadergraph. My initial point is to give -0.5 offset to uv so I can recenter it on the middle of the screen. When I tried to give UV.XorY power of 2, half of my output turned pink.

    I know that part of uv should be below 0, but why is it pink? Is there another way around to make it return correct output?

    Thanks for the help!
    Screenshot 2023-08-15 120107.png
     
  2. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    Plz.. any help
     
  3. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    For numbers with negative values, raising to a power is not a valid operation, so the pink indicates that those pixels have NaN values (not a number). You can fix it by inserting an Absolute node or Saturate node in between the Split and the Power node (depending on the results you want).
     
  4. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    So numbers below 0 in shadergraph UV node will be considered as a NaN? Is there other nodes have same limitations?
     
  5. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    No, this is specific to raising numbers to power - so only the Power node has this limitation.
     
  6. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    Screenshot 2023-08-16 233945.png
    I want to draw a shape like this, how can I do that?
     
  7. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    nvm I made it, thanks for the help! And good to know there is a limitation of power node!
     
  8. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    So now I am a little bit confused... After I split the output of Tiling and Offset node, and take R and G channel to do add/multiply/subtraction, I have a final outcome as below.
    Screenshot 2023-08-18 000658.png So in the previous nodes I have been doing a lot of calculations using U and V number, what does the heart image stands for? Does it stand for a final adjusted UV and assigned with a full white color?
     
  9. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    Nice work! Sorry, I don't understand your question. Looks like you succeeded in making a heart shape. That was your goal, right?
     
  10. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    Yes, sorry for the misunderstanding. I figure myself out.

    I have a further question, how can I made a feather effect on its edge? Currently the edge is too sharp
     
  11. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    Now I have a smaller shape and made a subtract to get the feather area I want. But I don't know what is next step to make it look like a feather edge
     
  12. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    Screenshot 2023-08-18 014902.png
     
  13. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    I guess you would need to construct function that fades on the edge - some kind of SDF. Obviously you can always render it (to render texture) and put antialias there, but I don't think this acceptable way.

    In any case I think you should start new thread as it went from pink power node to heart shape, and now it goes towards antialias or SDF :D
     
  14. Chahorain

    Chahorain

    Joined:
    Dec 20, 2017
    Posts:
    25
    SDF is a new area for me, I ll do some research and see if I need a new thread to discuss this. Thank you!
     
  15. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    To be precise you already have some kind of distance function, the thing is it's not perfect.
    upload_2023-8-18_12-45-43.png
    If you check procedural nodes in shader graph you will see they don't use any branching because it produces zero-one result, and aliasing, plus branching is not cheapest in this case.

    Anyway if you did the same as other procedural nodes, in your case you would end up with artifacts on sides and bottom:
    upload_2023-8-18_12-40-9.png
    It might be acceptable as it's not as noticable if it's big on the screen, but they are definitely there.
    I am not the math guy, but I doubt it will be easy to create proper function without artifacts, or rather it's way more simple to simply create the SDF texture and you would be able to get very nice shapes and you can even control size of them to some degree.
    You can check text mesh pro implementation, it uses SDF for letters.