Search Unity

Strumpy Shader Editor [Now Open Source]

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

  1. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Just had a quick look at your shader, I think there is a better way to do it:
    $Screen shot 2011-01-26 at 11.51.11 AM.png
    $Screen shot 2011-01-26 at 11.48.09 AM.png

    Apart from that I can not explain what you are seeing with the odd sorting, the shader set up looks correct, and the shader I used has correct sorting. Can I ask what version of the editor you are using? There was a bug in 3.2 that was fixed in 3.2a that might explain what you are seeing. If you could pm me the sgraph and compiled shader I could have a look at those, it might allow me to help diagnose the problem. Apart from the odd colors the picture you posted looks correct to me, the fox should be behind the bamboo in the foreground, and in front of the bamboo in the background. Is the bamboo using the same shader as the fox? I need a bit more info to help you out properly.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    [edit]
     
  4. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Interesting tutorial on vertex shaders...so I am thinking with it, i can do bulging muscles and deforming stuff like skin...can't wait until you show some more stuff :)
     
  5. entropy

    entropy

    Joined:
    Jan 26, 2011
    Posts:
    3
    Hey,

    how i can modify the RimLighting shader with UnlitAlpha or SelfIlluminated Diffuse?



    btw. sorry for my bad english ;-)
    thanks!
     
  6. jeremy

    jeremy

    Joined:
    Dec 16, 2010
    Posts:
    2
    thanks for this awesome tool stramit...

    i've been digging through these 46 pages of posts trying to find more information on a 'light vector' expression.
    There were some posts saying that it wouldn't work with the unity render pipeline, but 'simple lighting' materials could be used instead.
    is this correct? is there no strumpy equivalent to an unreal-style light vector expression?
     
  7. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    Could someone post an example of how the SimpleLighting graph can be used?
     
  8. metareact

    metareact

    Joined:
    Jan 23, 2011
    Posts:
    3
    My attempt at rgbe HDR reflection:

    Need help with reflection fresnel (see graph file in attachment)
     

    Attached Files:

    Last edited: Jan 26, 2011
  9. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Currently the custom lighting only supports the prepass pipeline. When rendering with prepass you get access to an accumulated light color per pixel, but don't have any information as to which direction the light came from. This is why the light direction is not exposed. The plan is to eventually support custom lighting in the forward pipeline as well. This will allow the light vector to be available in the shader, but you will need to disable the prepass for it to work nicely.
     
  10. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'll be writing a tutorial on this over the next week.
     
  11. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    Good to know, thanks. Incidentally, did you get my PM?
     
  12. Loa

    Loa

    Joined:
    Jan 27, 2011
    Posts:
    5
    Hello,

    Thanks for all this great job and posts.

    I'm looking to learn shader way with your editor as main tool and as a first step I'm looking to adapt this shader into a Graph.

    WindowShader

    May , please, ask you a sample graph for it ?
    In order to help me to start on a concrete exemple by example.

    Any other advise on additional reading in order for a 'noob' like me in shader programmingto be able to use correctly the Editor will be very appreciated :)

    Thanks a lot,
    Loa
     
  13. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    When i add the texture node circle red, my shader changes to pink color, which means error.
    check the attached image and shader graph.
     

    Attached Files:

  14. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    You have most likely gone over the number of texture interpolators, I can't really catch this error in the editor nicely. Turn the shader into shader model 3, or instead of using standard texture nodes use a texture node and a meshUV for the uv channel, that will reduce the number of interpolators.
     
  15. entropy

    entropy

    Joined:
    Jan 26, 2011
    Posts:
    3
    same problem here ;/
     
  16. Alec-Slayden

    Alec-Slayden

    Joined:
    Dec 16, 2008
    Posts:
    101
    I have transparency issues as well, specifically when involving native unity transparent shaders. I have a ring going through a sphere. The ring is unity's transparent / diffuse, and the sphere is strumpy rimlighting with transparency and transparency queue active. No further adjustments or complexity to the scene.

    There isn't intersection behavior for the strumpy shader, causing it to always appear in front or behind the ring, depending on camera angle.
    In fact, the ring will still be drawn over the sphere when moved behind it, until it reaches a certain distance, whereupon the sphere is properly drawn first.


    Despite the problems I'm having, I think this is a great and powerful asset, and I look forward to future updates. Thank you so much for your hard work and contribution to fellow developers!
     
    Last edited: Jan 29, 2011
  17. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    i am trying to FADEOUT my fresnel rim lighting in the distance ( because it becomes really aliasy/artifact-riden far away ! )

    isnt there an input node that returns 0 for a pixel that is as close to the camera and 1 for something that is 1 unit into the screen and so on ?! basically oldschool gl-fog !

    i could make that work as a mask i am sure ! but what is that node called "screendepth" and "screendepthdiff" both seam to not do that !


    actualy now that i upgraded to 3.2b screendepthdiff seams to do the trick but it says its a pro only feature/deffered rendering ?! whats up with that ? isnt old school gl fog like the cheapest effect ever ?
     
    Last edited: Jan 30, 2011
  18. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Are you on version 3.2b? Can you send me a copy of the sgraph / shader (om in a zip). It's hard to know exactly what is wrong if I don't have access to screenshots and data to work with.
     
  19. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I really want to fix this issue or at least tell you guys how to work around it. If you could repro it in a simple scene and zip it up for me that would be great.
     
  20. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Hey stramit, quick question...do you know that fake refraction shader that you posted way back when, will that work on Unity 3 Indie? And also, is there a nice elegant way to set up a shader that will allow me to do stuff like "damage on a fighter model as he gets progressively damaged"? with bruises and cuts...

    thanks man...
     
  21. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    For the damage on a fighter thing I'd go with two textures, a clean one and a damage one. Then an alpha mask with various alpha values painted on it. You increase a value that you pass to the shader based on damage and it paints portions of the damaged texture by comparing the passed value to the alpha of the mask, if the alpha is lower than the damage value, paint the damaged texture, if higher paint the clean texture.
     
  22. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    But it has to be procedural...i don;t want the damage to look the same every time...
     
  23. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yeah, I would do it in a similar way. Have two 'sections' in your shader, one would be the normal undamaged fighter. The other is a damage section that has an alpha value that is used for the blending.

    In the shader have a slider that determines how much of the damage section gets blended with the non damage section (do manual one pass alpha blending).

    Neptune_Imaging: You will need pro to do nice refraction as it requires a captured screen buffer / render to texture.
     
  24. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    This is much more difficult. One way would be to use a technique called world space mapping. You use the world space (or some random object seed, which you would need to pass into the shader) to control a texture offset (you could use two textures and blend them somehow to get an even more random effect). This would mean that so long as your objects have different offsets the damage would be in different locations. The issue would be that if they are UV unwrapped objects you might get some odd seams.
     
  25. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Yes that is the rub: the model is uv mapped... so I would have to create three more texture channels for levels of damage...would a lerp node help? I am also looking at my graph to check the ALU count and it says N/A...what is up with that...? I would have to see your slider setup for texture switching... I've been using Float values since the slider bar is very touchy
     
  26. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    If you have just loaded the editor you will need to click update. The ALU count is pulled after an update.
     
  27. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Cool... my NI Shader is ALU: 54 TEX: 7... (sounds bad and I don't know what an ALU is). And this setup is just for fighting game models with three levels of damage (will create a simple version of this shader for other game types)... so I could use a split node and a LERP node to plug in three other textures... weird that is says 7 for textures but there are only six inputs for textures... and with this damage model set up... i would have about 24-26 textures for each fighter

    EDIT: I could also have the material as an instance :)
     
  28. BloodRiot

    BloodRiot

    Joined:
    Dec 29, 2010
    Posts:
    11
    Hi all.

    This editor really rocks for me since it's not very different from what i have in Maya.

    I do have one question though. I've been trying to get a transparent shader that doesn't affect the oppacity of the specular highlight. I read somewhere that you could link the specular highlight output into the alpha input, but i haven't figured out how to do it.

    I want something like a fully transparent shader that shows the specular highlight fully opaque.

    thanks.
     
  29. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I have a shader that I believe does exactly that... I am not in front of Unity, but you would have to set the shader to transparent and plug in these nodes:

    A colour (RGBA) into the albedo node: Set it to black for better results
    Copy the colour node twice you can set this to whatever colour you want.
    Create two multiply nodes and plug the result into the Gloss and Specular.
    Now plug the colour nodes into Arg 1 of each multiply node.
    Create two float nodes and plug them into the Arg2.

    If u want to use textures instead, you could plug a Texture2D and a sampler2D into the Albedo (your texture needs an alpha), the specular, and the gloss. I am using this set up for my eyes on my model

    hope this helps :)
     
  30. BloodRiot

    BloodRiot

    Joined:
    Dec 29, 2010
    Posts:
    11
    I thank you for the assist, but unfortunatly as i make the object transparent, the specular highlight still fades out by the same ammount :S

    really stumped on this one.
     
  31. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    make sure to set the float on the spec and gloss to 1... and name ur nodes
     
  32. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    can u do a screenshot of your sgraph?
     
  33. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    Yes, A scene graph would be good.
     
  34. BloodRiot

    BloodRiot

    Joined:
    Dec 29, 2010
    Posts:
    11
    I got it to work with additive blending and your sugestion(black for best results and all.

    This does seem to fix the specular highlight going transaprent with the rest of the object.
     
  35. Karthi

    Karthi

    Joined:
    Jan 20, 2011
    Posts:
    3
    Hi everyone,

    Let someone explain me how to extend a laser ray till my target . In such a way the ray should not exceed the target . Also i have used the javascript given below hence i got a "line" till my target where i cannot add a material to it .. So kindly give a javascript which should replace drawline with gameobject . (How should I replace a drawline with gameobject to add material using javascript)

    var playerPosition: Transform;
    var subjectPosition: Transform;
    var hit: RaycastHit;

    function Update () {


    if(Physics.Linecast(playerPosition.position, subjectPosition.position, hit))
    {
    if(subjectPosition.collider == hit.collider)


    Debug.DrawLine(playerPosition.position, subjectPosition.position, Color.cyan);

    else

    Debug.DrawLine(playerPosition.position, subjectPosition.position, Color.cyan);

    }
    }


    Thanks in advance :)
     
    Last edited: Jan 31, 2011
  36. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    You should make a separate thread for this question, not hijack this one.
     
  37. windexglow

    windexglow

    Joined:
    Jun 18, 2010
    Posts:
    378
    How do I use the parallax node? I've searched yet can't find any examples of it.
     
  38. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'll do a simple parallax map example tonight for you :D
     
  39. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'll do a simple parallax map example tonight for you :D
     
  40. Loa

    Loa

    Joined:
    Jan 27, 2011
    Posts:
    5
    Hello,

    May be a starter question but, please, how do you manage to get the dynamic rendering working ?

    I can use it with unity preview but i would like to use the dynamic view.

    You build a web version of Strumpy ?

    I'm on Windows 7 64 bits.

    Cheers,
    Loa
     
    Last edited: Feb 2, 2011
  41. Loa

    Loa

    Joined:
    Jan 27, 2011
    Posts:
    5
    I warning I get here when updating a shader :

    There are inconsistent line endings in the 'Assets/StrumpyShaderEditor/Editor/Resources/Internal/Temp/TempShader.shader' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Unitron and other text editors can fix this using Convert Line Endings menu commands.
    UnityEditor.AssetDatabase:ImportAsset(String, ImportAssetOptions)
    StrumpyShaderEditor.NodeEditor:Update(EditorWindow)
    NodeEditorWindow:Update() (at Assets/StrumpyShaderEditor/Editor/Scripts/NodeEditorWindow.cs:24)
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    When I hit Update Sahder nothing happens in the shader viewed by unity (TempShader) even if it's updated.

    If I export as all is ok.

    If after I export the 'Export As' shader is updated but not the temp one.
     
    Last edited: Feb 2, 2011
  42. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I would ignore this...this always appears with my scene, but nothing is wrong... :)
     
  43. windexglow

    windexglow

    Joined:
    Jun 18, 2010
    Posts:
    378
    If you create a repeatable crash - is the only way reinstalling?
    (attaching a tex2d.a to parallax.bias / height or Infinite loops)
     
  44. jcdied4me

    jcdied4me

    Joined:
    Dec 21, 2010
    Posts:
    5
    The spec and gloss don't seem producing the expected visual results. What are the values expected for the Spec and Gloss inputs? Perhaps I am not supplying the correct values that are expected by the editor.

    The spec should be the intensity of the highlight and the gloss should control the spread of the highlight. Currently this is not the case. I have been unable to verify proper functionality on any type of object due to sporadic or random results. I tried both float values as well as using images in both inputs but still no good results.

    The standard math used to control these inputs should be: ((Spec value ^(pow) Gloss value) * (Light vector ·(dot) Surface Normal)) + albedo. This is how it's done in UDK and it gives off some amazing results. Also, every white paper on the subject shows a similar if not identical equation for calculating the spec and gloss. Please look into this. I believe this will be the definitive jump in shader quality from this editor. The use of spec and gloss together allows for an infinite amount of different realistic surfaces property replications. What sets pro games apart from Indy IMHO.

    BTW: The editor is awesome! Thanks!
     
  45. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I've fixed this issue in the next release, just waiting on some things to coalesce. If you delete the autosave.sgraph it will fix be usable again.
     
  46. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I know what you mean, and I can explain the reasons why SSE does what it does. This is a legacy issue mostly to do with how SSE needs to interface with the unity rendering system. If you look at the default unity lighting:

    Code (csharp):
    1.  
    2. inline half4 LightingBlinnPhong (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    3. {
    4.     half3 h = normalize (lightDir + viewDir);
    5.    
    6.     half diff = max (0, dot (s.Normal, lightDir));
    7.    
    8.     float nh = max (0, dot (s.Normal, h));
    9.     float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    10.    
    11.     half4 c;
    12.     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
    13.     c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
    14.     return c;
    15. }
    16.  
    They actually do it a bit differently, they raise the half vector to the power of specular, then multiply by gloss. Diffuse is still handled 'properly'. The default lighting in SSE is written to match the unity system even though the normal dot half scaler is normally raised to a 'hardness (gloss)' factor then multiplied by the specular color. It has actually been an interesting point of debate between myself and texel as to if we should move towards the 'standard' equation to make it clear to new people to the editor or stick with the unity convention. This is also confounded a tad because SSE allows for a specular color to be set, and this is passed in as s.Gloss (default unity has this as a single half, then adds spec color by another means). That being said when looking through this code for you I did find a minor bug that might cause some issues, but only on forward lighting. Deferred would have been okay. The full SSE lighting system looks like this, where the Prepass function can be programmed in the 'simple lighting' graph, advanced lighting WILL be coming (forward pass lighting), :

    Code (csharp):
    1.  
    2.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    3.             {
    4.                 half3 spec = light.a * s.Gloss;
    5.                 half4 c;
    6.                 c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    7.                 c.a = s.Alpha + Luminance(spec);
    8.                 return c;
    9.             }
    10.  
    11.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    12.             {
    13.                 viewDir = normalize(viewDir);
    14.                 half3 h = normalize (lightDir + viewDir);
    15.                
    16.                 half diff = max (0, dot (s.Normal, lightDir));
    17.                
    18.                 float nh = max (0, dot (s.Normal, h));
    19.                 float spec = pow (nh, s.Specular*128.0);
    20.                
    21.                 half4 res;
    22.                 res.rgb = _LightColor0.rgb * diff * atten * 2.0;
    23.                 res.w = spec * Luminance (_LightColor0.rgb);
    24.  
    25.                 return LightingBlinnPhongEditor_PrePass( s, res );
    26.             }
    27.  
     
    Last edited: Feb 2, 2011
  47. windexglow

    windexglow

    Joined:
    Jun 18, 2010
    Posts:
    378
    Did you ever do this? I'm closer to than I was last night, but right now I'm taking random stabs at it.

    edit: Got a lucky stab.
     
    Last edited: Feb 2, 2011
  48. jcdied4me

    jcdied4me

    Joined:
    Dec 21, 2010
    Posts:
    5
    Thank you very much, stramit. I appreciate your time. I would suggest moving to a standard approach as the current legacy approach doesn't make visual sense. It would seem that the gloss factor doesn't really do much of what it is supposed to do and therefore limits the quality of the visual output and also limits the creative limits of the artist. So regardless of how it is handles, if it is non-standard... it's just not right :D. I feel, at the minimum, there should be a flag in the SSE that allows the user to select which functionality is to be used. Or perhaps put a custom lighting input that allows the user to create their own algorithm for handling light on an object much like UDK has.

    I have great respect for what you guys are doing so please don't take this as a demand, I am merely making a suggestion. However, I do feel this is probably the most important foundational feature yet to be implemented properly. Please add this functionality :D. I, and many others, would be forever grateful (even if one is unaware of its power yet).
     
  49. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    i am 100% with jcdied4me i was also really confused about the interplay between the gloss and the specular inputs.it was not what i am used to at all and had a really hard time figuring out vales that looked semi decent )

    first thing that struck me as odd is that if either value ( spec or gloss) approaches 1 its gets totally blown out and becomes useless.

    as far as i am concerned (artists speaking here) the gloss value should determine the SIZE/blurryness of the specular highlight while the spec value controls the color/opacity of it !

    but to me it almost looks like they both do the same thing if i give them values at around


    0.1 (gloss) 0.0001 (spec)

    it looks practically identical to

    0.1(spec) 0.0001 (gloss )

    no matter what values i fed it i could never give it a small but strong specular highlight that you would want on something wet or rubber / plastic etc !
     
  50. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I usually end up overdriving my values to get them looking right...