Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    This is looking fantastic.
     
  2. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    That looks great!

    Are you able to share the node tree? I am also looking to implement a sf skin shader with marmoset skyshop support as well

    Cheers
     
    VargaPD likes this.
  3. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Hello, I'm new to shader forge or shaders in general.
    I'm a c# developer creating my own game and I am looking to solve a possible problem with a custom shader.

    What I am looking to do is use the textures/maps/Detail masks I already have but I want to be able to change a detail color(Detail Albedo x2) at runtime. The problem is I see the tutorials are a bit thin and I have no idea how to even begin this.

    Any help pointing me in the right direction would be great.
     
  4. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    I see no one monitors this forum, anyone know the best way to get answers to problems/questions?
    Bueller...Bueller...anyone?
     
  5. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
  6. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Try and clamp (0-1) after the Comp. Mask.

    I'm thinking when you do the remap from 0-1 to -1 to 1, the darker bits are getting mapped to -0.5 or something, but because it only displays 0-1 in the comp mask preview you can't really see it.

    The funny color is because it's trying to lerp between (base) and (tint) by (-0.5) which is what gives it that funny color.

    A lot of people don't know that lerping will actually go beyond values of 0-1.
    Ex, if you lerp between (0,0,0) and (1, 0.5, 0) by (2), you will get (2, 1, 0).
    Likewise, if you lerp between (0,0,0) and (1, 0.5, 0) by (-3) you will get (-3, -1.5, 0).
     
  7. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Hello!

    Getting two error messages when opening Shader Forge 1.26 in Unity 4.5.0B21:

    LoadAssetAtPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.

    UnityException: LoadAssetAtPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.


    Also, preview of animated Shaders (using the Rotator node) won’t play smoothly in 5.4.0B21.

    Oh and when I start the game using the following shader, I will get the error messages at the bottom:

    screenshot.jpg

    get_skinIndex is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_NodeConnector'.

    Internal_CreateRenderTexture is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_NodePreview'.

    INTERNAL_get_fogColor is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SFPSC_Blending'.

    get_skinIndex is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SFN_ComponentMask'.

    get_skinIndex is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.

    GetAllAssetPaths is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.

    UnityException: GetAllAssetPaths is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.


    Greetings,
    Shu
     
  8. MrPaPaBear

    MrPaPaBear

    Joined:
    Apr 25, 2015
    Posts:
    3
    Hey Guys, i want to share with you guys my cubemap shader. maby it is a good start to make a custom IBL based shader enjoy! Cubemap shader.png
     
    hopeful likes this.
  9. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    *edit* solved this by modifying one of the built-in Unity cgIncludes to have the lightmap variables defined

    I'm using ShaderForge 1.06 in Unity 4.7 with Skyshop, it is not adding the unity_lightmap variables to shaders when using Lightmap support, so the shaders don't compile:

    undefined variable "unity_LightmapST"
    undefined variable "unity_Lightmap"
    undefined variable "unity_LightmapInd"

    What is strange is it had been working fine, but I recently deleted and reimported ShaderForge, thinking I could upgrade- but forgetting the last version is 1.06

    If I add the missing variables into the shader manually it works, until I make a change in ShaderForge and it rewrites the shader file..

    Any ideas how I can fix this?
     
    Last edited: Jun 18, 2016
  10. NAVAZA

    NAVAZA

    Joined:
    Feb 20, 2016
    Posts:
    7
    I was wondering how to make water foam similar to this:
    https://gyazo.com/a0c786c82fd1c0007fc038cfc789b413
    I believe they are using the depth blend method, but they also have foam around the objects, not just in front of them.
    I was trying to achieve a similar result by bluring the depth blend node, but I don't think that's possible within SF/ I'm not doing it correctly.

    So, I would appreaciate any help with this, or if you can point me in a better direction to achieve this effect. Thanks
     
  11. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    Hello, I have a kindof noobie question (I have checked the wikk and documentation, even Unreal materials to get my head around it but I'm not sure how...)

    I would like to know how does the vertex animation work for things like water or for example a flag: Let's say I want some part of the flag not to be affected by the vertex animation, the part attached to the pole, and I paint those vertices green but I don't know how to tell my nodes not to affect green vertices... And for the movement of the flag (or water) I would like to move some vertices upward while others downwards to create that wavy noise, but using functions such sin affects everything and I'm stucked there :/

    Thanks!
     
  12. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    When I try to "Open [a shader] in Shader Forge" in 5.4.0B22, Shader Forge won’t open at all (in B21, at least, it was still opening) with the following error messages showing up:

    LoadAssetAtPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.

    UnityException: LoadAssetAtPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SF_Editor'.
     
    pointcache and CleverNickname like this.
  13. Tuni

    Tuni

    Joined:
    May 24, 2013
    Posts:
    74
    We have the same problem. I hope that we get an update for this desptie the success of Budget Cuts.
     
    CleverNickname and Shushustorm like this.
  14. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Hey there, I am trying to create a mobile mesh terrain shader in shader forge, but I am a bit confused and can not find tutorials, I basically need, a base color map, a base normal map, a splat map, 3 detail maps with normal maps. I was able to get the normal map, splat map, and detail maps working using the info on your site, however the color map doesn't do anything, I will show you a picture of my shader. If you could help that would be amazing, thanks!
     
  15. NAVAZA

    NAVAZA

    Joined:
    Feb 20, 2016
    Posts:
    7
    You basically multiply your vertex displacement function by your vertex colors, as you would do with a regular mask.
    That way, if the part attached to the pole has a value of 0 in the red vertex color channel, and white on the other extreme, when you multiply that by a waving function, it won't affect the attached area.
    Here's a little example:
    https://gyazo.com/41bfe312f266535baa066d99338c3e52
     
    Ga2Z likes this.
  16. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    Awesome!! Thanks :D!
     
  17. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Shader forge still can't manipulate vertex data (ie vertex shader, like colors, normal, lighting) or is still mostly a fragment based editor?
     
  18. johansan

    johansan

    Joined:
    Nov 7, 2014
    Posts:
    3
    Hey,

    I am working on a Unity project for a large company, and need to create a highly realistic-looking plastic shader.

    I found what I'm after on the blender forums, but since I'm no shader expert I'm at loss how I should go about to re-create this in Shader Forge. It's this:


    From http://blenderartists.org/forum/showthread.php?302413-Cycles-Glossy-Plastic-Material

    And this is how it looks like:

    Any shader expert here that could help me implement this in Shader Forge? Getting the double fresnel passes right here is the trick to get the proper glossy feeling.

    Thanks in advance
    Johan
     
  19. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    OK, firstly there's no (by default) noise node. However, you can go to the Shaderforge Wiki and you can see that someone's already made a noise graph. Check to see if that's similar enough, but remember to change things like scale, octaves, etc.

    The Bump node you've got, you'll have to look into Height To Normal. Again, check out the Shaderforge Wiki, it's on there as well. You may need to actually use a noise texture (instead of a generator) but to be honest I don't see why you wouldn't do there here in the first place anyway.

    BSDF, I'm not familiar with this early in the morning, is it like BRDF? If it's similar, google Shader Forge BRDF and make modifications where needed.

    Layer Weight and Mixing: There's a fresnel node in SF already. I don't know what the 'blend' option in your tree actually does (increase strength?) but if you know, then just use the nodes afterwards. Like plug (fresnel) and (Value:0.5) into a (Multiply) node.

    Mixing is what we call Lerp. It takes A, B and C inputs, and changes from A to B based on C being in the 0-1 range. So if C is 0 you get whatever you plugged into A, if it's 1 you get B, and if it's 0-5 you get something halfway between. You can plug textures, values, whatever into A B and C there.
     
    johansan and IFL like this.
  20. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    :confused:



    [EDIT::] The rest is spot on though. You're awesome for helping out so much.
     
  21. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    LOL, forgot about that one.

    I generally don't use it so much because the 'granuality' is too fine, but I worked out somewhere in one of my projects a way to control the 'resolution' and get bilinear filtering on it.
     
  22. JPlaystudios

    JPlaystudios

    Joined:
    Jun 24, 2016
    Posts:
    1
    How well do these Shaders perform on lower end devices?

    Thanks
     
  23. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Things in Shader Forge aren't going to be as fast as something written by hand. Having said that, they're not that slow. I've seen SF shaders used in iPhone 3s and such for things like oceans and particle effects.

    The key here is to keep the shaders you make simple. If you can find a way to lose an expensive node in your shader, see that it's lost.

    Expensive nodes are things like fresnel, any of the advanced math nodes, as well as things like using custom UV manipulation and such.
     
  24. johansan

    johansan

    Joined:
    Nov 7, 2014
    Posts:
    3
    Thanks for all the advice, I managed to get an excellent result on my iPad quite quickly. :)
     
  25. CleverNickname

    CleverNickname

    Joined:
    Aug 18, 2015
    Posts:
    16
    Same. Hoping this has a quick fix that can get resolved soon.
     
    Shushustorm likes this.
  26. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    I hope so, too. Really want to use the new Particles in 5.4, yet I need custom shaders. Maybe I should learn how to Cg myself after all.
     
  27. NAVAZA

    NAVAZA

    Joined:
    Feb 20, 2016
    Posts:
    7
    I have been investigating some more, and I found two people getting similar results in UE4 by using a node called "DistanceToNearestSurface"
    Do we have something like that in unity/shaderforge? Any other ideas on how to approach this?

    https://forums.unrealengine.com/sho...-a-toon-style)&p=522757&viewfull=1#post522757
    https://forums.unrealengine.com/sho...o-remove-grass&p=376116&viewfull=1#post376116
     
  28. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Just made this scary looking guy to test the skin shader.

     
    FPires likes this.
  29. moure

    moure

    Joined:
    Aug 18, 2013
    Posts:
    184
    Seems to me that you've been playing starcraft lately ;) My life for aiur!

    Shader looks great. Could you post a with/without sss comparison?
     
    DMeville likes this.
  30. Twoonebe

    Twoonebe

    Joined:
    Mar 30, 2013
    Posts:
    174
  31. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    I suggest someone make a website for requesting/sharing/selling/collaborating with people for Shader Forge shaders (for Unity ofc). You know, somewhere that other people can easily go and save time from recreating wheels, see what I mean.
     
    Last edited: Jun 28, 2016
  32. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    There is the Shader Forge Wiki, I think everyone's just been a bit slack with uploading stuff to it. Heck, I'm sitting on a couple of dozen shaders destined for the Asset Store, gotta free up some time and get them uploaded.
     
    imDanOush likes this.
  33. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I actually took that reference from Furio Tedeschi but I guess it fits both concepts :D

    Here's the SSS on-off video, watch it in HD !



     
    Deon-Cadme and FPires like this.
  34. topsekret

    topsekret

    Joined:
    Apr 18, 2013
    Posts:
    69
    Would it be possible to add the ability to #include cginc files in a future version of Shader Forge to be used in conjunction with the code node?

    I like to write shaders by hand, but our fx artist prefers to use Shader Forge. Recently, I implemented a new effect and put the modular pieces in a cginc file for reuse later. But our fx artist wanted to leverage some of my tech in shader forge. Rather than reconstruct all my code in nodes, I decided to use a code node to simply call one of my functions in a cginc file. I then told the fx artist to copy-paste the #include in the code generated by shader forge whenever he finished editing it. It would be nice if he didn't always have to remember to copy-paste this.
     
    IFL likes this.
  35. S-Miyahon

    S-Miyahon

    Joined:
    Jun 30, 2016
    Posts:
    12
    Hi, I have a question about matcaps. The official node setup has some weaknesses that I would like to eliminate if possible:
    http://acegikmo.com/shaderforge/wiki/index.php?title=Matcap
    This is the matcap I'm using for testing:

    When in the center of the screen, this 3D sphere looks more or less okay, thought a slight distortion is already visible. (Note the missing rimlight etc.)
    When positioned closer to the edges of the screen, the problem becomes more apparent. The matcap image is distored in a very unnatural way, unlike in other software like ZBrush or Blender. The "reflected" spots and highlights that you would normally want to remain still are moving all over the object. You can even see the mirrored matcap image on the other side of the object.


    The current matcap shader in the Shaderfore Wiki works fine for objects viewed in isometric perspective, but as soon as perspective distortion comes into play, this shader is practically useless.
    My question: Is there a fix for this? Is it possible to expand on the existing matcap shader and resolve this issue?
     
    Last edited: Jun 30, 2016
  36. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Gut feeling from the look of it is that either Unity's been changing the way the camera handles normals, or something's wrong with the shader.

    As you can see, the one in the center is right because the 'front' of the sphere is facing directly at you. Since the Matcap is aligned with the front, it's OK. The one in the bottom right corner, its front is facing to your lower right, so that's where the image is being projected from.

    It's the old game camera math, like how the viewport far plane is always (X) meters from the camers, even though it's obviously further away at the far corners and edges than the center.

    My guess would be that you have to adjust the new normal direction somehow based on FoV and such.

    Try this: After the Remap node, add a blend node, set to overlay, and plug the remap into both. Then add a Lerp node, and lerp between Blend and Remap by (field of view in degrees divided by 180, or 90, or something).

    For testing, you could even skip the lerp node and add a slider so you can adjust it manually to get a hang of how it works.

    Finally, ALWAYS ALWAYS add a bit of fisheye image effect to your camera.
     
    IFL likes this.
  37. S-Miyahon

    S-Miyahon

    Joined:
    Jun 30, 2016
    Posts:
    12
    @Jesus
    Thanks for trying to help. Your gut is going in the right direction, though sadly, your approach didn't work. I even tried a couple of variations.
    No, not entirely, but it's the closest to being right, of course. It should look exactly like the matcap image.

    I think that maybe a View Direction Node might need to go in there somewhere to help calculate the right angle.
     
  38. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    My bad! I think I uploaded that shader to the wiki. Here's a fix for the duplication on the back-side and a slight improvement on the one in the center. This is pretty much what Blender does. Also, as far as I know, almost every program that uses a matcap and a FOV greater than 30 will have this same issue at the edges of the screen.
    SF_SMiyahon01.jpg

    Finally, ALWAYS ALWAYS use color grading, tonemapping, anti-aliasing, ambient occlusion, depth of field, global fog, chromatic aberration, bloom, a slight vignette, and maybe a fisheye effect. See the image below for a comparison. Note how the spheres are far more realistically spherical in the image above. Guh, the one below makes me sick.

    SF_SMiyahon02.jpg
     
  39. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    ooooooooh no. Don't gimme that chromatic abberation nonsense when there's fisheye to be had.

    Isn't there a projection correction effect on the asset store? That, or something similar, should fix the ovaloid abominations that spheres become at the edge of the screen when you use a FoV above 10.

    I'll have another look at the math. The transform from world normals to viewspace normals is the problem. In worldspace normals all the +Z normals are parallel. I think even after the transform, it's still parallel, when they should converge on the camera at the center of each sphere. I'll see what I can think of to make them all face the camera properly.
     
  40. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    It's a spheremap, not an ovaloidmap. If you get it to map perfectly to the normals, then it'll probably have severe stretchmarks, which is okay I guess. Good luck!
     
  41. S-Miyahon

    S-Miyahon

    Joined:
    Jun 30, 2016
    Posts:
    12
    @IFL
    Thank you, that's definitely an improvement. Even if it somewhat distorts the matcap image towards the edges -- even in iso perspective for some reason. But I think I'll just go with this solution.
    My gosh, how did I never notice that? I just recreated the scene in Blender, and yes, you're right.
     
  42. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    @S-Miyahon - if you don't want the edges distorted, change the remap input to (-1, 1).
     
  43. kdm3d

    kdm3d

    Joined:
    Jul 20, 2012
    Posts:
    15
    Also, ALWAYS add a dark outer glow to your node trees ;P
     
  44. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Hello,
    I literally stuck too bad in creating a shader for my project, I'd be really happy if someone tells me how to get opacity map work properly in differed shaders. Please note that I only use this tool (I still don't know how to code shaders).
     
  45. NAVAZA

    NAVAZA

    Joined:
    Feb 20, 2016
    Posts:
    7
  46. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    [EDIT::]
    @Acegikmo -
    It's really frusterating not being able to use SF in the 5.4 beta. I use 5.4 for the Vive (openvr) support since pre-5.4 has the terrible thread-locking script from the SteamVR plugin. I'm against releasing updates for betas, but I hope SF will be operational once 5.4 is official.
    Great job on Budget Cuts by the way - the demo is very fun. I'll definitely be one of the first to grab it once it's released.

    ...I thought that would be obvious. You should always have a hideous black outline around stuff if possible. And, is this you?

    There's a few ways to do it, but everyone seems to stick to either rendering just the transparent objects in forward (while the rest of the scene is deferred) or they use deferred dithering, which I think looks really weird without a forward-rendered transparent shader on top of it, but it can kind-of give the appearance of transparent shadows. If you want forward-rendered transparency in deferred, there's a ton of limitations (fog, over-lapping depth-sorting, etc). If you're fine with the limitations, then the simplest route in Shader Forge is to select Forward rendering and connect an alpha to the Opacity output. Feel free to ask if you want more help.

    Have you tried using the stencil buffer stuff yet? I've messed around with it, but I'm not experienced enough with it to be giving advice.
     
    Last edited: Jul 4, 2016
  47. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    You can do it if the interesting light volume is a primitive, then you just need to calculate the bound. For example a sphere has a center and a radius, for each point compute the distance to sphere, if lower than radius, lit!
     
    IFL likes this.
  48. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Anybody ever have a transparent shader work fine in osx, but be opaque in windows? Known issues?

    edit: I'm on shader forge 1.22

    edit2: ok, made a simpler shader to test with



    This works fine on both, except when face culling is set to double sided. With double sided, it works in mac but in windows it's just opaque. Is that a directx limitation or what?

    Not really related, but there seems to be a really weird bug where the shader (cross?) compiler doesn't work right and causes really odd sorting bugs, but then fixes itself later randomly without me changing the shader... not even sure shader forge has anything to do with it
     
    Last edited: Jul 3, 2016
  49. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Well thanks for the reply, but when I make a forward shader in my project, it is fine until I assign the A channel to the opacity input:
    As you can see there is not a sphere in the renderer.
    It is interesting that the Unity's standard shader doesn't this problem.
    EDIT 1 : Assigning the A channel to the Opacity Cutout make the sphere black.
    EDIT 2 : Assigning this shader to an object would make lots of problems, the orders would all get messed up, which none of these problems ocuur when I use Unity's standard shader in my project.
     
    Last edited: Jul 3, 2016
  50. CleverNickname

    CleverNickname

    Joined:
    Aug 18, 2015
    Posts:
    16
    FYI it looks like Shader Forge is loading for me again in the latest 5.4 beta (B24), though I haven't tried to actually do anything with it yet to see if it's functioning properly.
     
    IFL likes this.