Search Unity

Shader Forge - A visual, node-based shader editor

Discussion in 'Assets and Asset Store' started by Acegikmo, Jan 11, 2014.

  1. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this help?
    SF_ArthurClark01.jpg


    If you're going to do all of those Multiply & Adds, use a ChannelBlend (Summed) instead. Also, consider what your math looks like outside of the 0-1 UV range. For instance, if you're wanting each quadrant to repeat past the 0-1 range, you're going to have to do a lot more math than if you just want something like a checkerboard repeat. And if you're going outside of the 0-1 range anyway, you might just want to work with positive/negative Us/Vs. +u+v is one texture, +u-v is another, etc. I might be really misunderstanding what you're going for though.


    I went to answer this, but when I checked my assumptions, I was wrong. I'd suggest trying out each by just looking at the stats section in the compiled shader source and testing it out in a stress-test scene. Depending on the platform, Lerp (Mix for glsl) can yield fewer instruction counts than summed, but that doesn't mean it'll be faster. Oh, and using the channel blend with a layered setting is the same as using lerps.


    [EDIT::] Consolidated several posts into this one.
     
    ArthurClark likes this.
  2. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    i want to repeat same texture effect from 0-1 uv range outside uv range.
    the last node that it is connected to base color, i want it to repeat like how you expect what model will get when its vertices is outside uv.

    here is a simpler shader with multiply and add nodes.. as you can see everything repeats as expected from final node..
    testshader.png

    how i can solve this if its not a bug?
    my target only to apply multiple textures on different isolated parts of uv bounds.. and i want it to repeat. that is simply my intent from these shaders.
     
  3. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    So if you have the UV coords divided into the following textures:
    t1 t2
    t3 t4

    do you want the result to tile like this:
    t1 t1 t1 t2 t2 t2
    t1 t1 t1 t2 t2 t2
    t1 t1 t1 t2 t2 t2

    t3 t3 t3 t4 t4 t4
    t3 t3 t3 t4 t4 t4
    t3 t3 t3 t4 t4 t4
    or like this:
    t1 t2 t1 t2 t1 t2
    t3 t4 t3 t4 t3 t4
    t1 t2 t1 t2 t1 t2
    t3 t4 t3 t4 t3 t4
    t1 t2 t1 t2 t1 t2
    t3 t4 t3 t4 t3 t4

    Maybe I misunderstand what the problem is. If you look at your first example of the issue, it occurs at 1.5u. That makes me this it's a math issue...
     
  4. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    yep like the first one..
    t1 t1 t1 t2 t2 t2
    t1 t1 t1 t2 t2 t2
    t1 t1 t1 t2 t2 t2
    t3 t3 t3 t4 t4 t4
    t3 t3 t3 t4 t4 t4
    t3 t3 t3 t4 t4 t4
     
  5. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Thank you IFL really appreciate your advice and will look into profiling my shaders although I get a sense it could be marginal. Also I did not know about layer being same as lerp so thanks again.
     
  6. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this help?
    SF_mangax01.jpg [EDIT::] Note that the textures are going to be shrunken by half compared to the UV of 0-1, but I think it makes more sense if you're opposed to positive/negative UV splitting. If it's an issue, change the Remap from -1 - 1 to -0.5 - 0.5.

    Yeah....... It might not be worth it if your projects aren't aiming for AAA graphics on mobile. I guess I'd really just suggest having fun and making it simple so you don't waste time, which might lead to demotivation. If you ever want to know what a node in SF does, open the source (not compiled) and find it. I usually use a really simple shader to do it.
     
    Last edited: Jul 23, 2015
  7. abitofjohn

    abitofjohn

    Joined:
    Nov 6, 2012
    Posts:
    27
    Hello all!

    I'm looking to do create a shader that will do something based on a vector, so for example if I had a plane with a water shader and a stone collided with it i could create a ripple where the stone collided with the plane.

    If anyone could tell me what nodes to start experimenting with that would be appreciated, cheers!
     
  8. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336

    thanks alot for the help IFL! i tried your solution, it repeated fine on editor.
    i tried using it on android build, this what happened >>
    stillissue.jpg

    later on i used your append idea with channel blend and i used my old uv way.. without the remap. and it worked fine both on editor and build :)

    you know, it works fine now, but it feels like try and test until it works..
     
    Last edited: Jul 25, 2015
  9. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey guys. I am playing with a leaf shader again and am having an issue finding a way to get the tree to bend in world space. So if I have a 100 trees randomly rotated they will bend in the same direction. It would be amazing to be able to have a windzone node. So that windzones can control the direction.

    So basically what is the best way to get trees to bend in world space.
     
  10. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  11. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    Vladnes likes this.
  12. Ravart

    Ravart

    Joined:
    Mar 9, 2011
    Posts:
    42
    He everyone,
    is something like that native possible with ShaderForge (I know you change stencil options)?



    I hope to achieve an effect, where a "light" sphere makes objects visible, when they pass it.
    Cheers
     
  13. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    @Ravart currently its is not possible BUT you can manually edit it into the shader after you are done with it.
     
  14. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
  15. VisCircle

    VisCircle

    Joined:
    May 4, 2015
    Posts:
    43
    For a car paint shader I need to access the skybox manually beside the standard reflection. Is it possible to access the automatically assigned cubemap in Shader Forge, which has been set up in Unity 5 as Skybox?
    I want to reproduce a metallic effect for a car paint shader and have to duplicate the hdr cubemap for the flakes. I need to blur the skybox, multiply it with the flake color and add it to the car paint. My intention is to get an influence to the flakes by the light sources in an hdr environment instead of a "real" light only. It would be extremely time consuming to blur and assign the "metallic map" manually.
     
    IFL, jjason08 and Baldinoboy like this.
  16. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Texture has a top and bottom. I use this texture for the shader particles.
    Is it possible to make the texture is always aligned its bottom and up to the top and bottom of the world, despite the rotation of the particles?
     
  17. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    I wrote up an article on the wiki about procedural skyboxes, you can find it here.
    I linked it in the community creation since I don't really know where it would fit on the main page
    Here's what it looks like at night :

    On the particle system, change the renderer to vertical billboard.

    There's a cubemap node in SF, MIP level can fake the blurring but why dont you use the Metalic/specular and gloss/roughness output? plug in your flakes map and you are done.
     
  18. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    I have a different angle of rotation of the particles, it will not help
     
  19. elamhut

    elamhut

    Joined:
    Sep 13, 2013
    Posts:
    45
    Hey guys, I was wondering if there's a way to expose the U & V coordinates of a panner in the material editor so I don't need to go making different panning shader for different objects that I need scrolling textures (i can just set their scrolling direction right in the material) ss+(2015-07-28+at+07.40.45).jpg . I tried many things but nothing seems to quite work :(
     
  20. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    IFL likes this.
  21. elamhut

    elamhut

    Joined:
    Sep 13, 2013
    Posts:
    45
    Holy crap I feel dumb...

    I was trying something exactly like that but I was multiplying instead of adding... Also I feel even dumber for not finding this in the wiki before asking.

    Thanks a lot DMeville :D
     
    IFL and DMeville like this.
  22. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Was someone wanting a glitchy shader translated from shadertoy, or am I insane? I revived an old one that I was working on a couple months ago, but it's not finished...
    SF_GlitchyShaderWIP.gif
    (original image is from GameGuyz)
     
    Vladnes and Marco-Sperling like this.
  23. yaronme

    yaronme

    Joined:
    Mar 28, 2015
    Posts:
    2
    Hey guys !
    Been searching for hours, I'm trying to find a way to create an alpha clipped shader with soft edge, is this possible with Shader Forge? Thnx
     
    IFL likes this.
  24. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Clipping and soft edge blending in one sentence - does not compute.
    Do you have an example of what you want to achieve?
     
    IFL likes this.
  25. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    No it's not possible in SF, but you can combine two SF shader passes to do it, I think. I'm actually surprised that it's not already in SF. @Marco Sperling - the recent blacksmith hair shader from Unity is a good example. From what I can tell, it's a pass for clipping followed by a pass for alpha.
     
  26. yaronme

    yaronme

    Joined:
    Mar 28, 2015
    Posts:
    2
    Marco Sperling, I attached an example image of a shader i downloaded from somewhere (can't remember where), the top left rect is the source texture and the the main image shows it on a plane inside unity, the shader has an alpha cutoff parameter and it clearly creates a soft edge

    IFL, thnx, I'll search for a tutorial or some info about combining two passes, hope I can manage something :)
     

    Attached Files:

  27. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    This I wanted, but already deleted my post. I have achieved the same results as you have in the picture. While the focus on this. Shader was the link https://www.shadertoy.com/view/Md2GDw
     
    IFL likes this.
  28. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I'm not sure that what I see in your example actually involves any clipping/discarding of pixels. That cutoff parameter you speak of might be used for something entirely different in the context of that shader. Maybe some kind of signed distance field calculation to calculate the falloff from opaque to transparent. Is there an alpha channel in your source texture?
    If you've got uncompiled code to show we might get a little closer.
    @IFL Aahh, yes. 2-pass-shader... hair... proper sorting and self-shadowing. That's something on my wishlist further down the road of my shader adventures :D

    What browser are you using to view shadertoy? I tried Opera 12 and IE 11, both fail. IE seems to have trouble with texture2D calls. The default new shader displays correctly.
    Firefox at least shows the textures - not the videotexture as it seems.
     
    Last edited: Jul 29, 2015
    IFL likes this.
  29. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Update to the glitch shader I posted above.
    SF_GlitchyShaderWIP03.gif
    SF_GlitchyGraph.jpg

    @Acegikmo - is the node-preview method built on render textures or pixel math? It gets infuriatingly slow when the depth of a node stack has more than 30-35 previews. :(
     
  30. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I guess it is based on pixel math due to the fact that SF worked in Unity Free Versions before Unity 5 with its PE (free rendertextures) came out.
     
  31. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Shaderforge did use a trick to force rendertextures to work inside the editor , the same way unity use it for there own interface.
     
  32. Andy-Buchanan-222

    Andy-Buchanan-222

    Joined:
    Mar 12, 2014
    Posts:
    1
    I'm getting a difference in light falloff response for spots and point lights compared to the Standard Shader. Is there any way I can get them to respond the same?
     
  33. VisCircle

    VisCircle

    Joined:
    May 4, 2015
    Posts:
    43
    Thanks for your reply. I'm aware of the cubemap node of course but I actually want to use the automatically assigned cubemap related to the scene background in Unity 5, which is somehow written/assigned in the main node (well, I'm not a coder ^^). So changing the background should change "all" cubemaps on the car surface automatically, of course. Also using the mip maps for the reflection glossiness don't bring me the required blurriness.
    I already got flakes working and it does fine with the directional lights but this is not how flakes work. Metallic paints like silver have to be affected by the environment as well. So basically I just need 2 cubemaps, a blurred and a sharp one, both using the "scene skybox".
    Carpaint_001.jpg

    However, I can't use the default shader, since I need at least 2 highlights (flakes & glaze) and color falloffs (fresnel). Assigning a flake map into the metallic output, puts the flakes everywhere, even in non-illuminated areas. I don't want a physical simulation of car paint but some minor aspects are simply important for a realistic impression and since I have over 20 car paints, I don't want to assign another cubemap every time by testing around different skyboxes :).

    This is what I have so far. Perhaps there is a completely flubbed approach already but at least it's basically working :D.
    sf_carpaint_7302015.png
     
    pachermann and crudeMe like this.
  34. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    Users can't access GI data inside Shader Forge and the scene reflection probes and skybox are part of it.
    Inside the shader file, the variable "gi.indirect.specular" is the one you are looking for but GI use mipmaps to blur the reflection probe so even if you coded your shader, it wont give you exactly what you are looking for

    Did you activate the "Mask directional light specular by shadows" in the lighting tab ?

    If you did then multiply the flakes by a dot between light and normal direction(perturbed on), light attenuation and a value to control the intensity.
     
    VisCircle likes this.
  35. ArthurClark

    ArthurClark

    Joined:
    May 12, 2013
    Posts:
    15
    Hi!
    I need a shader that imitates an old electron tube tv. The image must consist of RGB grain and distortion that moves. Like this:


    Can you help me? Thank you!
     
  36. AkiLap

    AkiLap

    Joined:
    Sep 14, 2014
    Posts:
    24
  37. VisCircle

    VisCircle

    Joined:
    May 4, 2015
    Posts:
    43
    Too bad but thanks for the information. I played around and added the cubemap manually and my idea actually works quite well. The following images show a completely unlit scene but using the mip maps as blur is horrible. The second image shows the car paint material with a uniquely blurred cubemap in Photoshop. So I guess, I just won't get this result in a proper way.
    HDRMetallic.jpg

    HDRMetallic2.jpg
     
  38. AnthonyAckerman

    AnthonyAckerman

    Joined:
    Feb 20, 2015
    Posts:
    16
    Hi everyone, (I also posted this question in the Unity shader thread)

    I translated an older GLSL LED shader in SF. Looking at the panel close-by is ok, but when you look at it from a distance, it gets pretty messy. It starts with a moire pattern and then becomes worse when the distance to the LED panel becomes greater. Can someone give me any tips how to fix this? Ideally, when watching a LED panel from a bigger distance, the panel should look like a regular screen with no noticeable dots from the LEDs.
     

    Attached Files:

  39. Deleted User

    Deleted User

    Guest

    Ok, I have create this shader wirh SF, starting from the first that you have posted.

    I hope that goes well...



    https://mega.co.nz/#!sQdRkSJD!lMavacI2srtyQ1I-ShfUfFMNB7UuPE2vPE8K2c8O6Kw
     
    Last edited by a moderator: Jul 31, 2015
  40. Deleted User

    Deleted User

    Guest

    How can i change tessellation amount based on distance? It is for a terrain shader so needs to work across a mesh rather than changing the tessellation level of the whole thing.
     
  41. VisCircle

    VisCircle

    Joined:
    May 4, 2015
    Posts:
    43
    There seems to be no filtering at distance so you still have more leds than pixels on screen. I don't know how you set up the mask for the leds but if this is an image input you might play around with the mip maps settings of the texture. If this is a generated mask you might blur it at distance. Unfortunately I do not know how but maybe it brings up some ideas?
     
  42. AnthonyAckerman

    AnthonyAckerman

    Joined:
    Feb 20, 2015
    Posts:
    16
    Thanks for you reply. I am using a procedural mask to create the dots. I am aware that the problem would not be there if I would use a texture instead. Unfortunatly I need it to be procedural for flexibility. I found some information how to mip map procedural texture but it is very complicated, at least for me it is.
     
  43. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Dilate or fade the procedural mask based on distance?
     
  44. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I don't know a lot about tessellation, but I like to think of it as the tessellation amount applying only to the vertices. So if you want to tessellate across a mesh, calculate the tessellation on distance from the camera, and have a base mesh with a complexity that fix your needs (I've had bad luck with using a quad).
     
  45. Deleted User

    Deleted User

    Guest

    how do i calculate tesselation level of one polygon/vertex based on distance from camera? rather than the whole mesh.
     
  46. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Distance(CameraPos, WorldPos)... just plug that in wherever you need it. You're going to have to use the distance in a useful way though. There's not really a special way to do tessellation in SF afaik.
     
  47. Deleted User

    Deleted User

    Guest

    Thanks IFL; One problem though, is the change in tessellation appears too sudden, I want the tessellation level to seem to lower more gradually.
    This node tree was plugged into tessellation

    Now the problem is, i get A very obvious and sudden change between no tessellation and tessellation.
    Explanation: vertices are added/tessellated at a constant/gradual rate with increasing camera distance; BUT the volume they cover is increasing more and more rapidly (exponentially-ish) with increasing camera distance. This gives a "popping" effect when the tessellation is decreasing to a very low level. My only idea to combat this is by adding/subtracting value more and more rapidly (exponentially-ish) to the value of the "distance" node.
    I have no idea how i can do this, can a shader master help me?.
    If you don't understand my explanation then please say, and i will elaborate.
     
    Last edited by a moderator: Aug 2, 2015
  48. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Hi Shader Gurus :) I have tried to avoid posting here on this subject but I have run out of resources on the internet that can help me and I am a bit desperate now.

    Has anyone successfully created a shader that uses an Atlas Texture for blending textures like you would for a terrain (splat) or vertex colour blending? I know that a UV mapped mesh texture can be atlased very easy with others but splat and vertex based blending textures are not associated with the UV in that way and I am struggling to figure one how to approach this task. I am trying this convoluted approach because I think I can improve the mobile platform memory and performance footprint of my game by reducing the amount of textures I need to load and their size.

    I have had a go at doing this in SF (see image) but I am not sure I am on the right path and a strong part of me is thinking that I should probably be doing this in Unity (C#) by loading an array with sub textures? I think I know why I am having difficulties but would like to know if SF is the right route to take or if I should take a different direction.

    Below I have a test shader with a plane with R,G,B and A vertex colours painted in to test the texture atlas and I have a 1024 UV texture divided into 4x512 coloured subtextures to help debug.

    Has anyone ever got something like this working before?

    ISSUES:
    Tiling is limited to 1 x 1! Anything more (e.g. 2 x 2 or 4 x 4) and it does not work.
    As you can see there is a scale issue because each sub texture is only coming through as 256 x 256 so I am not getting the full 512 subtexture.
    I have a FRAC node ready to deal with MIP MAP issues but I can't connect this to the texture node for some reason so I am avoiding this part of the problem for the time being until I can at least get the subtextures right

    Anyone got any ideas?.
     

    Attached Files:

    Last edited: Aug 2, 2015
  49. Steven

    Steven

    Joined:
    Dec 23, 2009
    Posts:
    43
    Does ShaderForge in the RoughMetal workflow use an inverted roughness map when compared to the standard RoughMetal shader? It seems the only way to get the same result is to invert that map.
     
  50. CastleIsGreat

    CastleIsGreat

    Joined:
    Nov 10, 2014
    Posts:
    176
    How difficult would it be to create a realistic cloud using shader forge, or even a more realistic fog than what can be done with basic billboards and shuriken?