Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. duncanx

    duncanx

    Joined:
    Feb 12, 2011
    Posts:
    45
    One of the problems with allegorithmic's bitmap2material or their substance designer, is that the shaders that ship with Unity don't support any of the output maps except for the 2-3 basic ones. You can find shaders on the store that add another 1 or 2 inputs into the mix, but it's still pretty far from what substances can output. Can Shader Forge make shaders that support all of the substance outputs? For example things like a curvature map, ambient occlusion, etc etc
     
  2. wingcutangel

    wingcutangel

    Joined:
    Jan 14, 2013
    Posts:
    6
    Hello. I've been following this great thread for quite some time, I love Shader Forge but I have a problem. What I am trying to do is recreate the box projected cube environment mapping tehinque in SF. All goes well until a certain IF looks dramatically different in SF compared to a standard shader. $forum question.JPG On the left you can see the shader written by hand, on the right sthe SF version (the result of the IF is plugged into diffuse). Any ideas?
     
  3. wingcutangel

    wingcutangel

    Joined:
    Jan 14, 2013
    Posts:
    6
    I've created a shader that uses metalic and roughness maps from Substance designer without any trouble, I don't see why you could not support the other types (especially AO would be realy simple to add)
     
  4. Chaoss

    Chaoss

    Joined:
    Jul 8, 2011
    Posts:
    327
    How would I create a shader that makes a 'quad' plain always face the camera on the Y axes only? I've tried everything and not even our programmers can figure this one out, this 'must' happen inside the shader. Alternatively if that is not at all possible, how would i... based on viewing angle increase the value of the alpha clip, so when viewing from the front it's normal (0.75) and as you move towards the side it fades (increases up past 1). This effect is to help avoid the cardboard cutout effect when making X shaped low poly trees and viewing them so the edge of one of the slices if closest to the camera?

    Does anyone here have any ideas because we're stumped?
     
  5. IllTemperedTunas

    IllTemperedTunas

    Joined:
    Aug 31, 2012
    Posts:
    782
    @ choas in terms of getting a fade based on vieing angle I'd suggest plugging a fresnel node into the alpha channel (you can multiply your current alpha by this, you may want to try playing with a 1 minus node in regards to the fresnel.
     
  6. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
  7. Steven

    Steven

    Joined:
    Dec 23, 2009
    Posts:
    43
    Hey Acegikmo.


    I assume there is some specific processing on the normal maps that is costly or messes with the texture entirely that buggers the alpha channel, but if this isn't the case I was wondering if it is possible to keep access to the alpha channel in normal map nodes. I could conveniently store an edge highlight map in the alpha channel that is related to the normal map I am using, save me from having to store extra maps.


    Edit - I just found info on what Unity does to normal maps, so that is out of the question.
     
    Last edited: Apr 1, 2014
  8. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    would you mind sharing a screenshot of your shader. I've been needing to delve into SF and create shaders for substances but hadnt had a good starting point. Thanks.
     
  9. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Supporting AO maps, curvature maps, and all that, is something you can already add in Shader Forge, so, yes :)
     
  10. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You can easily write your own asset postprocessor for the kind of normal maps you'd like to use. For instance I use "_p.tga" ending for any normal textures that store an alpha channel in addition to their RGB channels.
    When the assets get processed this texture does not end up as a regular normal map. It gets compressed as DXT5 - but before that I manually swizzle channels with the help of the custom postprocessor.
    Back in the shader I know which channel of the processed texture contains the actual YX components of the normal texture. And I know what channel the alpha ended up in.
    So I leave the Texture2D asset as is (don't tick the Normal checkbox) and extract the nessecary data from the respecitve channels manually.
    Sounds like a lot of work. But it gives you the ability to store alpha data with your normal map. Also with 0.28 came the Code node. So alot of this stuff can be put into a smaller node. No clutter on screen anymore.
     
  11. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    A little warning ahead of time:

    As of Shader Forge 0.29, the minimum Unity version required will move from 4.2 to 4.3

    This is because Unity added their new Undo system in 4.3, which Shader Forge will use.
    It should be released within the next two days :)
     
  12. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    For this to be robust you need matrix support and access to the object matrix, camera matrix, and inverse world matrix. None of these are available in Shader Forge currently.
     
  13. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I just wanted to throw this out, but I'm thinking about combining specular and glossiness texture maps using a different tool to a single texture (spec in R, gloss in G, which leaves me a couple channels for whatever).

    The textures I created (using substance designer), are grayscale... so I believe I could save a bit of memory and trouble doing this... create my shader to take this map, separate the channels, and hook them into the appropriate channels.

    Is this something commonly done and I am just a bit slow on the uptake or is this a bad idea as it actually does not save any resources or processing?
     
  14. Deleted User

    Deleted User

    Guest

    I can't seem to get normal maps working with terrain. The splats work great, but the terrain doesn't seem to be applying the normals. The shader preview in Shader Forge shows the normals taking effect, so I'm pretty confused. What did I forget to do?

    Here's my chain: http://i.imgur.com/pBPdeMA.jpg
    And here's the terrain: http://i.imgur.com/KCJIjqJ.png — No normals. :(
     
  15. Psychon

    Psychon

    Joined:
    Mar 11, 2014
    Posts:
    17
    So you need to setup your camera to render depth blend texture though it's SUPER weird that your sphere is flat with it plugged in because even when I didn't have the camera setup it would still rendered the refraction but it just had sorting issues. You'll want to add a new script to your camera and enable it for the depth to work correctly. Assuming your camera is called camera I think that should work.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameradepthTextureMode : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         // Generate a depth
    9.         Camera.depthTextureMode = DepthTextureMode.Depth;
    10.  
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.    
    16.     }
    17. }
    Also make sure your shader is set to alpha blend
     
    Last edited: Apr 2, 2014
  16. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    thanks
     
  17. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's easy to do, and also quite common. You save a lot of memory, but you do lose quality when using compressed textures
     
  18. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    Thanks Ace.. I was just about to post so thanks for sparing me the embarrassment of responding to myself :) also, just want to say thanks so much for all the effort you have put into this tool and especially the support you've been providing.. it has really been helpful, there is a ton of information in this thread alone and the Wiki will hopefully be a big help.


    I combined the Glossiness and Specular in Substance Designer into a RGBA Merge node and output to a TIF... I was able to save ~40% by doing this, 2 files totaling 8.7MB to a single file of 5.3MB. And you're right, it was easy to do. (eventhough it has taken me a few hours to figure out this and among other cross-tool issues, i'm still learning though).

    I have been struggling a little trying to match quality between SD and Unity. I think its' just a matter of tweaking settings as the shaders are a little different. They have a "relief" blinn-like shader that is close, but matching specular reflectivity and lighting setup is a odd. I wish I was able to export to a GLSL file from Shader Forge that would work in Substance Designer.. it would make that process a lot easier.

    here's how I put the nodes together to combine the channels in SD:

    $sd-sf-img01.jpg

    and splitting in SF:

    $sd-sf-img02.jpg

    output as rendered in Unity:

    $sd-sf-img03.jpg
     
  19. Deleted User

    Deleted User

    Guest

    Hmm, I tried following your advice, but I ran into a problem with trying to use a fixed direction instead of the normal direction node. The normal direction node has an option for "perturbed" which makes the shader use the normals. Is there a way to apply the "Normal" input to the fixed direction?

    Here's the chain: http://i.imgur.com/Ob9M7zp.png
     
  20. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    well.. my imagination has outgrown reality again. seems that the shader I built (though looks / works great on my desktop) does not work at all on my Surface device (Windows RT)... the surface is just black. I recalled reading that SM 2.0 is only supported for that hardware (its' the original surface tablet)

    Direct3D:
    Version: Direct3D 11.0 [level 9.1]
    Renderer: NVIDIA Tegra 3 (ID=0x35303130)
    Vendor: Unknown (ID=4144564e)
    VRAM: 484 MB

    so I enabled the experimental feature "force sm 2.0", set target renderers to Direct3D 9 and your new option for Windows RT (not really sure what that does honestly, but seemed appropriate for that platform), disabled all other renderers., and set graphics emulation to SM2.0 Oh dear...

    Shader warning in 'Shader Forge/chamberMat': Program 'frag', pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them (compiling for d3d11_9x) at line 134

    Shader warning in 'Shader Forge/chamberMat': Program 'frag', Compiled shader code uses too many arithmetic instruction slots (84). Max. allowed by the target (ps_2_0) is 64. Consider increasing optimization level to reduce instruction count. (compiling for d3d11_9x) at line 145


    I'm not sure what that first message is, maybe safe to ignore... but the arithmetic slots I am taking is the reason why it shows as black on the RT. Somehow I guess I need to optimize the shader by hand and treat this platform like mobile...? I'll take another look at your wiki on that, but first glance I would say that has gone way over my head (I need more resources lol).

    So, I thought for temporary solution for this platform, I would create a simple diffuse/bump.... same renderer and emulation settings:

    Shader warning in 'Shader Forge/chamber': Program 'frag', implicit truncation of vector type (compiling for d3d11_9x) at line 37
    Shader warning in 'Shader Forge/chamber': Program 'frag', implicit truncation of vector type (compiling for d3d11_9x) at line 77
    Shader warning in 'Shader Forge/chamber': Program 'frag', error X4539: sampler mismatch: sampler used inconsistently (compiling for d3d11_9x) at line 133

    and it is black in both SF and unity emulation display. ok, this can't be from too many arithmetic operations.... any ideas?


    [edit] wanted to add that I am using a lightmap (enabled on shader too).
     
    Last edited: Apr 3, 2014
  21. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    This is all due to the limitations of SM 2.0; uncheck that and it should work.
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Beta 0.29 is now out! This is (again) possibly the last beta before SF goes 1.0 :)

    New in Shader Forge Beta 0.29:
    • You can now Undo and Redo! As a result; you now need Unity 4.3.0 or later (Previous minimum was 4.2.0)
    • Added node: Posterize. This node will turn smooth gradients into stairsteps
    • Added node: Relay. Outputs its input - useful for organizing connections
    • The Code node can now read from Texture Assets using the sampler2D input type
    • Fixed a bug where the code node didn't compile properly. It's now also using the function name in the code
    • Fixed a bug where the code node's output was pending instead of typed
    • Fixed a bug where node previews sometimes displayed too many color channels
    • Fixed a bug where the Parallax node could cause the shader not to compile
    • Fixed a bug where the version checker didn't work
    • Slightly improved the look of the main node when using the light skin
     
  23. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I no longer get those messages, but the shader is just black on the actual device... shows ok in Unity with 9.1 emulation, so this is odd. I think it goes back to needed to optimize for mobile and reduce arithmetic operations.


    [edit]

    yes, it is going to a fallback if configured. which is odd, even if I have a very small shader setup in SF (diffuse, normal map, and diffuse power).

    $sf-img001.jpg
     
    Last edited: Apr 3, 2014
  24. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    Dont work http://i.imgur.com/pR4jbIO.png

    and
    $sf_watershader_432014.jpg

    can u give your tree, mb i have some error in my tree
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Strange - it says .29 is out in my shader forge window, but the app store still shows .28..
     
  26. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    ya, same here..
     
  27. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Strange. Did you get the new stuff or is it only displaying an incorrect version in the asset store?
     
  28. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    says 0.28 in the shader forge window.. and also says 0.28 in the asset store..
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yeah, I've encountered this one before. Essentially, if the compiler thinks the value your passing to pow *might* be able to be negative (not a constant, or cannot be folded into a positive only result) then it'll throw this error. It seems very inconsistent, because it's really dependent on where the input comes from. In many cases, it won't throw the error at all. Anyway, if you wrap the input in an abs you'll be fine.
     
  30. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    well... I grabbed my package of strumpy, and built a similar shader and was able to get the ALU down to 48 from 74 (based on my earlier graph with diffuse, diffuse power, gloss/spec from split RGBA file with simple power multipliers) for use with #pragma target 2.0; however, I have the same problem... looks fine in DX11 9.1 emulator, but shows up as black surface on the device.. :sad:


    so, not sure what the deal is... not like I am getting any errors in any log files at all on this one... not sure what more to do, ... the shader from SF just looks better too...
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    The various checkboxes in the shader settings itself affect how expensive your shaders are as well. Try turning off features and/or lowering quality of things.
     
  32. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
  33. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Beta 0.30 is now out, this time it's more of a hotfix for 0.29, as it had a bunch of nasty issues. This is (yet again) possibly the last beta before SF goes 1.0 :)

    New in Shader Forge Beta 0.30:
    • Fixed a bug where the Channel Blend node crashed Unity
    • Fixed a bug where dragging nodes sometimes caused severe lag and memory leaks
    • Fixed a bug where properties were never removed from the property list
    • Fixed a bug where you had to connect to the MIP input when using textures in vertex offset and outline width on OpenGL
     
  34. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    working good for me today :)


    ok, got it working finally with forcing SM2.0, I had to ignore projectors... not sure what the deal there was as the emulator would still show it working for D3D11 9.1, but it was bumping instructions above 64 (like to 66 or 67). I was able to change a few other settings to get it down to 50, and the shader looks really nice (well, at least to me, compared to what I could barely do in strumpy).

    thanks again Ace for your help!
     
  35. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    steel dont work ...

     
  36. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
  37. kaizokuo

    kaizokuo

    Joined:
    Feb 10, 2014
    Posts:
    3
    Hey guys,

    I'm sorry if there was a discussion about it, but I don't have time to read all the 60 pages;
    I would really like to buy this (seemingly very cool and powerful) extension, but may I ask you
    to tell me, whether or not it is usable on mobile platforms (especially on iOS, Windows Phone,
    I don't care about android :D ), on gaming consoles, and if yes, with what kind of restrictions and performance?

    Thank you in advance and congratulations for the maker! :)

    Have a nice day,
    Kai Zokuo
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's usable, but you may run into performance issues - especially if you use many textures and has lighting turned on. Essentially - shaders will most likely work, but be careful :)
    The thing is that SF is primarily aimed at higher-end platforms, and does most things on a per-pixel level rather than per-vertex.
    That said, some companies, such as Rovio and Toca Boca, both use Shader Forge for prototyping shaders, and optimize them by hand later on.

    Also, Shader Forge is 50% off today :D
    Would be awesome if any of you would help spread the word about it!

    http://u3d.as/6cc
     
  39. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,348
    Hi, i have some questions before i buy

    Is there any guarantee this will work with deffered in the future ? I use deffered in at least 50% of my scenes and i could not work wihtout it, or at least knowing will be implemented for sure at some point.

    What would be a timeframe for that addition ?

    The other question is about Skyshop, i use it everywhere, so is it fully compatible ? And i read something about buying Skyshop nodes sepratly, what does that mean ? Are the nodes at extra charge somewhere or will come with Skyshop next update ?

    Also is the displacement mapping available without DX11 ?

    Finally what do i need to get the exact effect of this video (Shader Forge - Real-time spherical area lights) ? Is it possible just with Shader forge for both the sphere glow and floor reflection for example ? Is this scene included in the pack ?

    https://www.youtube.com/watch?v=3tHI2J9_c9k




    Thanks
     
    Last edited: Apr 7, 2014
  40. kaizokuo

    kaizokuo

    Joined:
    Feb 10, 2014
    Posts:
    3
    I hope it won't flood the topic, but can you please give us some hint, what do you mean by this performance issue; like I would use it occasionally, may it be a resource problem, or is it the case only if it is used frequently? I don't know anything about shaders, I couldn't optimize them, I just want to have nice effects, around 4-5-max 10 occurrences per screen.

    And if it is a stupid question, because of it-depends-on - sorry.

    Yes, I would like to buy it because of the sale, but still, it seems that it is worth even the full price! Thanks again for this stuff! :)

    Edit, for the manufacturer (Joachim?): do you plan on optimizing this extension for mobiles? If yes, what is the 'schedule', 'around-when' would it be available? Thank you in advance!
     
    Last edited: Apr 7, 2014
  41. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I want to make my own watershader with planar realtime-reflections (I have UnityPro).
    Is there any example / tutorial on how to do this with shaderforge?
     
  42. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I have no timeframe at the moment, but, more info here:
    http://acegikmo.com/shaderforge/faq/?Q=deferred#deferred

    If you own Skyshop, the skyshop nodes will come for free in the next Skyshop update :)
    As for the specific features of the Skyshop nodes, you'll have to ask them!
    From what I can see, it seems to support most things that I would want from it, but I'm not really a power-user of Skyshop, so I can't tell for sure.

    I've planned to make a tutorial on that at some point, so, soon :)
    And no, the scene is not included.

    It's hard to say, because, as you mentioned, it depends on a lot of things. I've gotten varied reports on mobile shading. Some say it works fine, some say it's horrible. But essentially, SF isn't made for mobile development at the moment.
    I don't have a solid timeframe for a mobile friendly version of SF at the moment - for several reasons

    Also, if you still want to use SF, but also keep things optimized when finalizing the visuals, you might find this useful:

    http://acegikmo.com/shaderforge/wiki/index.php?title=Using_Shader_Forge_for_Mobile
     
    Last edited: Apr 7, 2014
  43. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    Just took advantage of the promotion! Lets see what my artist brain can do with SF!
    - Is this possible? Some pointers on how to achieve it?
    - How would i benefit from the integration with SkyShop (i own it also)?

    Congratulations on the great product and thanks!
     
    Last edited: Apr 7, 2014
  44. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yep! Vertex offset based on distance. You can use the Distance node, World Position node, and the View Position node, and divide the distance by some factor to change the shape of the falloff.

    Read the post above yours, and check out the screenshots on the asset store :)
    There's a Skyshop example there.

    Thanks!
     
  45. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,348
    Thanks, this clarifies a lot :)

    "That said, SF shaders will work when your project is rendered with deferred rendering, but the SF shaders will be forward rendered"

    This is a major point, i can now buy the product :)
     
  46. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    @Acegikmo,

    I had a dream the other day that there is a Mobile button on SF, I couldn't believe it, clicking this button generated a Mobile version of the shader. Totally awesome. I woke up, ran to the computer and checked SF, but sadly it wasn't there yet.

    I did read the link you sent about mobile optimization for SF and one thing that is spot on is that nearly everything is going Mobile. I'm sure that this road is tricky, however, what you've done with SF for desktop is nothing less than miraculous. Perhaps you could wave the magic wand to enable Mobile support in the near future.

    Cheers.
     
  47. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    No support on planar reflections!?
    Shouldn´t be too hard
    to implement for someone who knows shaderprogramming.
    Any help is very welcomed!
     
  48. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  49. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,348
    Incredible asset, just tried it and is working like a charm

    Especially love the vertex manipulation shading.

    Is it possible to emulate displacement mapping through that shader without using DX11 ? ( i want my game to be globally applicable and cant base it on DX11)
     
  50. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You can offset any fixed amount of vertices by a displacement factor along their surface normal - if this factor is coming from a texture2D or gets generated procedurally is up to you.
    But you can't create new vertices for more defined tesselation in areas that are close to the camera and get displaced for example. That's just not possible without DX11.