Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NEW - Gradient Shader Pack - realtime animatable gradient shaders!

Discussion in 'Assets and Asset Store' started by imaginaryhuman, Jun 15, 2013.

  1. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You can do a circular gradient with a palette. You could do that on one object and then do a horizon on another in alphablend to combine them together, I guess. I don't really see how it will look like a galaxy though.
     
  2. PabloAM

    PabloAM

    Joined:
    Dec 25, 2012
    Posts:
    35
    Hello, I have finally bought your pack shaders.

    I am testing it and I have almost I want but I have some questions to finish it.

    I have added to my Main Camera a new skybox with the material with your Vertical Shader /SolidBlend.

    And looks as expected, but I would like by c# script to move it with the acceleration I´m pushing to my character.

    How could I access to "UV Scale" value from my C# scripts??

    Thanks!
     
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Same as any shader, look at 'SetFloat' command on the material. The shaders aren't particularly designed for 3D so I'm not sure how it will be have on a 'skybox' particularly as there is no cubemapping going on.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    When you click on the actual shader file itself, the inspector will list the variables that you can access with SetFloat.

    e.g. _UVScale
     
  5. PabloAM

    PabloAM

    Joined:
    Dec 25, 2012
    Posts:
    35
    Something like this??

    Code (CSharp):
    1.   Material skyMat;
    2.  
    3.     public void MoveY(float speed)
    4.     {
    5.         skyMat.SetFloat("_UVScale", speed);
    6.     }
    EDITED: Tested and works.

    Thanks!
     
    Last edited: Jan 8, 2017
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
  7. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hiya! I'm really sorry if this is obvious, I've read through all the forum posts, and I see that the shaders don't work for sprites, but I can't decipher whether they work in Unity GUI or not? I was hoping to use them as backgrounds for my panels.
     
  8. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi. I'm not sure. I haven't tried it myself. I can tell you this. For the shaders to generate gradients, they need to interpret the UV1 texture coordinates. Regardless of whether its a built-in unity object or a quad or a 2d polygon or a sprite or a UI element or original GUI element, it has to be supplying texture coordinates in the mesh data. It also generally is required that the texture coordinates are set up in a range of 0...1 across the geometry. Scaling doesn't affect it too much but if the text coords are weird then the gradient will be weird. When you e.g. add a quad or cube to the scene and put the shader on it, Unity automatically gives it UV's of 0..1 across the face of the square, which works perfectly and gives you the default output. But if the mesh data doesn't include that, e.g. with sprites, a sprite from a spritesheet doesn't have tex coords from 0..1 since it references a subset of the texture, so it might be 0.2 .. 0.34 or something, this won't produce the right gradient output. Some shaders might work in that you can set a SCALE and could potentially scale and offset the gradient to compensate for the wonky tex coords, but I can't say that's very reliable. Similarly with Unity GUI stuff, if they aren't supplying tex coords or they're not in a range that you can work with, it'll be difficult. Also to consider for sprites is they only typically set a UV1 texture coord for the sprite texture and don't set a UV2 so the shader wouldn't be able to use UV2 to generate a gradient on top of the sprite texture.

    Anyone found out if this works with Unity UI yet?
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I did a simple test with Unity UI images.

    If you create a UI canvas and add a UI 'image' to it, do not choose a texture for the image. But if you set the material to be a gradient shader material (the no-texture kind), it will show a gradient where the UI image would be. This is because the UI image apparently defaults to a 0..1 texture coordinate space when there is no sprite texture chosen.

    Once a sprite texture is added to the image, it is possible the texture coordinates of that sprite within its sprite sheet will not be 0..1 and would mess with the gradient. But also, once you choose a sprite texture for the UI Image, UV1 will then be consumed by the texture rendering. So if you then switch to a 'texture+gradient' shader, it will just render the sprite texture and not render any gradient. This is because those shaders need a UV2 channel in the geometry and it doesn't have it.

    One workaround then is to use two UI Images, one with a texture as normal, then on top/in front of it, add another image with a gradient-only shader on it, with alphablending, and then it will generate the gradient and combine it with the image below. But alphablend may or may not give you the output you want, compared to e.g. a multiply blend.

    So it sort of works with Unity UI images, you can at least generate a gradient by itself, but combining it with textures is problematic.
     
  10. Argiris

    Argiris

    Joined:
    Nov 14, 2014
    Posts:
    23
    Hello.

    Your plugin looks very interesting. Congratulations!

    We're using NGUI for our game and I'm wondering if it will work with it.

    Thanks!
     
  11. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi there. Actually I have no idea. I would expect some parts might some might not. The gradients are generated based on the texture coordinates in the geometry/mesh... usually a 0..1 range across the object is appropriate for normal gradients. e.g. when you add a Unity cube to the scene, the gradient works normally. If it's using texture coords for something else or if you want to use a textured version of shader, then either texcoord2 has to be supported or it won't work. You'd have to ask about what kind of geometry data NGUI creates for the objects.
     
  12. Argiris

    Argiris

    Joined:
    Nov 14, 2014
    Posts:
    23
    Thank you for your swift reply! :)
     
  13. akashif

    akashif

    Joined:
    Aug 25, 2016
    Posts:
    7
  14. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I would say, almost. The square thing is almost possible if you use a square gradient and offset it a bit. The circle is almost possible in that you could offset a circular gradient, but it looks like the image you showed is not just a pure circle inside another circle, it's adaptive to the distance from the edge, which is not possible.
     
  15. akashif

    akashif

    Joined:
    Aug 25, 2016
    Posts:
    7
    Hi
    Thank you for quick reply. Can you please be kind enough to create a sample of best possible matching my both requirements. Just pngs. Or some limited demo of your shaders where I can play and see how much I need to compromise if I use your shaders.

    Thank you
     
  16. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Sorry I have no time to do that. I suggest looking at the asset store page to see what it can do and what it looks like.
     
  17. haggai

    haggai

    Joined:
    Mar 24, 2017
    Posts:
    2
    Hey Imagnary, I have an urgent project and I think I can use it, but I have some questions:

    The effect I am trying to achieve is a "flashlight" like the animated transition to fake spotlight feature you mentioned.

    The target object is a square plan or a flat mesh. It is has to be transparent so when I move the "fake light" in front of it, it will show as light shining in a transparent surface. The light would be expected to be radial whiter at the center and fades out outward, or possibly a diamond.

    So the first question. Can I control the position of the center of the "light"? I'd need to interact with it so it can be driven by a gameObject in unity. 2nd question, can it be over transparenncy as I mentioned?
     
  18. haggai

    haggai

    Joined:
    Mar 24, 2017
    Posts:
    2
    Hey Imagnary, I have an urgent project and I think I can use it, but I have some questions:

    The effect I am trying to achieve is a "flashlight" like the animated transition to fake spotlight feature you mentioned.

    The target object is a square plan or a flat mesh. It is has to be transparent so when I move the "fake light" in front of it, it will show as light shining in a transparent surface. The light would be expected to be radial whiter at the center and fades out outward, or possibly a diamond.

    So the first question. Can I control the position of the center of the "light"? I'd need to interact with it so it can be driven by a gameObject in unity. 2nd question, can it be over transparenncy as I mentioned?
     
  19. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You can't do the transparency. Better off just using a transparent texture and drawing it over the surface?
     
    Last edited: Jun 5, 2017
  20. udubaso

    udubaso

    Joined:
    Dec 30, 2014
    Posts:
    16
  21. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yes, choose one of the vertical shaders and set the colors via the material inspector. You can also then access the color fields of the material via script and modify them as you desire. The shader will only output the actual gradient using the colors given, it won’t animate the colors. So you need to script the animation. I think you can also animate those with an animation curve?
     
  22. udubaso

    udubaso

    Joined:
    Dec 30, 2014
    Posts:
    16
    Thank you imaginaryhuman for your reply. Of course, the best way is to do the animation via the script. I am glad your asset supports that. I look forward to buying it.