Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Strumpy Shader Editor [Now Open Source]

Discussion in 'Works In Progress' started by Tim-C, Aug 2, 2010.

  1. theinfomercial

    theinfomercial

    Joined:
    Sep 9, 2008
    Posts:
    1,000
    Excellent editor you have :D . But it does need some changes to be the best it can be.

    Some suggestions:
    -Thin Linear curves are ok, but thicker Bezier curves with ease in/out are better. Other than that, you have the look of the editor pretty much nailed. :)

    -I can't figure out a way to delete links between nodes on the fly (apart from the break buttons at the top). Clicking on a link between two nodes should destroy the link. Also, when you click on a node button and goto click on another node's button to link them, you should be able to click in empty space to destroy the link going from the button to the tip of your mouse. It would make the workflow better.

    -Texture nodes should have a preview of their assigned texture. Just so we can see what texture on the material the node is referencing from. But not necessary.

    -Texture nodes, when selected, should have rgba checkboxes that you can choose individually. That way you can output, for example, only the blue channel of a texture.

    The directory and saving system should also be more automatic. Right now, you have to save both the graph and shader files separately. This easily makes shader development much more tedious, as it's possible to save a shader, but overwrite the graph when you create a new graph and forget to save! Basically, you should be able to hit just "Save Shader" and it will save both the graph file and the shader file, since they are both used by the editor and you want to save both (just have them be named the same).

    Directory suggestions:
    -Load graph should start in the graph folder under Editor>ShaderEditor. Save shader should start in the Project>Assets folder instead of the Project folder.

    -The preview shader should be moved to the Editor>Shader Editor directory, rather than have it in a folder called "Data" that only gets used for one file.

    -Autosave file should be saved to the Editor>Shader Editor directory.

    -Graph files should be saved to a folder called "Graphs" under the Editor>Shader Editor directory.

    -Shaders should be saved to wherever you want in the Project>Assets folder.

    I'm sure there's more, but I can't think of anything.

    Anyway, your shader editor so far is really good! I for one am glad you made this. Major thanks!!! Keep up the great work. :D
     
  2. deis

    deis

    Joined:
    Sep 17, 2009
    Posts:
    29
    A simply amazing and awesome addon for Unity. Thankyou very very much. In moments I cooked up an amazing water shader I was looking for.

    I am really looking forward to future versions too.

    If you put up a paypal donate button, I will donate.
     
  3. theinfomercial

    theinfomercial

    Joined:
    Sep 9, 2008
    Posts:
    1,000
    Any chance we can see this wonderful water shader? :)
     
  4. tornadotwins

    tornadotwins

    Joined:
    May 21, 2008
    Posts:
    308
    @stramit Hey dude! Played around with your shader editor, perfect work mate!!
    'Been waiting far too long for this one, even though you coded it in a couple weeks ;-)

    I understand most of it, but I do think it might be a little hard to use for most of us. Perhaps, when you feel the project solidifies, we can help you by making a couple tutorials for it? This would give it some exposure beyond the forums also.

    DM or email me.

    Cheers!

    -TT
     
  5. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    224
    Really cool, it doesn't need too much more to be perfect. I'll second the suggestions above from theinfomercial. Also I couldn't find a 'lerp' function, but maybe it was named something else.

    I tried making some more complex shaders I've made before by hand and it was faster. The lack of lerp did hold me back a bit though. Thanks, and looking forward to further iterations.

    Edit: Just another thought that may be a bit more complicated than you had in mind, but the ability to create custom functions would be cool. Basically the ability to create a graph, save it as a function and then insert that new function in another graph with the ability to set any inputs that weren't assigned inside the function's graph and retrieve the outputs. Again, that might be asking too much, but for shaders involving lots of repetition it might clean things up and might make it faster to snap in common processes when creating new shaders.
     
  6. theinfomercial

    theinfomercial

    Joined:
    Sep 9, 2008
    Posts:
    1,000
    MattCarr, you mean something along the lines of "Use Pass" command that's in shaderlab? That would be great, but I don't think it would work well. If an entire shader graph were to be saved as one function, and that graph made use of not only albedo but other outputs as well, it would be hard to output to the master node or add onto the graph.

    Although, I might be talking out of my ass. :)

    I think a better approach would be to have simple "template" graphs that have basic functionality in them, such as bump diffuse or specular, and then just add on from there, reducing repetitiveness. I think that works better. :)
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Thank you for the feedback theinfomercial, there are some suggestions there that are very good, and I'll go about implementing the ones that i feel meet the design goals of the project as part of the UI work for beta2.

    I would love to see this water shader! Post an image in the thread of the result!

    :S I accidentally removed the lerp node from subversion when I was doing a cleanup, it will be back in very soon.

    I have plans for something like this. I'm trying to conceptually come up with the best way to implement it while still sticking to the principles of the initial design. I will have an api guide out sometime soonish about how to make new nodes that should fill the gap until that time.
     
  8. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Beta 1.1
    Just bug fixes and a few very minor features. Remember to check out Texel's documentation here.

    Release Notes
    - Stop null reference on preview mesh being set to null
    - Moved some nodes from functions -> operations.
    - Lerp node found in subversion and added.
    - Mask node fixed.
    - Float constant added.
    - Width of single column nodes increased.
    - Sampler2d default texture defualts to white.
    - Color input defaults to white.
    - Display name of input nodes is now the name of the configured input.
    - Tex2dNormal node added - automatically does an unpack normal.
    - SplatAlpha added - auto splat alpha channel.
     

    Attached Files:

  9. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    506
    Hi there,

    Will this be free or commercial?

    can we have some sample file where peoples have tested it?
     
  10. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    It includes a couple samples.
     
  11. Frido

    Frido

    Joined:
    Mar 27, 2009
    Posts:
    107
    Thanks! Without the knowledge of the shaderlanguage i'm able to create my own shaders!

    The thing i'm missing is a way to select the nodes and copy paste it in the graph.
     
  12. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Hi all,

    I come from a non-mathy background, and so this tool is amazing (as we've all been saying).
    So now it's time for some serious questions... I want to make a nice glass for curved objects. I need a refraction. Anyone know how I might go about that?
     
  13. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    224
    I didn't explain it very well, but I wasn't referring to saving an entire complete graph that includes a Master node as a function, but instead a set of functions or the like. For example the 'Tex2dNormal' node that stramit has added to the latest version could have been created as a custom function that used the Tex2D and UnpackNormal nodes. The custom function node would then have the inputs to Tex2D available and the output of UnpackNormal. Obviously more complicated functions with inputs and outputs from multiple nodes being exposed in the final node could be created too.

    Sounds good. I think what I'm trying to describe might fit in with the current style, but there would need to a separate type of graph without the Master node that can be created as a custom function.

    Oh, and it would be good to have an input for Vertex Normal as well :).
     
  14. Word

    Word

    Joined:
    Jan 23, 2010
    Posts:
    224
    can you add a glow feature please? :p
    (similar to the one in cinema 4d)
     
  15. tornadotwins

    tornadotwins

    Joined:
    May 21, 2008
    Posts:
    308
    I think glow is an image effect, which is a pro feature.
    Don't know if shaders can do that... but I might be wrong (hopefully!)
    -TT
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Its indeed a postfx that requires a render texture and render textures are pro only.

    up to a given degree it can be faked but it will cost a considerably amount of performance
     
  17. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,400
    Couldn't you use the destination alpha channel to draw glow values and then do a shader to blur it into a glow?
     
  18. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Nice !

    I built a shader in no time. Will you give access to vertex color ?

    Auto update would be awesome (not sure shader compile can happen in the background).
    Off course a few extra goodies like node search and contextual add would be top.

    By the way, it's better if you update a download link in the initial post - that way we don't have to hunt for your updates
     
  19. br0kenp0ly

    br0kenp0ly

    Joined:
    Jun 3, 2008
    Posts:
    469
    Really nice stuff so far man, even though I don`t know what 95% of those nodes do. I guess I`ll just have to play around with it and check out Texel`s documentation.

    What I would like to see in future versions is a checker background for the shader preview window. I don`t know if you`ve seen the 3dsmax material editor, but something similar to that would be really nifty.


    Keep up the excellent work!


    Roald
     
  20. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    That's very likely how the Pro-only glow effect already works, but as was already said "drawing glow values" depends upon render-to-texture.
     
  21. deis

    deis

    Joined:
    Sep 17, 2009
    Posts:
    29
    The water shader I made with this awesome tool. Please make sure to watch it at 720p and expanded, if not fullscreen. It is a little hard to see the subtle effects going on.

    http://www.youtube.com/watch?v=CvMDlFmFV3c
     
  22. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    224
    Vertex Color is already in the input section in the latest download on page 4.
     
  23. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    We should start a new thread just for an explanation of the nodes.
     
  24. Texel

    Texel

    Joined:
    Dec 25, 2009
    Posts:
    61
    No need, I've appended the Documentation to include a listing of the nodes, their functions, and when to use them.

    If anyone has anything else want to know how to do/would like to see added to the documentation, do not hesitate to ask. (Otherwise, I'll probably have another section on animating shaders either tonight or tomorrow)
     
  25. tornadotwins

    tornadotwins

    Joined:
    May 21, 2008
    Posts:
    308
    Super nice work dude!
    -TT
     
  26. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    506
    Hi there,
    I tried to use it, but getting errors

    is there any hardware requirement?
    It works with Unity Beta2? or need beta4

    thanks
    rahu
     
  27. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Well this is freaking fabulous. My coder friend is singing your praises too, as he no longer has to learn to code shaders.

    Would I be out of line making a couple of usability requests? These are not related to the graph itself, but more to the user-experience.
     
  28. Word

    Word

    Joined:
    Jan 23, 2010
    Posts:
    224
    The image effect applies for the whole scene, not just one particular mesh. i'm unable to figure out how to make something glow with these cylinders :p
     
  29. Filto

    Filto

    Joined:
    Mar 15, 2009
    Posts:
    697
    Wow this is just brilliant!! Just what Unity needed!,
    just a couple of questions,

    Can you add unityspecific arguments to the shaders like turning off so its not affected by fog, or having the shader be affected by the ambient light in unity and so on?

    Are there a downside in performance creating a shader with this tool rather than writing one by hand?
     
  30. GhostDog

    GhostDog

    Joined:
    Nov 11, 2009
    Posts:
    103
    Works like a champ. Much appreciated.
     
  31. Texel

    Texel

    Joined:
    Dec 25, 2009
    Posts:
    61
    I spent a while looking into this, and found that it is "Probably not"

    The editor always uses float4 internally, so for a float you have .xxxx, float2 you have .xyxy, etc. This creates such lovely gems as:
    Code (csharp):
    1. Tex2D(_Sampler2D0,(uv_Sampler2D0.xyxy).xy);
    Most of the time this works just fine, since the compiler will actually recognize when their would be either no chance for multiple components to have varied (Nesting swizzles are solved, unnecessary swizzles are dropped), the exceptions being functions where, while expecting a three component result, a four component result can give improper returns, such as Normalize, Distance, and Length, leading to an extra dimension being considered unless you use mask to remove the fourth value.

    So, for shaders that can be created with this tool (mind you, not all shaders can), it should be for all intents as purposes as efficient as creating it by hand.
     
  32. YeOldeSnake

    YeOldeSnake

    Joined:
    Aug 7, 2010
    Posts:
    29
    :eek: :eek: :eek: :eek: :eek:
    I cant wait to test this , too bad no unity 3 for me at the moment :(
     
  33. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    391
    Found a bug when you try to enter a capital "A" for a name for the shader it will not allow it.
     
  34. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    Could SSE be used to emulate photoshop's Overlay blending mode?
     
  35. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    SSE? you mean the cpu capability?

    Then no, shaders operate purely on the GPU, not the cpu and attempting to use the cpu to modify textures in realtime will always have the performance impact (-> close to unusable for realtime)

    But if you wanted to do so in Unity 3, then you would likely start by checking out if Mono.SIMD is present in U3
     
  36. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    My bad, I meant the Shader Editor. Building a graph/shader that emulates Overlay blending mode. Or is that what you mean? ..confused~
     
  37. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Ah to replicate it through a shader?

    Normally thats very well possible.
    In case of overlay though its harder.

    Reason is that the formula according to http://www.nathanm.com/photoshop-blending-math/
    its just

    (L < 128) ? (2 * B * L / 255):(255 - 2 * (255 - B) * (255 - L) / 255)

    where as 128 in our case would be 0.5 and 255 would be 1
    but the problem is that this is an IF statement, something the editor at least as far as I've seen does not support yet.

    Branching is something to always consider from case to case, because real SM2 only hardware and the first wave of SM3 cards did technically not have branching at all. What they did is just execute both sides of the "branch" and after reaching the end of the if - else block, decide which result they need and use that one (or in case of just an if, decide at the end of the block if the if ever happened and otherwise drop the result of the whole calc)
    here not much of a problem as its lightweight but when you more to much more complex shaders and once the editor has if blocks, it would become something to keep present in the back of your head or you could easily kill out lower end machines
     
  38. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    Great response. Thx for your insights.
     
  39. Texel

    Texel

    Joined:
    Dec 25, 2009
    Posts:
    61
    Overlay shader (Click to see graph):

    [​IMG]

    I must say, working out conditionals with nodes is rather cumbersome, and it took me a while to come up with that result.

    The overlay Dreamora cited isn't quite right, and is liable to produce discontinuities at the transition. After looking for a while, I adapted another implementation to:

    Code (csharp):
    1. // Calculate Luminance
    2. float lum = dot(base, lumCoeff);
    3. // Screen multiply lower values, screen the higher ones, cleanly blend
    4.  
    5. if (lum < 0.45)
    6.      return 2 * source * dest; // Mul x2 blend
    7.  
    8. if (lum > 0.55)
    9.      return 1 - 2 * (1 - source) * (1 - dest); // Screen blend
    10.  
    11. return
    12.      smoothstep(
    13.           2 * source * dest,
    14.           1 - 2 * (1 - source) * (1 - dest),
    15.           (lum - 0.45) * 10);
    16.  
    This is a bit trickier to use in a node based editor though, because you have to manually branch using step (Like I have in the Documentation, you can use step to emulate conditionals), so I ended up implementing the naive approach, which leads to some sharper discontinuities where luminance crosses the halfway-point, but it's more then sufficient to do some nice detail texturing. I wouldn't worry so much about the cost of the branching, at most your only going to be wasting a few fistfuls of instructions most of the time, it's not until you get to creating multi-shaders for draw-call reduction that branching becomes more of an issue.

    Would definitely appreciate having nodes for the advanced blends though, as conditionals make node-graphs easily massive, it could be done cleanly (And probably more efficiently) under the hood.
     
  40. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    I posted this in the other thread as well, but figured it would be worth while to have it here so each author and the users of each could reply in their own thread:

    Hi, figured I'd give my impressions of both of the node based shader editors that have been recently released.

    Things I like about Kurt's:
    • Storing node layout inside the shader.
      Right click to break links.
      Delete key to delete nodes.
      Middle mouse to pan around.
    Things I like about stramit's:
    • Categorization of node types makes it easier to find what you're looking for.
      Previews, although they could use some work.
      Error checking and coloring of nodes depending on status.
    Things I would like to see added to both:

    • Zooming in and out.
      Tooltips on hover, or small documentation window popup on select that gives quick description and input and output format.

    At the moment I've had a little more luck getting the results I want w/ Kurt's (mainly because I figured out how to swizzle in there), but small hand edits of ones generated w/ stramit's gave me the desired results as well.

    I haven't look at the code to see how easy it will be to add/extend node types in either yet, but I'll dive into that next.

    Anyways, great job to both of the authors, I really look forward to seeing what you guys come up with next.
     
  41. Texel

    Texel

    Joined:
    Dec 25, 2009
    Posts:
    61
    This one I actually really like and would love to see integrated into stramit's, the others are just usability.

    After talking with Stramit, it became evident that one of the core issues with surface shaders is that, because of the sheer number of permutations, it take Unity a fair bit of processing to compile a surface shader, hence why it's a button you have to press instead of passive and automatic. It may be feasible to write an older style fragment program setup to be able to generate quick previews, but it would end up being emulation and could lead to inconsistent results (aswell as not having the same information available as the surface shader).

    The preview itself is done with reflection, in addition to using DrawMesh, meaning it is the feature that makes stramit's editor Pro Only, unless Unity exposes the proper Editor calls, or at-least the ability to render an object outside of the scene.

    Removing the rotation sliders in favor of being able to grab the model wouldn't be too hard to add though, but I'm at a loss for how else it can be improved.

    At first I was thinking, "Zooming in and out would be incredibly nontrivial", then it occurred to me that it's just a matter of adjusting the GUI.Matrix, so it may end up being very straightforward to add.

    Tooltips, aswell as a rightclick menu for the nodelist (so it can be removed from the side of the screen) are both planned features which I'm verymuch looking forward to.
     
  42. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Since we're having a usability conversation... Would it be difficult to have your tool remember the last place I saved a shader or graph too? Because every time I press save, I have to re-navigate to the location I want to save it. And if I've done things that have spoilt my "Recent Locations" feature in windows... it slows things down a lot, that's all...

    Also, I understand it that Distortion effects (the kinds seen when you place a normal map in the FX/Glass shaders) is beyond this tool right now. Is that correct?
     
  43. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Hey everyone.

    Some great feedback and I am happy that you are making progress and enjoying the editor. I'll post some more detailed information on what I'll be changing / improving based on this feedback in a few days.

    I am a little afk at the moment, as I am on a snowboarding trip in NZ and internet access is a bit sketchy in the places I am staying.

    Keep posting feedback, it's all good :D
     
  44. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Can you post the errors and steps you used to install this as well as a save of the graph.
     
  45. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Texel covered most of this but the unity specific argument work will be part of beta 2 (fog / unity shader arguments ect). Beta 1 was (for the most part) just to get something solid out there so that people will start using it and gathering feedback. I want to make this tool as usable as possible.
     
  46. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    I could not repro this, could you attach a copy of the bad 'sgraph' file?
     
  47. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    1,939
    Yeah zooming is a nice idea... I'll have to add that to my list :p

    I'll address the other points later... time to go and have a drink while looking over the scenic mountains of NZ :D
     
  48. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    Texel, I put together the Overlay shader via your screenshot and added a Normal map option. It's great to have an overlay that I can independently offset, but I notice that it doesn't add contrast at the dark end of the spectrum, the results are milky - at least the results are quite different from the kind in Photoshop I'd like to emulate.
    But it's still great to have, thx for following it up.
     
  49. KITT

    KITT

    Joined:
    Jul 17, 2009
    Posts:
    221
    The South Island got some fresh powder with the recent cold snap. Where abouts are you snowboarding? Queenstown?

    Oh, and great work on the Shader Editor btw :)
     
  50. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    506
    will need more tutorials on it as it is quiet new method of shader making.
    Normal people who are not able to use programing will make simple shader easily but for complex shaders they will need more teaching.

    thanks in advance to all those who will provide learning material on this.

    however as a first request of tutorial, i need one for real time glass shader.

    thanks
    rahu