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
    Um. Disconnect your SpecTint from the multiply. Then, connect it to the second slot on the lerp. Then the multiply (the one commented with Diffuse) to the first slot on the lerp. Yeah...? I think (hope) that's it. If not, I'll admit that I'm shooting in the dark.
     
  2. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Screen Shot 2014-10-29 at 9.51.54 PM.png

    Like this? Still no luck, same problem. I don't know what else to try, so thanks for the ideas hahah.
    I've tried to think it through, I've tried to connect it in every random order, I've tried clamps before every input to the lerp.
    It's gotta be the lerp though because everything is fine until I put that lerp in. Is there another way to combine/overlay (not the overlay blendmode!) two textures or is lerp the way to go?
     
  3. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Wow, I'm apparently horrible at helping. Are you just trying to get the spec to not have influence from the diffuse color? Or have the spec have a mask before it's added to the diffuse? Or something else...?

    Edit:: never mind. I reread your initial post and it answered my questions. I'll recreate your node graph tomorrow. It should be as simple as multiplying the spec with the tint map and diffuse before the add node, but I am almost definitely misunderstanding something.
     
    Last edited: Oct 30, 2014
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    I suppose it depends on how accurate you need it to be. Maybe you could fake it by looking up the object position, world position, normal direction, scale, and object size. Of course, it wouldn't be perfectly accurate, wouldn't play nice with concave surfaces, or anything like that.

    Ideally, you COULD handle all this with a geometry shader and get around these issues, but that would limit you to DX11 and writing a lot of custom code, not just using shader forge.
     
  5. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,209
    Since there's a lot of debate between Metallic/Roughness and Specular/Glossiness, Has anyone created shaders for both workflows using Shader Forge?

    I believe this video shows how to create a shader for Spec/Gloss, but there may be more to it.
     
  6. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Metal vs spec-gloss are two slightly different ways to achieve the same thing, like the gloss in a spec-gloss material is equivalent to the roughness in a metal workflow (im using substance painter nonclemature here, they are not necessarily the same values), it would be good to get a decent grounding in PBS/R entirely to see how the two approaches relate - in the example you gave you have a blinn-phong relectance model, but this can be used in either metallic or spec/gloss approaches as far as I myself know, along with alternative reflectance models like Cook-Torrance.

    I may be being ignorant but I do think that although some things are not equivalent in both approaches, they're both able to be described in the same domain. Might be wrong!

    This guy is good reading however, anyways http://seblagarde.wordpress.com/
     
  7. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    @DMeville Is this spec/diffuse similar to what you want?
    SF_DMeville01.gif
     
  8. Ashinokami

    Ashinokami

    Joined:
    Oct 10, 2014
    Posts:
    3
    Hello everybody and thanks a lot Joachim, for helping such Arch-viz noobs like myself to get into real-time shaders so quickly!

    Currently I'm having trouble implementing Schlick-Fresnel approximation into my Blinn-Phong uber-shader (or any shader).

    I've tried to wire with nodes this formula:
    R=R0 +(1-R0)(1-dot H,V)^5
    R0=((n1-n2)/(n1+n2))^2



    Instead of rim effect I get diffuse-only surface towards the light, and some specularity in the unlit side.
    After long research I've read that SF Half and ViewDirection vectors are in World space, contrary to presumed Tangent space in equations and UDK example I was looking at. The problem is, Transform node doesn't seem to help. I also have no experience with coding and don't know how to write stuff into Code node, even with ample examples online.

    I've had success using in-built Fresnel node and used it with Exponent and Bias parameters, but I really need something with physical IOR to be a benchmark for those simplified settings. Other shaders like Water and Glass need correct values just to start.

    Also I use Fresnel multiplied with Specular color(white) and Specular Power slider, plugged into Specularity slot. Maybe that is also not the right way to do it?

    Thanks very much for assistance.
     
    Last edited: Nov 2, 2014
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    It's hard to tell from that GIF :p All I'm looking for is a way to tint parts of the spec by a colour, while keeping the rest of the spec white (and not losing it from the black x diffuse in the tint mask..) or get weird lighting issues like before!
     
    Last edited: Oct 30, 2014
  10. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    So the "SpecTint" sampler is a mask for which parts of the spec are tinted by the diffuse color instead of being white?
     
    DMeville likes this.
  11. NapalmRain

    NapalmRain

    Joined:
    Mar 3, 2013
    Posts:
    29
    Hello everyone!
    Please tell me the answers to two questions.
    I created a simple shader exactly like the video:

    But I can not figure out how to get it to work correctly with the alpha channel in double side mode, and where and how do I connect a node with a Specular map.


     
  12. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Yep exactly. Playing around with it a bit more I came up with something like this. Seems like an odd way to do it, but it seems to give the right results.

     
  13. irwit

    irwit

    Joined:
    Sep 30, 2014
    Posts:
    55
    Hi all

    I know there was some discussion about this earlier but there didn't seem to be a conclusion. I want to use either Parallax Occlusion material or a Relief Shader but build it in Shader Forge but so far all i seem to be able to create is basic Parallax mapping which lets be honest, is pretty naff. There were some great examples earlier of some made in Unreal4 but is this actually possible in Shader Forge?
     
  14. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    I had the same issue. Normal parallax seem to work, but I don't think we can implement relief mapping with the current version. At least, I didn't found any way.
     
  15. libin717

    libin717

    Joined:
    Oct 15, 2014
    Posts:
    6
    Consulting a problem.
    How to make the UDK DISTORTION functions?I want to make the Water look at have a distorting effect
     
  16. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    What's stopping you? It should be possible given the current tools, it's just quite technical to get it right :)

    Use the refraction input of the main node
     
  17. irwit

    irwit

    Joined:
    Sep 30, 2014
    Posts:
    55
    Well whats stopping me is I dont know where to start so Im posting in here hoping for some help :) I worked through the Parallax example in Shader Forge which makes sense and seems quite simple however the result shader is not really useable as the distortion is pretty awful at glancing angles.

    Have you any advice of how to build one, where to look for more information etc ? Its obviously something a lot of people in this thread are looking for but there don't seem to be any examples or solutions?
     
  18. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156


    Having a bit of fun using Shader Forge to generate post-processing effects. I'm just working on a VHS shader so it doesn't require any wacky loops, making it perfect for SF, amazingly.
     
    Deon-Cadme likes this.
  19. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
  20. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I have a general shader related question; is it better to have one BIG shader, or individual ones and switch between them when needed.

    For example right now I'm working on a toon shader which I want to apply to two separate objects of my character - his body and his head. Both of them act the same (in terms of toon shading everything) however on the head I want to have some UV animation. Is it better in terms of performance to have two versions of a shader that are 90% similar, or to have one shader that can toggle on/off extra functionality?
     
  21. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Thats quite interesting. However it would be great (especially for Noobs like me) to get a SF replica of the U5 Standard Shader. That would be a great base to work on. I am loving Shader Forge because I am pretty much awesome in turning every line of code into chaos and failure. The U5 Standard shader is pretty much awesome but lacks in some areas I need like combining different changeable diffuse colors driven by a RGB mask. It was easy for me to achieve in SF but I had no luck in copying the Standard Shader as a Node based version in SF to have a start to work with.
     
  22. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    I'm not quite sure what pbr approach the Unity5 standard shader uses, but I have a working version of a pbr shader which should be quite similar. It's not perfect yet, but here is the node tree if you want:
    http://notenoughsleep.eu/files/ShaderForge/sf_real_pbs_10292014.png
     
    toxtronyx likes this.
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    A little update:

    Some of the most requested features that people want in SF, are nearly impossible to implement simply because of how the system was designed. I've since then started a rewrite, which is from the ground up designed specifically with all those features, along with a more future-proof and stable codebase, which I now call Shader Forge 2, which is also why no updates have happened for a while.

    However, after a little meeting with Joachim Ante at Unity, he made a few good points on the fact that I should prioritize Unity 5 features, since it's coming along quickly now, especially with the beta. So, within the week, SF should update with things like Unity 5 PBR, reflection probes, enlighten integration and so on :)

    And I might as well call it SF 1.0, since I should have done that already by now
     
    RUBILYN and toxtronyx like this.
  24. Mads_AE

    Mads_AE

    Joined:
    May 12, 2013
    Posts:
    2
    Hello.

    I have looked around if there is a way make presets of nodes, but i haven't found anything.

    SF_ex.png I need all of the nodes marked in the photo in each shader, but if i want to make changes i have to go to each shader and do it, is there a way to sample this together and reuse in other shaders ?

    usually i would use a #CGINCLUDE but i want/need to use Shaderforge for this project.

    Hope there is a solution, and thanks for an amazing peace of software !
     
  25. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    So, I guess I'll be the person who asks the inevitable question. Will SF2 be a separate purchase from 1.0?
     
  26. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    No, it'll be an update :)
     
    Deon-Cadme and shkar-noori like this.
  27. kaz2057

    kaz2057

    Joined:
    Jan 18, 2011
    Posts:
    326
    Wait for Unity 5 support!
     
  28. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Hey guys this is really great so far - now i'm up to working on custom lighting. I have a question about "light position" and directional lights - How do these relate? Is there a way to determine whether the currently processed light is a positional or a directional light? This is the final piece of the puzzle for my ocean deep water shader!

    (Basically want to use a directional light as the sun, and have it fall off over distance with a gradient - got this working for other lights ... and if I can't do this i can fall back to faking it with a global normal, but then i lose shadows)

    tl;dr How do I tell if the processed light is a world light? Is the light position node useful when dealing with directional lights?
     
  29. EricColossal

    EricColossal

    Joined:
    Sep 7, 2013
    Posts:
    6
    Hello, I've been tinkering with Shader Forge for the last few weeks and it's so fun to play around with.

    I was wondering if there was a way to expose numbers so I could see what was happening a little better.

    For instance, is there any way to see the numbers that Distance and Length are generating?
     
  30. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    My bank account just breathed a sigh of relief. I'd have ended up buying it anyway since Shader Forge has saved me so much time and money, but this is great to hear
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  32. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    This is excellent news! While you'd be working the massive rewrite, deferred shading would remain broken in U5, preventing myself (and I'd imagine others who are in the same boat as me) from upgrading to 5 at all. I think this is the right choice especially if supporting it is only going to take a week. I hope tearing yourself away from your rewrite work isn't too unappetizing for you. I know it can be hard when you're in the middle of something else.
     
    shkar-noori likes this.
  33. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    You can apply shaders to animated sprites, right?

    I wanted to added a grunge texture to some animated sprites and give them an "unmoving plaid" effect to them. Can anyone give me an idea on how to start it? I'm sure it's simple, but apparently not for me!
     
  34. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    You'd probably want to use screen-space mapping for that and then some various bits of trickery if you want to layer stuff on top of that.
     
  35. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    Issue #1: I did what you asked and applied that shader to the sprite, but now I am getting a "Material does not have a _MainTex texture property. It is required for SpriteRenderer" error in the inspector, and my sprite is invisible now!

    Issue #2: I tested the same shader on a 3D model and it's definitely doing what I wanted, but the grunge pattern takes over as the main diffuse. How should I rearrange the node graph so that the model maintains it's main texture while having the screen-space mapped grunge texture over it?
     
    Last edited: Nov 6, 2014
  36. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    1: Shooting in the dark, but did you name your Texture2D input "MainTex" (which will give it the interal name of _MainTex)

    2: It depends on the effect you want to achieve; you could do a few different ways:
    You could multiply them: Screen Shot 2014-11-06 at 12.26.21 AM.png

    Or if your grunge patter has an alpha you could layer them with a lerp like this: Screen Shot 2014-11-06 at 12.28.30 AM.png

    Or you could control the lerp T with a slider (0-1)
     
    Guideborn likes this.
  37. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    This worked perfectly for the 3D model! Thanks!

    As for the sprite, I changed the name of it to _MainTex and it removed the error! Unfortunately, the sprite remains invisible. The sprite is visible under a few built-in shaders such as Sprite/Diffuse, but it won't appear under a Shader Forge shader even when I put the Sprite diffuse into the slot in the Inspector. I think this is where my problem lies.


    Edit: It works now! The sprite was flipped and wasn't showing from the back! Thanks for everything, guys!
     
    Last edited: Nov 6, 2014
    DMeville likes this.
  38. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    Rats, just when I thought I had it! The sprite is being given a "background" when it is originally transparent. It was transparent when I imported it, but the Shader Forge shader is eliminating the transparency.
     
  39. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Plug the MainTex Alpha (A) into the Alpha/Alpha Clip on the main node
     
    Guideborn likes this.
  40. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    And there we have it! I can't thank you enough, bro. I owe you!
     
    DMeville likes this.
  41. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Thanks mate! Looks pretty complex. I am not right sure if I will give it a try hence acegikmo post about SF 1.0

    Great news!

    EDIT: One thing that could already be helpful is the use of the cubemaps. Can somebody please give me a hint how to force Unity use the result of the reflection probes? The Standand shader does it by design, but I don't get it to work with a custom SF shader.
     
    Last edited: Nov 6, 2014
  42. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Hello everyone!
    I have a question about texture splatting! Maybe someone could help?
    I would like to know how to let a color texture flow into another area so that it only covers where the normals of the other area are low?
    Here are two images showing the node setup I am currently using, what the material looks like in the scene and how I would want to make it look like:
     

    Attached Files:

  43. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Cool thanks! Just to be clear - the position is the position in world space right?

    Also it'd be great if I could determine if it was a directional light vs. spot - I think that's my main issue. (As when you're dealing with a directional light, distance to the light really becomes invalid)
     
    Last edited: Nov 7, 2014
  44. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Hey i figured out - if you want to determine if a light is direction, if it's at Vector3.zero it's probably a direction light (assuming you didn't put the light at 0,0,0)
     
  45. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    I'm trying to make it so that there's a screenspace projection on something so the texture always appears flat, but I want it to move with the object as the object is moved around the screen.

    Right now, my node graph looks like this:



    I then use this script to pass values to the X and Y values of the screenspaceTransform vector4:

    Code (CSharp):
    1.  
    2. Vector3 screenPos = Camera.main.WorldToViewportPoint(target.position);
    3. renderer.material.SetVector("_screenspaceTransform", new Vector4(screenPos.x, screenPos.y, 0, 0));
    4.  
    It almost works, but for some reason there's a little bit of drift when I move the object around?




    What incredibly obvious thing am I missing here?

    EDIT: I found that I can switch to scene UVs in the screenspace node and that allows me to travel without distortion, but now I have the problem of making sure that my texture coordinate tiles are always at the correct ratio.

    EDIT 2: With a little elbow grease and digging, I managed to figure it out! I have to set the texture tiling in a script, but other than that it's all good.

    Code (CSharp):
    1. Vector3 screenPos = Camera.main.WorldToViewportPoint(target.position);
    2. renderer.material.SetTextureScale ("_space", new Vector2(tiling, tiling*(Camera.main.pixelHeight/Camera.main.pixelWidth)));
    3. renderer.material.SetVector("_screenspaceTransform", new Vector4(screenPos.x, screenPos.y, 0, 0));
     
    Last edited: Nov 8, 2014
    IFL likes this.
  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Well, like I said in the description of the linked node documentation, you can determine whether or not it's a directional or point light - give it another read :)
    http://acegikmo.com/shaderforge/nodes/?search=LightPosition

    And yep, it's in world space!
     
  47. P1st3ll1

    P1st3ll1

    Joined:
    Dec 13, 2012
    Posts:
    69
    Hey guys !
    Does anyone know how to make a fur shader ?
     
  48. reptilebeats

    reptilebeats

    Joined:
    Apr 28, 2012
    Posts:
    272
    hey quick question guys, if i have nodes that arent used by anything do they still effect the shader cost. want to keep them in there for personal reference.
     
  49. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    They are unused, so you can keep them there :)
     
  50. reptilebeats

    reptilebeats

    Joined:
    Apr 28, 2012
    Posts:
    272
    nice