Search Unity

In Shader Graph how to use custom gradient png instead of gradient nodes?

Discussion in 'Shaders' started by ozturk_brk, Jul 5, 2019.

  1. ozturk_brk

    ozturk_brk

    Joined:
    Jun 27, 2018
    Posts:
    10
    I am trying to create a flying flag using a vertex displacement shader. I did it with the simple gradient noise node. But I read somewhere these nodes are expensive to use. So I try to figure out how to use a custom grayscale gradient png instead. But I don't make it work until.

    My current work is below:
    shader.PNG

    If I use SimpleNoise output to offset the Y of the current position and feed PBR master, it works perfectly. But with the external gradient image, I could not get it done. What am I doing wrong?
     
  2. Mutimir

    Mutimir

    Joined:
    Dec 6, 2018
    Posts:
    36
    If you are using a grayscale image there is no need to add the rgb values and then divide them and clamping them. They are all the same value between 0 and 1. I will try to recreate your effect and see if i find what was happening.
     
  3. ozturk_brk

    ozturk_brk

    Joined:
    Jun 27, 2018
    Posts:
    10
    Yes, I know that. I tried without them also. It is just in case. Thank you. I am waiting for good news from you :)
     
  4. Mutimir

    Mutimir

    Joined:
    Dec 6, 2018
    Posts:
    36
  5. Mutimir

    Mutimir

    Joined:
    Dec 6, 2018
    Posts:
    36
    so here is how i have done it, i used object space, and i multiplyed the tiling uv with a small number then used fraction and combine the position with the object position and feed that into the pbr master node. You should reiterate on this if it isnt distorting in the right direction, also i added the distortion onto the y-object position you might want to feed it without that part. The thing that i found that might have been your problem is that the position uv-s did cover a small part of the texture so the flag was moving up and down as a whole thats why i addad all the above mentioned part.
     
    Last edited: Jul 5, 2019
  6. ozturk_brk

    ozturk_brk

    Joined:
    Jun 27, 2018
    Posts:
    10
    It works perfectly. I only add the Multiply and the Fraction nodes after tiling to my shader. Could you explain why you did this and how it differs?
     
  7. Mutimir

    Mutimir

    Joined:
    Dec 6, 2018
    Posts:
    36
    I edited my last post to explain it but i will do it again in more detail. The problem was that the uv-s that you feed to the sampler werent covering your whole texture. So the flag mostly got the same value for all of it vertices. The multiplier and the fraction part makes it so that you expand the values in the uv-s. Fraction is also useful if you want to tile your uv coordinates so than you multiply your uv-s with a large number instead of a small one.
     
  8. ozturk_brk

    ozturk_brk

    Joined:
    Jun 27, 2018
    Posts:
    10
    I got it. Thank you so much. You save my day.
     
  9. Mutimir

    Mutimir

    Joined:
    Dec 6, 2018
    Posts:
    36
    I dont have time to test it now but i think you can actually drop the fraction nod and it would still work. You might want to try that out.