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. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    I've used Unreal to make really good real-time glass shaders, and I feel that this tool will allow us to do the same thing in Unity. Mostly I copied the work of my betters. :oops:

    Here's a couple of methods that work well in Unreal. Using (roughly) the same process might work in this tool.
    http://www.polycount.com/forum/showthread.php?t=61089
    http://www.game-artist.net/forums/support-tech-discussion/4334-unrealed-4-glass-material-2.html

    I second the call for a few tutorials (Glass!). And maybe a repository for shaders, so we can share good results?
     
  2. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Will this tool work for iPhone/iPad as well?
     
  3. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    Anyone know some tutorials that explain shader node graphs, and the like?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Within constraints cause surface shaders might generally not optimal for mobiles.

    but it gives you a base to build upon for example
     
  5. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    Sorry for the noob question but is there a way to access different UV channels in an object? ie. create a shader that controls textures in the second UV channel separately from the first?
     
  6. box01

    box01

    Joined:
    Apr 2, 2009
    Posts:
    62
    Same question. Any way to include node for choosing which uv channel will be loaded?

    Thanks.
     
  7. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    I am not sure you understood what I meant, but when I try to input a name for the shader, before I can even make one, I press shift and hit "a" and cannot make a capital "A" in the input field for the name. So saving a bad sgraph file wouldn't work since I cannot create it in the first place, you need to make a name to make a shader graph.
     
  8. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537

    Sure i can post the graph.
    However now i am not getting the errors, but not getting result as i expect.
    I tried a ref for glass material in unreal.
     

    Attached Files:

  9. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    first of all great work !

    is it possible already to make different scene blend shaders ? for example i want a really simple scrolling additive shader ( basically just what your tutorial does ... except with additive-transparency)
     
  10. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Well there are quite a few things wrong with the graph. Many of the nodes do not have inputs. This will mean that they don't know what they have to lerp of select. Have a look at the example shaders, and the documentation to get a better idea of how to set up graphs.
     
  11. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537

    I tried some tutorials from net for UDk and also tried documents and now in better position to work with shader editor.
    I am getting this error when using world reflection and normal bump.

    If you have any suggestion or other way to work on it please help.
     

    Attached Files:

  12. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    From the shader lab docs
    Currently the shader editor supports either the reflection vector or the normal, not both which is why you are seeing that error. This is one of the tasks that is yet to be done (as I am still trying to find a nice way to do it code wise).
     
  13. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Hello,
    well amazing great helpful Tool you made !!!
    I want to make a shader for underwater fog.
    I have a Underwater Game and really need Fog also on iPad.
    So i need a Shader in GLSL for OpenGL ES 2.0.
    I have no idea how to start with... so maybe someone can show me how ?
    thank you
    :oops: kerstin
     
  14. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Can't see an answer to this anywhere... Was this commented on?
     
  15. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    No it wasn't, so far as I can see there currently isn't a way to access uv's in this shader editor, but there are nodes in this: http://forum.unity3d.com/viewtopic.php?t=60611 that allow for uv channel separation. It's a bit different to use vs this one (I personally prefer this shader editor), but it does the trick.
     
  16. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    By the way, Unity only allows for access of up to two UV channels, so if you've got more than two channels on one GameObject, you're a bit stuffed and will probably have to do a bit of texture-mapping.
     
  17. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Ah sorry. I have implemented this feature. It will be in the next release. I'm adding a large number of features that have been requested, and I'm going to drop them all in one release and not in small increments. I hope to have Beta2 out quite soon.
     
  18. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    Awesome! Thanks Stramit
     
  19. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Yes, many thanks Stramit. Looking forward to getting my hands on the latest version.

    Best Regards,
    Matt.
     
  20. QFS

    QFS

    Joined:
    Jan 22, 2009
    Posts:
    302
    One thing that would make this really great is if the textures RGBA channels were accessible separately.

    So for example, that you could use the diffuse alpha to hold a specular map, and the normal map's alpha to hold a height map, etc.
     
  21. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    thats already possible.

    You can extract the channels from RGBA as you need them :)

    the splat node you see on the first postings image does exactly that :)
     
  22. QFS

    QFS

    Joined:
    Jan 22, 2009
    Posts:
    302
    Thanks, you made my day :wink:
     
  23. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    I was totally beaten ;)
     
  24. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Stramit,

    Very very cool system! The previewer is great and I'm glad you made it so I have all the options that are available such as "black", "white" and "normal" on the Sampler2D nodes!

    I can't wait to see your next Beta release!!!
    Nathan

    edit: it's spelled such, not suck, haha :)
     
  25. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Thank you for the kind words.

    I'm still looking for feedback on anything that needs to be added or is missing that is not part of the product roadmap. If anyone has any feedback let it fly!
     
  26. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    At some future point, node groups would be great.

    To explain the idea (I guess there are dozens of names of it): A way to store a group of nodes with input and output as a blackbox within other shaders.
    upon doubleclick, we could "zoom into them"


    This is likely not that trivial because it means that there would need to be output nodes, there would need to be a different editor mode than the one now and naturally the editor would need a dedicated folder where such blackbox nodes would be stored.
     
  27. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    ZooKeeper (a plugin for Max) has these and calls them Composite nodes. They're basically just containers with ins and outs (that you can specify) that you can open independently.

    http://www.cgtraining.com/Videos/ZKCompMM3/ZKCompMM3.html
     
  28. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    How do I go about setting tiling/offset in the samplers?

    edit: nevermind, the documents say it all! It may make sense to roll this functionality into the Sampler2D node as you'd want these options more often than not!

    PS. I'm following this wonderful tutorial for UDK:
    http://book.hourences.com/tutorialsue3water.htm
     
  29. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    You can do tiling / offset in the graph itself by modifying the UV from the sampler2d node. Adding the unity tiling / offset is a bit more difficult (not the code, but doing it so that it does not break the paradigm of the editor). You don't ever specify the tiling and offset on a shader, you do it on the material. The best place to add this would be on the preview, not the input. It's a decent idea, and probably worth adding.

    I noticed that the tutorial used depth biased alpha... that is not currently in the editor, but is coming soon! So when you get that far don't stress out.
     
  30. jeffreyianwilson

    jeffreyianwilson

    Joined:
    Apr 19, 2009
    Posts:
    58
    First off, I'd like to compliment the editor itself. Not coming from a scripting background I can definitely appreciate a new tool.

    That being said....

    I created a simple shader I've noticed that the glow image effect no longer works properly...

    Also, I wrote a simple script that links a light's color to the emissive value of the material...

    what could possibly be wrong with this script?
    Code (csharp):
    1.  
    2. var cubeMaterial : Material;
    3.  
    4. function Update () {
    5. light.color = cubeMaterial.GetColor("_Color1");
    6. }
    Here's the custom shader that was generated:


    Code (csharp):
    1.  
    2. Shader "SelfIlluminated_Diffuse"
    3. {
    4.     Properties
    5.     {
    6. _Color("_Color", Color) = (1,1,1,0)
    7. _MainTex("_MainTex", 2D) = "white" {}
    8. _Color1("_Color1", Color) = (0,0,0,0)
    9.  
    10.     }
    11.    
    12.     SubShader
    13.     {
    14.         Tags
    15.         {
    16. "RenderType"="Opaque"
    17.  
    18.         }
    19.        
    20.         CGPROGRAM
    21.             #pragma surface surf BlinnPhongEditor
    22.            
    23.             struct EditorSurfaceOutput {
    24.                 half3 Albedo;
    25.                 half3 Normal;
    26.                 half3 Emission;
    27.                 half3 Gloss;
    28.                 half Specular;
    29.                 half Alpha;
    30.             };
    31.            
    32.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    33.             {
    34.                 #ifndef USING_DIRECTIONAL_LIGHT
    35.                 lightDir = normalize(lightDir);
    36.                 #endif
    37.                 viewDir = normalize(viewDir);
    38.                 half3 h = normalize (lightDir + viewDir);
    39.                
    40.                 half diff = max (0, dot (s.Normal, lightDir));
    41.                
    42.                 float nh = max (0, dot (s.Normal, h));
    43.                 float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;
    44.                
    45.                 half4 c;
    46.                 c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
    47.                 c.a = s.Alpha + _LightColor0.a * Luminance(spec) * atten;
    48.                 return c;
    49.             }
    50.            
    51.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    52.             {
    53.                 half3 spec = light.a * s.Gloss;
    54.                
    55.                 half4 c;
    56.                 c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    57.                 c.a = s.Alpha + Luminance(spec);
    58.                 return c;
    59.             }
    60.            
    61.             struct Input {
    62. float2 uv_MainTex;
    63.  
    64.             };
    65.            
    66. float4 _Color;
    67. sampler2D _MainTex;
    68. float4 _Color1;
    69.  
    70.             void surf (Input IN, inout EditorSurfaceOutput o) {
    71.                 o.Albedo = 0.0;
    72.                 o.Normal = float3(0.0,0.0,1.0);
    73.                 o.Emission = 0.0;
    74.                 o.Gloss = 0.0;
    75.                 o.Specular = 0.0;
    76.                 o.Alpha = 1.0;
    77. float4 Tex2D0=tex2D(_MainTex,(IN.uv_MainTex.xyxy).xy);
    78. float4 Multiply0=_Color * Tex2D0;
    79. float4 Master0_Normal_NoInput = float4(0,0,1,1);
    80. float4 Master0_Specular_NoInput = float4(0,0,0,0);
    81. float4 Master0_Gloss_NoInput = float4(0,0,0,0);
    82. float4 Master0_Alpha_NoInput = float4(0,0,0,0);
    83. o.Albedo = Multiply0;
    84. o.Normal = float3( 0.0, 0.0, 1.0);
    85. o.Emission = _Color1;
    86. o.Alpha = 1.0;
    87.  
    88.             }
    89.         ENDCG
    90.     }
    91.     Fallback "Diffuse"
    92. }
    93.  

    The code I wrote to update the light color is correct and works when set to "_Color" but NOT "_Color1"... The script also works with the default shaders so I know it must be a problem in the shader I created.

    Thanks ahead of time...

    Jeff
     
  31. Tim-C

    Tim-C

    Unity Technologies

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

    The glow issue is caused by there being no way to (currently) scale the amount of glow per object. The unity shaders do this by scaling the 'glow' by the specular value. This needs to be hooked into the lighting calculation at this stage:

    Code (csharp):
    1.  
    2. c.a = s.Alpha + Luminance(spec) * magical_glow_scale;
    3.  
    I will work on adding an extra channel for glow to the surface structure. It will be a little different to the unity way of configuring glow, but it should be much more configurable and you will be able to use glow textures (single channel).

    I PM'd you a version of the script (in c#) that works for me, but you mentioned in a PM that you are using the script in conjunction with the animation editor. If you send me a copy of the package that is not working for you I can have a look at the animation curve you have set up. But this is not a shader editor issue (I'm still very happy to help though).
     
  32. jeffreyianwilson

    jeffreyianwilson

    Joined:
    Apr 19, 2009
    Posts:
    58
    I'm under NDA as far as the project so I can't send you any of the scene but I can setup a similar scene which uses the same principal elements...

    Jeff

    BTW...... Thanks!
     
  33. dabitbol

    dabitbol

    Joined:
    Aug 25, 2010
    Posts:
    1
    I think this node based system could be a lot more powerful if it was made to work with all objects as well as shaders. Sort of a MotionBuilder like relation constraint.
     
  34. nasser

    nasser

    Joined:
    Aug 25, 2010
    Posts:
    2
    Hi all,

    This is an awesome looking shader editor for Unity and I can't wait to give it a go, but I get a stream "RenderTexture.Create failed" errors whenever the node editor window is visible, and the preview area remains black.




    The complete message is as follows:
    Code (csharp):
    1. RenderTexture.Create failed
    2. UnityEngine.Camera:Render()
    3. StrumpyShaderEditor.PreviewRenderer:Render(Mesh, Vector3, Quaternion, Camera, IEnumerable`1, Color, Material, RenderTexture)
    4. StrumpyShaderEditor.PreviewNode:RenderPreview()
    5. StrumpyShaderEditor.NodeEditor:Update(EditorWindow)
    6. ShaderEditorWindow:Update() (at Assets/Editor/ShaderEditor/ShaderEditorWindow.cs:22)
    7. UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
    8.  
    I suspect it has something to do with the camera rendering the preview and the texture it is rendering to, but without access to the code or much experience in this area, I can't say for sure. I searched, but couldn't find anyone else with a similar problem.

    I am running Unity 3.0.0b6 (48675) on a MacBook Pro running OSX 10.6.3.

    Thanks in advance for such a useful tool!
     
  35. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi nasser.

    I have never seen that issue and no one has reported it as bug so far (and there have been quite a few people using this editor now). The one thing that I could think it might be is that your computer does not support render textures, as beta 1 does not guard strongly against this support not being present.

    Could you create a c# script in the Editor directory called 'SupportWindow' and in it place this code:

    Code (csharp):
    1.  
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. public class SupportWindow : EditorWindow {
    6.    
    7.     [MenuItem("Window/Graphics Info")]
    8.     public static void Init ()
    9.     {
    10.         GetWindow (typeof(SupportWindow));
    11.     }
    12.    
    13.     public void OnGUI()
    14.     {
    15.         GUILayout.Label( "graphicsDeviceID: " + SystemInfo.graphicsDeviceID );
    16.         GUILayout.Label( "graphicsDeviceName: " + SystemInfo.graphicsDeviceName );
    17.         GUILayout.Label( "graphicsDeviceVendor: " + SystemInfo.graphicsDeviceVendor );
    18.         GUILayout.Label( "graphicsDeviceVendorID: " + SystemInfo.graphicsDeviceVendorID );
    19.         GUILayout.Label( "graphicsMemorySize: " + SystemInfo.graphicsMemorySize );
    20.         GUILayout.Label( "graphicsShaderLevel: " + SystemInfo.graphicsShaderLevel );
    21.         GUILayout.Label( "operatingSystem: " + SystemInfo.operatingSystem );
    22.         GUILayout.Label( "processorCount: " + SystemInfo.processorCount );
    23.         GUILayout.Label( "processorType: " + SystemInfo.processorType );
    24.         GUILayout.Label( "supportsImageEffects: " + SystemInfo.supportsImageEffects );
    25.         GUILayout.Label( "supportsRenderTextures: " + SystemInfo.supportsRenderTextures );
    26.         GUILayout.Label( "\t ARGB32: " + SystemInfo.SupportsRenderTextureFormat( RenderTextureFormat.ARGB32 ) );
    27.         GUILayout.Label( "\t Depth: " + SystemInfo.SupportsRenderTextureFormat( RenderTextureFormat.Depth ) );
    28.         GUILayout.Label( "\t ARGBHalf: " + SystemInfo.SupportsRenderTextureFormat( RenderTextureFormat.ARGBHalf ) );
    29.         GUILayout.Label( "supportsShadows: " + SystemInfo.supportsShadows );
    30.         GUILayout.Label( "supportsVertexPrograms: " + SystemInfo.supportsVertexPrograms );
    31.         GUILayout.Label( "systemMemorySize: " + SystemInfo.systemMemorySize );
    32.     }
    33. }
    34.  
    In the unity window menu there will now be a new option called "Graphics Info". Open that window (make sure to expand it so all the info is shown), and then take a screen shot of what is there. This is what mine looks like for example:


    I pretty much need to know the in depth details of your computer. It also might be some obscure driver issue... It should not be happening, and I don't see how it could be caused by the editor. (It might be some other underlying unity issue?)
     
  36. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Also it might be possible that you set your target platform to one that does not support render textures. Could you check this in your configuration?
     
  37. nasser

    nasser

    Joined:
    Aug 25, 2010
    Posts:
    2
    stramit,

    Thanks for your quick reply! I was working on an iPad game when the errors came up, and they're gone in the PC game I'm working on. It was the platform targeting. Maybe there could be a check for that? Just so that the errors don't flood the console.

    I can't wait to finally dig into this! Thanks again for being so helpful!
     
  38. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    No worries nasser. I (maybe naively) assumed that in editor mode, and in a custom window, that the editor override settings would be ignored. I might flag a support ticket to unity to somehow add an override for when in a custom editor context (although it maybe to hard for them to remedy simply).

    Beta 2 has an added guard against this. If render textures are not supported it will not try and draw the preview.

    Here is a screenshot of how beta two is shaping up, the GUI work is pretty much complete (aside from the odd bug), and the feature list is looking very solid! There are only a few more things I want to get done before I let it out. Some cool things in this picture are the front end GUI rework (mostly handled by the illustrious Texel) this includes a drag to rotate preview, a right click context menu to place nodes, bezier curves and a whole host of other minor improvements.

    The back end has also had a massive rework. The node architecture has been paired down into simple interfaces and is much cleaner and easier to use. You can now include multiple input nodes with the same name (so long as there type is the same) and the editor will only add one to the shader. This means that you can make cleaner graphs by duplicating input nodes. I'll keep the other features a bit secret for the next few days, don't want to give too much away ;)

    Note that the node selection pane is a right click pop up menu... lots more screen real estate now! Non pro skin... I still don't know which I prefer!
     
  39. Anim

    Anim

    Joined:
    Aug 11, 2008
    Posts:
    289
    All I can say is wow! This looks amazing.
     
  40. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Brilliant stramit, just brilliant.

    Regards,
    Matt.
     
  41. thomasmahler

    thomasmahler

    Joined:
    Mar 18, 2009
    Posts:
    181
    I WANT SO BADLY.

    Unity Team, give this man a candy!
     
  42. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    Very nice to see the clipping values available now :) culling here we come! I assume it has to do with depth values?

    *edit: or can have something to do with depth mapping?
     
  43. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Looking very nice stramit, can't wait to play with the next build of it :)
     
  44. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Thanks for the kind words everyone, and everyone that gave feedback, you get a second thanks. It's coming together quite well and I am very happy with the results.

    Clip allows you to stop the rendering of a pixel (similar to alpha test), but on any arbitrary value. If the value input into the clip is < 0 then the pixel will be clipped! It's much more powerful then a simple alpha-test and internally the alpha tests are normally implemented using the same hardware instructions. If you want to have a look at a better example have a look at the 'Slices via World Space Position' shader example in the unity 3.0 documentation, it comes with the 3.0 install.

    With regards to the depth... Beta 2.0 exposes access to the depth buffer so you can do things like depth biased alpha, and a host of other things that requires depth buffer access.
     
  45. FatiguedArtist

    FatiguedArtist

    Joined:
    Mar 3, 2010
    Posts:
    38
    Sweet. Sounds good, cheers :)
     
  46. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey, I want to start using this, but it looks very... complicated...any tutorials for it?

    EDIT: does this work for Unity iPhone?
     
  47. thomasmahler

    thomasmahler

    Joined:
    Mar 18, 2009
    Posts:
    181
    jrricky: Node-based applications by nature look pretty complicated by just looking at the node trees - it's only after you understand that it's just simple networks connected together that it'll all make sense to you.

    It's as simple as 1+1=2.
     
  48. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    So you are saying just jump in blindly and I will get it? All I want to see is if I could make a nice self illumination and alpha shader atm, and some other things down the road.
     
  49. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi jrricky. There are not any tutorials currently, but the user documentation (linked to in the first post of this thread) gives a run down on some shaders and using the editor itself.

    You should currently be able to make a nice self illumination shader (using the emission channel), and do alpha blending using the alpha channel.

    I am not currently super familiar with the iPhone shader support stuff because I only just purchased iPhone basic (I have spent all my yearly software budget on unity already :( ). But I intend to do a full iPhone / iPad support pass for beta 3. Until then I am not sure how well the material editor will support iDevices.
     
  50. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Cool! I'll give a read. Thanks! I'm not looking to do crazy stuff with the shaders. I'm still planning on using the Unity defaults, it just didnt have self illumination/alpha channels one which I would like. So I hope that works for the iPhone atleast...