Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Strumpy Shader Editor [Now Open Source]

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

  1. MarkPixel

    MarkPixel

    Joined:
    Apr 15, 2010
    Posts:
    39
    Thank you very much!!
     
  2. Drol-Anurav

    Drol-Anurav

    Joined:
    Nov 16, 2010
    Posts:
    14
    hi there, strumpy

    first of all, I have to say, that you did great work with your editor. For me, as an Artist, writing shaders is more likely a process of trial-and-error. With your editor you gave Artists the power to do something, they could only do with additional knowledge of a programmer. So thanks for that. Also thanks to Texel for all the work he put into the documentation.

    My question is: how could I achieve effects that are postrendered, like an outline or a glow effect ?
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi Duke,

    I don't have much time to explain how the whole interface thing works for the shader editor. But this is the source code for the parallax node. You could base any custom node you want to write on this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using System.Runtime.Serialization;
    5.  
    6. namespace StrumpyShaderEditor
    7. {
    8.     [DataContract(Namespace = "http://strumpy.net/ShaderEditor/")]
    9.     [NodeMetaData("Parallax", "Function", typeof(ParallaxNode),"Context menu description.")]
    10.     public class ParallaxNode : Node, IResultCacheNode {
    11.         private const string NodeName = "ParallaxOffset";
    12.        
    13.         [DataMember] private Float4OutputChannel _result;
    14.         [DataMember] private Float4InputChannel _view;
    15.         [DataMember] private Float4InputChannel _scale;
    16.         [DataMember] private Float4InputChannel _bias;
    17.        
    18.         public ParallaxNode()
    19.         {
    20.             Initialize();
    21.         }
    22.        
    23.         public override sealed void Initialize ()
    24.         {
    25.             _result = _result ?? new Float4OutputChannel( 0, "Result" );
    26.             _result.DisplayName = "Result";
    27.             _view = _view ?? new Float4InputChannel( 0, "View", Vector4.zero );
    28.             _view.DisplayName = "View";
    29.             _scale = _scale ?? new Float4InputChannel( 1, "Height", Vector4.zero );
    30.             _scale.DisplayName = "Height";
    31.             _bias = _bias ?? new Float4InputChannel( 2, "Bias", Vector4.zero );
    32.             _bias.DisplayName = "Bias";
    33.         }
    34.        
    35.         public override IEnumerable<OutputChannel> GetOutputChannels()
    36.         {
    37.             return new List<OutputChannel> {_result};
    38.         }
    39.        
    40.         public override IEnumerable<InputChannel> GetInputChannels()
    41.         {
    42.             return new List<InputChannel> {_view, _scale, _bias};
    43.         }
    44.        
    45.         public string GetAdditionalFields()
    46.         {
    47.             var arg1 = _view.ChannelInput( this );
    48.             var arg2 = _scale.ChannelInput( this );
    49.             var arg3 = _bias.ChannelInput( this );
    50.             var ret = arg1.AdditionalFields;
    51.             ret += arg2.AdditionalFields;
    52.             ret += arg3.AdditionalFields;
    53.             return ret;
    54.         }
    55.        
    56.         public string GetUsage()
    57.         {
    58.             var arg1 = _view.ChannelInput( this );
    59.             var arg2 = _scale.ChannelInput( this );
    60.             var arg3 = _bias.ChannelInput( this );
    61.            
    62.             var result = "float4 ";
    63.             result += UniqueNodeIdentifier;
    64.             result += "=";
    65.             result += " ParallaxOffset( " + arg3.QueryResult + ".x, " + arg2.QueryResult + ".x, " + arg1.QueryResult + ".xyz).xyxy";
    66.             result += ";\n";
    67.             return result;
    68.         }
    69.        
    70.         public override string NodeTypeName
    71.         {
    72.             get{ return NodeName; }
    73.         }
    74.        
    75.         public override string GetExpression( uint channelId )
    76.         {
    77.             AssertOutputChannelExists( channelId );
    78.             return UniqueNodeIdentifier;
    79.         }
    80.     }
    81. }
    82.  
    You probably won't be able to write a whole function here (there is a function node planned for beta 3.1 or beta 4 where you can write custom code). But if you can fit it in one line you can implement it in the GetUsage function.
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Not with this editor. It's only for surface shaders. Maybe in the future though ;)
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    I just had a look at the boot camp demo. they have a completely custom shader that does not support lighting. The grab pass looks like it should only be used in the transparent queue for rendering distortion objects. It's quite limited for surface shaders :(
     
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Clamps threw together a depthbiased alpha graph here: http://forum.unity3d.com/threads/56...hting-support)?p=429384&viewfull=1#post429384

    With regard to performance, I am aware of the issues and am really trying to do something about it but I'm running into some severe limitations in unity. The GUI framework in unity is not the fastest piece of code i've ever worked with.
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Yep, set up texture panners like in the UVPan example that comes with the ShaderEditor. After this is done add them up using the add node, or use the lerp node to blend between them.
     
  8. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    In 3.1 the nodes will be named a bit better to make it clear. To break it down you basically have these inputs:
    Code (csharp):
    1.  
    2.             struct EditorSurfaceOutput {
    3.                 half3 Albedo;
    4.                 half3 Normal;
    5.                 half3 Emission;
    6.                 half3 Gloss;
    7.                 half Specular;
    8.                 half Alpha;
    9.             };
    10.  
    As well as the light color. You use these inputs to describe how the surface is illuminated. When I can get around to it I will write a tutorial.
     
  9. designamyte

    designamyte

    Joined:
    Nov 16, 2010
    Posts:
    1
    Im new in the Un.Com.,

    i want to say many thanks for this great Shader-Editor.
    Playing a lil bit around with it. And it seems not to be
    very comlicated. (cause im from the design area, not a coder)

    I remember in older posts that you -@stramit- also have had in mind to
    build a visual logic system. I know, there are to people working on it.
    But it seems that you have to purchase for their stuff.

    Maybe you can also keep on working on your idea of an vis. logical
    system. Maybe only basic nodes, such as mous-aktions and keyboard
    actions, or so. And it could also be free, like ur exsisting shader-editor.
    Maybe....(it´s only a question)

    many thx greetings
    designamyte
     
  10. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Hey stramit, thanks for your answer... but i mean a double sided shader with two different textures, like a blue outside and a red inside :)
     
  11. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Did you use the possibility to offset the shader in his group through +1 / -1 etc to make the "grab pass thats behind" happen first? (unsure if this is fully possible in Unity, but technically its a matter of making such stuff happening in the right order)
     
  13. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Yeah but the problem is that it's the same object so same grabpass.
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    splitting the objects that use the distinct grab passes then would help.
    perhaps there are other options, depends a lot on what you want to achieve in detail.

    but 2 grabpasses also means 2 materials and shaders or 2 distinct passes.
    in both cases you have control over the order in which they happen and are technically able to get the second one to have the data from the "thing behind"
     
  15. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Yeah i thought abt that :) it would work, but i have another idea i wanna try out first as it would cost much less and look cool i hope :p
     
  16. malyna

    malyna

    Joined:
    Jul 9, 2010
    Posts:
    105
    hei guys.
    Shader editor: Amazing !
    I have to say that iam a shader noob, are ther any tutorials which explains the basics of making shader in strumpy shader editor ? without the one in the first post ? If not is there anybody who can make some ?
    Or should I read normal shader tutorials ?
    cya
     
  17. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Damn T_T....isn't there any other way to have a correct grab pass.
    btw do you know how to get refraction mask like in this one http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter19.html
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the grab pass can technically be rendered whenever you want but doing so prior to the transparent queue doesn't make any sense as it will lack foliage etc on terrain then among many other things.

    Also, that shadows don't work on such surfaces is rather common, you won't find many engines that offer shadow drop onto water for example, especially none that don't cost your soul or corresponding amounts in $$$ ;)

    As for the refraction mask: could be a bit tricky but technically you could potentially use a second camera to render such a mask texture through rendertexture to then use in your real shader for example.
     
  19. osmant

    osmant

    Joined:
    Apr 16, 2010
    Posts:
    39
    Hi,

    Thank you for this wonderful extension, it has made my life a little easier :)

    I have a question, i'm sorry if this has been explained already; in the new 3.0 beta, anything I plug into alpha does not work. In the previous beta, it did. Is this a bug, or did the workings of the alpha input changed? Thanks in advance and keep up the great work.
     
  20. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Ah it changed a little bit. Alpha is used for glow as well as transparency in unity. What you want to do is click on the master node and turn transparency to 'On'. It defaults to false on new / 2.2 graphs that are imported.
     
  21. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    The problem with this is that when you do it you are doing 'hand coded' sorting. This is okay if you can guarente that something will ALWAYS be drawn behind something else. But for many / most situations this is not the case. Some examples of where it might be applicable are water, when things in the water will always be drawn BEFORE the water surface (provided you are not in the water volume looking up). It's a painful situation and unity does not seem to sort non transparent queues.
     
    Last edited: Nov 16, 2010
  22. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Such situations are where usage of scripting to dynamically adjust the queue trigger in to keep it alive.
    Its not that common to have combined grab passes as most people prefer to have realtime FPS :)
     
  23. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    I can just imagine how slow that would be to execute... so many ray casts and bounds checks... or a quadtree or volume structure. Blegh.
     
  24. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    agreed.
    Though such complicated environments don't exist. At least not if you had the target of gaming or realtime as that will never work without raytracers, having multiple dependent refractive transparent surfaces and alike.

    as long as it remains in realistic borders there is an alternative way that potentially works: use distinct cameras that you restrict near - far wise to the distance of the refractive transparent surface and let them render to render texture and then create shaders that build upon these data + what they see on their camera. This could potentially work
     
  25. loken

    loken

    Joined:
    Mar 25, 2009
    Posts:
    109
    Stramit, I asked this question some pages ago. It's fairly simple, and if you have time to answer, this shader noob would greatly appreciate it.

    I've been trying to setup my own skybox shader that blends between 2 cube maps. The shader works fine on a mesh but does not work as a skybox material. Any hints?



    I know this could easily be done in Shaderlab but I'm just trying to learn your awesome tool. =)
     
  26. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    I'll have a look tonight for you Loken. So you are talking about when you actually hook it up into skybox (i.e the camera skybox or the scene skybox. Not just a box you have in the scene?)
     
  27. loken

    loken

    Joined:
    Mar 25, 2009
    Posts:
    109
    Yeah, I'm using the Camera Skybox rendering component.

    Thanks for the quick reply!
     
  28. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi loken. Skyboxes are a special case and they do some interesting stuff in the back end. Because of the way they are done they are not supported in the current release, but I have made changes in the code base which will fix them up for 3.1. Thanks for pointing this out to me.

    In 3.1 this is how you would do a skybox shader. Note you still use the UV not the normal. This is because unity passes the correct vertex skybox normals via the UV channels.

     
  29. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    If I have missed any questions that have been asked over the past few days I am sorry. Post them again now and I will see what I can do.
     
  30. loken

    loken

    Joined:
    Mar 25, 2009
    Posts:
    109
    I had a feeling they were a special case.

    Thanks again, really appreciate it!
     
  31. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Stramit I sent you a PM with 2 nodes.
     
  32. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    hmm...i guess you guys right about this.. even in the newest COD series they still had false refraction for they're water shader.
     
  33. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    $Clip_8.jpg
    Well with grab pass limitation, this is as far as i get then...
     
  34. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    If you look at games like bioshock rea they manage to do this type of refraction. The trick seems to be to use a very small distortion offset in the shader so that it minimizes the foreground objects leaking into the distortion (Have a look at the windows in that game looking out into the water) and it might give you some ideas.
     
  35. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    hmm....i think you're right....somehow i remember reading their water tech somewhere.....
    well i'll see what i can do...
     
  36. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    The limitation is gotten around by various things. I'll copy this verbatim from a Crytek prentation called "Crysis Next Gen Effects" by Tiago Sousa:

    - Use current back-buffer
    - Mask out everything above water surface
    - Water Depth > World Depth = leaking - disallow refraction texture offset for this case

    http://crytek.com/cryengine/presentations/crysis-next-gen-effects
     
  37. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    You might be able to do that in unity actually. Batch the distortion pass into transparent (even if you have zwrite on / no transparency). Grab the current pixel z depth and compare to the one from the depth buffer.

    Anyways here is an example of a distortion effect. What you need to do is have offsets centered around 0. So an offset ranges from -1 -> 1. If you want to get fancy normalize to grab texture dimensions ect, but I am not doing that here. The normalization means that the foreground objects will not leak very much, just a small frill around the edges.

    Note the inclusion of the unpack normal to convert into [-1, 1], this means you need an offset texture encoded this way (for my testing I just used a normal map I had handy)


    Here is an extreme example (I would never use this much in a real game). Notice the foreground cube is preserved, but there is some leakage into whatever is in the background.


    Here is a more realistic example (looks good in motion as well), some small frills.
     
  38. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Ah cool. I'll I'll check them out and if they work well I'll put them in 3.1 if that's okay with you.
     
  39. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Yep that was the idea!
     
  40. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    hey Stramit i sent you a PM, can you check it?
     
  41. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    I purchased Unity Indie (2 licenses) and iPhone Basic (1 license) in the 2.x days, and have since updated to 3.1. There is no preview window when I load SSE. Do I seriously have to have Pro/Advanced just to get a preview of the shader I am working on? This tool, while useful, is seriously handicapped (from the artist's perspective) without a dynamic preview of the shader you are building.
     
  42. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    realtime preview just requires RTs not much to do there and nobody aside of UT can do anything about it.

    Only pseudo realtime one could be made available in free unity (through readpixels and transfering it)
     
  43. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Hi folks.
    Here's the tutorial I promised a couple of days ago. Sorry for the delay, it's been really hectic around here. If there's any issues or problems with this tute, please PM me and I'll fix them.
     

    Attached Files:

  44. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Yep you need unity pro for these features. It's not that I don't want preview in the indie version it's just that because it uses render textures and a few other things (graphics.draw ect) that are pro only I can't support the preview on Unity free. If unity ever removes any of these limitations I'll definitely change it.
     
  45. loken

    loken

    Joined:
    Mar 25, 2009
    Posts:
    109
    Clamps, the tutorial is very cool, but I kind of feel like I wish you had described why you're using certain nodes to do this and that, rather than just instructing how to wire them up. Kudos though - still learned a lot, and I'll have to pour over it again. And again.
     
  46. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Loken, It's interesting you should say that. I had a version of the tute with more explanation, but it was thought to be too "Casual". I can post that up too if you like.
     
  47. osmant

    osmant

    Joined:
    Apr 16, 2010
    Posts:
    39
    Hey there :)

    I've got another question: when I create very basic shader that uses one texture and I input that into the albedo, it works fine in SM3.0 mode, but in SM2.0 mode it ignores the ambient light, it looks full bright-ish. Is there anything I need to know about this? Thanks in advance :)
     
  48. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    $Clip_9.jpg
    @stramit : I guess you were right, using low value of distortion is good enough. And you almost can't notice the false refraction. i guess i can use this for now...
     
  49. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    yes please share more tuts, bro!
     
  50. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    That's really cool! I bet it looks really ace in motion!