Search Unity

Strumpy Shader Editor [Now Open Source]

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

  1. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Hey Dude... am stil struggling to re-produce this shader... any chance you will be able to look at it soon? Anyone else wanna have a crack at getting it working?
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Don't worry, finally worked it out.... was way over complicating it all !!!!
     
  3. Arkdurath

    Arkdurath

    Joined:
    Jan 10, 2010
    Posts:
    64
    Hi all

    This shader editor is able to edit and output fixed pipleline shaders ? or only programable pipeline / surface-shaders instead ?

    Thanks for your help :)

    LLORENS
     
    Last edited: Nov 19, 2010
  4. Svyatoslav

    Svyatoslav

    Joined:
    Sep 28, 2010
    Posts:
    8
    Nice improvements in version 3 )))

    Something like adaptive snow.
    Two layers(object - diff spec normal emission refl; snow - diff spec normal refl sparkling) mixed through cubemap+detail mask with tweakable settings.
    Still don't know how to add object's normal map influence for snow mask

    $pic_Snow_Adaptive_extended.jpg
     
  5. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Does anyone know if there's a way to get nice shadows from a shader with cut out transparency ?



    I can't get it to work like the regular cut out shaders :\ Is there a setting I might be missing or do this just not work at the moment ?
     

    Attached Files:

  6. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Sorry for the double post.

    Small bug report!

    Sampler2D nodes don't save the "black - white - normal" setting to the .sgraph file. Every time you re-load the graph they all default back to white.

    Minor annoyance.
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    This is happening because SSE uses clip not the alpha test value in the shader. It's a known issue and I'll have to fix this. It would be nice if unity honored clip in their shadow shaders :(
     
  8. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Fixed this just then :D
     
  9. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Currently we only support surface shaders. In the future we will be adding support for fixed function fallback (for iphone / ipad / android). But the work has not been stared yet.
     
  10. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    In case anyone is curious I just got copy / paste working for nodes, and it will even work between graphs and sub graphs ;)
     
  11. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Good stuff.

    Shame about the Cutout shader shadows. Are there any work arounds? I hope you're able to solve the problem anyway :\.
     
  12. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    3.1 will fix this up. It's going really well (mostly just bug fixes and a few new nodes).

    I just put a fix in for performance, big graphs now work well and really fast. The preview refresh rate has also been upped to 66hz. Damn low level bug... But it's super responsive now! I really want to push this out as soon as possible so you can all experience the awesome.
     
  13. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Yes, let us know when you do, I'm interested in getting my hands on it and using in 3.1 :)
     
  14. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
  15. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
  16. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
  17. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Just remember to pass a valid texture in and not null. Passing in null makes the editor crash #hardlearnedlesson
     
  18. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Just finished off drag selection. This will make life a bit easier for everyone I wager!

    $dragselect.png
     
  19. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Now This is getting better and better, just need the abillity to Group Node and Zooming in/out *wishing :p
    awesome work guys....
     
  20. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    Haha yeah you were like 10 minutes to late, I learned it the hard way :)

    I got em working fully now, thanks a lot =)

    Btw, could you maybe post a few words on your performance update, what made it lag and how did you fix it?
    (Just so I stay out of that trap myself).
     
  21. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Both planned for sometime in the future. They won't be in 3.1 though (I really want zoom more then anything actually).
     
  22. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    are there any plans to release a non-pro version in the future?
     
  23. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it is a non pro tool :)

    that render textures (-> preview) require pro is a restriction no addon developer can overcome ...
     
  24. ArmedBee

    ArmedBee

    Joined:
    Nov 22, 2010
    Posts:
    17
    Hello,
    I am trying to make some basic surface shader using AWESOME Strumpy Shader Editor.
    Looks like I managed to make texture based specular :) Right now I am stuck with making specular power, which I wanted to make adjusting texture brightness and contrast.
    Here is what I came up with


    Wanted to rule RGBA information by camp arguments, not working.
    What could be a correct node to drive it?
    Is it possible to create some combination of nodes acting as brightness and contrast adjustments in Photoshop for example?
     
  25. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    It's definitely possible.

    For contast you could have a value come in (called, say, con), and for brightness (bri), both with default of zero, then do:

    (originalValue)*(con + 1) - (con*0.5) + bri

    and then put that though Saturate.

    Also, and I'm not sure about this, but you might want to try plugging it into Gloss as well/instead of Specular.
     
  26. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    You should put what you have in spec now into gloss instead, Unity have switched the two, so if you're used to 3dsMax then spec=gloss and gloss=spec, confusing i know. You should then just put a range from 0 to 1 into spec to control the glossiness.
     
  27. ArmedBee

    ArmedBee

    Joined:
    Nov 22, 2010
    Posts:
    17
    @Zomby138: Thank you a lot! You make a good push in the right direction! Well I used your advice and get a bit more options, like increasing the blue channel of the normalmap to make a power control for it.

    @Westmark: Got the key difference and some range controller for specular power.

    Well I wasted about a day looking for a good working shader for Unity 3.x which use diffuse, normalmap, specular and has controllers to tweak them in real-time. After that I discovered this fantastic editor! So I would like to share the shader and sgraph here if it possible.

    Feel free to download and improve Sgraph
    And the resulting shader
    Code (csharp):
    1. Shader "BasicSurface"
    2. {
    3.     Properties
    4.     {
    5. _Diffuse("_Diffuse", 2D) = "white" {}
    6. _NormalMap("_NormalMap", 2D) = "white" {}
    7. _Normalpower("_Normalpower", Float) = 0
    8. _Glossiness("_Glossiness", Range(0,0.1) ) = 0
    9. _SpecularMap("_SpecularMap", 2D) = "white" {}
    10. _SpecularPower("_SpecularPower", Range(-0.5,0.5) ) = 0
    11.  
    12.     }
    13.    
    14.     SubShader
    15.     {
    16.         Tags
    17.         {
    18. "Queue"="Geometry+0"
    19. "IgnoreProjector"="False"
    20. "RenderType"="Opaque"
    21.  
    22.         }
    23.  
    24.        
    25. Cull Back
    26. ZWrite On
    27. ZTest LEqual
    28.  
    29.  
    30.         CGPROGRAM
    31. #pragma surface surf BlinnPhongEditor  vertex:vert
    32. #pragma target 3.0
    33.  
    34.  
    35. sampler2D _Diffuse;
    36. sampler2D _NormalMap;
    37. float _Normalpower;
    38. float _Glossiness;
    39. sampler2D _SpecularMap;
    40. float _SpecularPower;
    41.  
    42.             struct EditorSurfaceOutput {
    43.                 half3 Albedo;
    44.                 half3 Normal;
    45.                 half3 Emission;
    46.                 half3 Gloss;
    47.                 half Specular;
    48.                 half Alpha;
    49.             };
    50.            
    51.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    52.             {
    53. half3 spec = light.a * s.Gloss;
    54. half4 c;
    55. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    56. c.a = s.Alpha + Luminance(spec);
    57. return c;
    58.  
    59.             }
    60.  
    61.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    62.             {
    63.                 viewDir = normalize(viewDir);
    64.                 half3 h = normalize (lightDir + viewDir);
    65.                
    66.                 half diff = max (0, dot (s.Normal, lightDir));
    67.                
    68.                 float nh = max (0, dot (s.Normal, h));
    69.                 float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;
    70.                
    71.                 half4 res;
    72.                 res.rgb = _LightColor0.rgb * (diff * atten * 2.0);
    73.                 res.w = spec * Luminance (_LightColor0.rgb);
    74.  
    75.                 return LightingBlinnPhongEditor_PrePass( s, res );
    76.             }
    77.            
    78.             struct Input {
    79.                 float2 uv_Diffuse;
    80. float2 uv_NormalMap;
    81. float2 uv_SpecularMap;
    82.  
    83.             };
    84.  
    85.  
    86.             void vert (inout appdata_full v, out Input o) {
    87. float4 Vertex_VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
    88. float4 Vertex_VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
    89. float4 Vertex_VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
    90. float4 Vertex_VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
    91.  
    92.  
    93.             }
    94.            
    95.  
    96.             void surf (Input IN, inout EditorSurfaceOutput o) {
    97.                 o.Albedo = 0.0;
    98.                 o.Normal = float3(0.0,0.0,1.0);
    99.                 o.Emission = 0.0;
    100.                 o.Gloss = 0.0;
    101.                 o.Specular = 0.0;
    102.                 o.Alpha = 1.0;
    103. float4 Pixel_Tex2D1=tex2D(_Diffuse,(IN.uv_Diffuse.xyxy).xy);
    104. float4 Pixel_Tex2D0=tex2D(_NormalMap,(IN.uv_NormalMap.xyxy).xy);
    105. float4 Pixel_UnpackNormal0=UnpackNormal(Pixel_Tex2D0);
    106. float4 Pixel_Mask0=float4(0.0,0.0,Pixel_UnpackNormal0.z,0.0);
    107. float4 Pixel_Add2=Pixel_Mask0 + float4(_Normalpower);
    108. float4 Pixel_Assemble0=float4(Pixel_UnpackNormal0.x, Pixel_UnpackNormal0.y, Pixel_Add2.z, Pixel_UnpackNormal0.w);
    109. float4 Pixel_Tex2D2=tex2D(_SpecularMap,(IN.uv_SpecularMap.xyxy).xy);
    110. float4 Pixel_Add0=_SpecularPower.xxxx + float4( 1);
    111. float4 Pixel_Multiply0=Pixel_Tex2D2 * Pixel_Add0;
    112. float4 Pixel_Multiply1_0_NoInput = float4(0,0,0,0);
    113. float4 Pixel_Multiply1=Pixel_Multiply1_0_NoInput * float4( 0.5);
    114. float4 Pixel_Subtract0=Pixel_Multiply0 - Pixel_Multiply1;
    115. float4 Pixel_Add1=Pixel_Subtract0 + _SpecularPower.xxxx;
    116. float4 Pixel_Saturate0=saturate(Pixel_Add1);
    117. float4 Pixel_Master0_2_NoInput = float4(0,0,0,0);
    118. float4 Pixel_Master0_5_NoInput = float4(1,1,1,1);
    119. float4 Pixel_Master0_6_NoInput = float4(1,1,1,1);
    120. o.Albedo = Pixel_Tex2D1;
    121. o.Normal = Pixel_Assemble0;
    122. o.Specular = _Glossiness.xxxx;
    123. o.Gloss = Pixel_Saturate0;
    124. o.Alpha = 1.0;
    125.  
    126.             }
    127.         ENDCG
    128.     }
    129.     Fallback "Diffuse"
    130. }
    And some picture of what I have got
     
    Last edited: Nov 22, 2010
  28. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    I would still put a range into spec to control the softness of the highlights (glossiness), but cool shader :D
     
  29. ArmedBee

    ArmedBee

    Joined:
    Nov 22, 2010
    Posts:
    17
    @Westmark: I hope I got you right. Added the slider for Glossiness in shader code of previous post ;)
     
  30. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @ArmedBee: It looks like it :) Unity can be really confusing that way :p
     
  31. Nick3d

    Nick3d

    Joined:
    Jan 28, 2010
    Posts:
    100
    This is really awesome...I'm starting to work with it and its quite amazing...

    Now a very important question:

    Is there any way to add/integrate/whatever a shader that is capable of display normal map on surfaces that are not affected by direct light?

    I'm talking about radiosity normal map ( see Valve Source engine ).

    Its Beast dependant or it can be achieved by shading?

    I'm quite bored to add lights all over the scene to see normal maps everywhere....
     
  32. martinszeme

    martinszeme

    Joined:
    Nov 21, 2010
    Posts:
    2
    Sorry if this seams a silly question, but how do you get a texture in one of those nodes? I presume its 2DTexture node, but there is no browse or open button/dialogbox. Also, how do people use this editor in a free version of Unity? Do you apply it to a sphere and look at it in game? What's the easiest way approaching it?
     
  33. Dan Fury

    Dan Fury

    Joined:
    Jul 18, 2010
    Posts:
    158
    I have the feeling a lot of people are trying to do Android,/iOS shaders with this awesome tool.
    I'm one of them and I haven't build my own shaders before, but I absolutely love it.
    I did the earth tutorial and it looks great on my mobile, but since I don't know what isn't working, I need some hints.

    The two obvious bugs I have are that the shader doen't wrap around the sphere correctly, but is ok on PC, I probably need to map it differently.
    The second bug I have is that it looks like the cloud layer get's scaled down on the Y-axis every time the model is loaded. I attached the planet to the Google Logo per AR and everytime I loose track, the model looks slightly different.
    I uploaded the apk file here, if somebody wants to try it out, it only reacts to the Google Logo.
    http://www.file-upload.net/download-2993703/Earth.apk.html
    And here's the earth.shader , I hope this helps, if you need other data please let me know.
    http://www.file-upload.net/download-2993735/Earth.shader.html
     
    Last edited: Nov 22, 2010
  34. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    This is a great tool, I've been messing with it but I'm not quite used to having that SimpleLighting view, can anyone give me pointers about how to communicate between that and the pixel shader graph view? I see that I can use inputs from the Light menu while in SimpleLighting, but what if I want to use information on how the surface is being lit by lights...it seems I'd need that in the pixel shader graph view, an example is having a light affect the alpha of an object, so instead of lighting it, it just makes the lit parts fade out, and the unlit parts remain visible.
     
  35. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    For normal maps to be 'valid' in unity 3d they need a light / light direction. This is because normal maps modify the surface normal and hence the result of the lighting equation. In techniques like RNM they 'bake' the static lighting information into a surface (with directional information).

    Out of the box I don't believe unity supports any type of directional lightmapping (RNM is one such technique). Geenz has been working on an RNM for Unity you might want to have a talk to him about this.

    If you could generate a RNM then the shader editor could be used to sample and calculate what should be done and how it should be applied to the scene.
     
  36. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    The easiest way is to:
    -Set up a simple scene (sphere ect)
    -Export the shader you want to test from the shader editor
    -Apply the shader / material to the object in the world (the material properties will have all the texture2d / input parameters listed like any unity material)
    -Keep modifying the shader
    -Click export again (every time you export the shader it will recompile it / reapply it to the object in your scene)
     
  37. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi Dan Fury. I don't own an android / android licence so I can't really help you much. Something you might like to try is using the meshuv node for the material UV instead of the material UV that comes by default from the sampler2d. Unity might be doing something odd with the UV's and the best way to be safe is with the mesh UV. It seems like an odd issue. A shader is a shader, all the scaling information ect is just passed in via unity. Is it possible that this data is wrong?
     
  38. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Simple lighting is the custom lighting model for the deferred path of the renderer. Because of this you don't get any access to things like light direction of individual light color. All you get is a compound light color that is the sum of all lights effecting that pixel. An advanced lighting mode will be coming sometime in the future, this will force the forward rendering path but allow for much more detailed lighting calculation.

    Think of the lighting pass happening after the pixel pass. Many of the outputs you calculate there are used as inputs to the lighting graph. For a reference implementation of the default lighting that is used by SSE see the defaultlighting.sgraph file. It should help a little bit and I'll try and answer any questions you have.
     
  39. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Found a nasty bug. I'm working with some normal maps, lerping between a map and an empty one, relying on the default "normal" color given. The bug is that the compilation or saving or something often seems to forget the "normal" color as the default value for a texture sampler. So I have to often reset it twice and then reupdate :(

    And it seems like after a while I have to reload the shader because SSE "forgets" it.

    Also, I'm having some pretty weird normal problems with my custom shader based on the Rim lighting one. Using a color that's 127,127,255 for the normal doesn't seem to work...but shouldn't it?
     
  40. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Both these bugs have already been fixed in the internal version and will be making their way into the next release.

    Are you putting this color directly into the Normal channel of the master node? If so the value needs to be (0,0,1) as the normal is represented in tangent space, and as a float between (0-1). If you mean the normal you are entering into another node let me know which node type and I'll be able to help. (Posting a pic of the problem portion of the graph can help a great amount as well!)
     
  41. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Just implemented undo and redo into the graph ;) This release is shaping up to be bigger then I originally anticipated...
     
  42. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks for the feedback. I guess I thought the "flat" value was 0.5, 0.5, 1 (given 0-1 range)? Otherwise why do tangent space normal maps use 127,127,255?

    Man, can't wait for the next release!
     
    Last edited: Nov 23, 2010
  43. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Flat normal is (0.5, 0.5, 1) before unpack normals, and (0, 0, 1) after unpack normals.

    (0, 0, 1) is what you want to feed into the normal channel to get flat.
     
  44. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Gotcha, so 0,0,1 is after the scale/bias based on a range of -1 to 1 right?
     
  45. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @god at play: yes :) but you just multiply by 2 and then subtract 1 to unpack normals :)
     
  46. pluhn

    pluhn

    Joined:
    Jul 27, 2010
    Posts:
    42
    Would anybody be willing to lend me a hand on how to create a particular shader? I'm by no means a programmer and therefore have trouble wrapping my head around the concept of shaders... I'm working on a golf game for the iPhone and what I need is a shader I can use on my putting grid. I'd like it to blend between two colors along the world y-axis, so that the lower areas are one color while the higher areas blend into a different color. Can anyone tell me how to get started on this with Strumpy?
     
  47. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
    Sorry is this has been touched on but I think this is a bug, whenever I make a shader, even something as simple as a diffuse only shader, it compiles into a 5000 line shader with tons of garbage.

    Is this a bug or am I doing something wrong, or is there a workaround?
     
  48. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    A literal 5000 lines of literal garbage ASCII, or are you using hyperbole?

    Can you paste the actual result in here using
    Code (csharp):
    1.  tags?
     
  49. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Can you please post the sgraph file? It is hard to tell if I don't know what the graph looks like.
     
  50. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Maybe you are looking at the compiled shader code not the actual .shader file ?

    compiled shader code ~3k lines, .shader file ~150 lines

    On another topic:
    Can anybody point out a way to do a switch with the provided nodes ?
    Like I want the user to be able to select between x or y and depending on that choice, change the output of my shader? ( specifically, I was trying to switch between an effect on the x axis or on the y axis )