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
    Thanks for telling me of the issue. I'll fix it up for 3.1 I'm glad you like the editor!
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I sent you a pm duke. If I could get a copy of this shader that is broken (the .sgraph) file, or steps to repo it I will be able to put a real fix in for you.
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    No Problems dude. Whenever you have time :)
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Duke sent me a PM about this, I'll post the reply here for anyone that runs into similar issues. The breakdown is that by using the world reflection node the vertex interpolator count was exceeded. Here is the explanation:

    --------

    So in shader land you can have a certain number of varying outputs from the vertex shader into the pixel shader. In shader model 2 this is 8 (+2 color interpolators), SM3 it is 10, and SM4 it is 16 (which can be expanded to 32 via geometry shaders).

    Now if we look at the structure that the vertex shader was generating for output into the pixel shader:
    Code (csharp):
    1.  
    2.             struct Input {
    3.                 float4 screenPos;
    4.                 float2 uv_Bump2;
    5.                 float3 worldRefl;
    6.                 float3 viewDir;
    7.                 INTERNAL_DATA
    8.             };
    9.  
    Because you are using the world reflection node INTERNAL_DATA is required (which is a whole matrix worth of interpolators!). Unity (on internal shader compilation) will pad out this data structure out even more with things like shadow data, and lightmapping data depending on which shader permutation is being compiled.

    Looking at the error message: 'Shader error in 'ShaderEditor/EditorShaderCache': Program 'frag_surf', cannot locate suitable resource to bind parameter "_ShadowCoord" at line 152' it seems like something has exceeded the allowed interpolator count.

    The way to work around this issue is to reduce the number of interpolators you are using. Step one for me would be to remove the World Reflection node and replace it with a Vertex Reflection node. It is much simpler (you can't modify it by the normal from the normal map :( ) but it will only use one interpolator register instead of the 4 I think you are using now.

    This issue can also be run into if you have too many unity texture samples because the offset UV's / tiling / scaling is calculated via the texture matrix in the vertex shader and passed through as an interpolator. There is a node that can help with this (Mesh UV), but it bypasses unity's nice material stuff. If the texture coordinates were calculated in the pixel shader this would not be so much an issue, but this is out of the shader editors control.

    If you are curious as to why this does not happen with transparent shaders it is because they don't calculate the same permutations of shaders that an opaque object does. In other words you kind of got lucky that you didn't go over the interpolator count before.
     
  5. Deleted User

    Deleted User

    Guest

    I've been doing my best to replicate it today, as it was happening a lot yesterday, but to no avail - it works fine today! It was just after pressing "new graph" in web player mode on Pro. I had been doing quite a bit before using it though. I've attached the info image anyway.
     

    Attached Files:

  6. priceap

    priceap

    Joined:
    Apr 18, 2009
    Posts:
    274
    hi -
    this is really exciting to see the new version with the access to custom lighting. I've been trying to figure out how to use it, and may not have the right idea. I tried making a "toon" shader with stepped color, but am not having great success. The second color blends with the first (see graph) and also the torus view in the screen shot shows how the object seems to be transparent with the lighting although the material is opaque. I figure I am not using the nodes correctly, so I was hoping some example could be given of how it could be used for stepped colors or textures, etc.

    edit: I fixed the transparency problem by turning it off in the details for the Master node in the pixel graph, but would still like feedback whether I am trying to use the custom lighting graph correctly
     

    Attached Files:

    Last edited: Nov 13, 2010
  7. farid

    farid

    Joined:
    Apr 11, 2010
    Posts:
    5
    I dont know , how to make this shader script for movie texture with shader node , anyone help me please !!! ;


    //////////////////////////////////////////////////////////////////////////////
    Shader "Matte/RGB Color"
    {

    Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _Matte ("Matte Color", Color) = (1,0,1,1)
    _Thresh ("Threshold", Range (0,1)) = 0.0
    _Cutoff ("Cutoff", Range (0,1)) = .5
    }

    SubShader {

    Pass {
    AlphaTest Less [_Cutoff]
    CGPROGRAM
    #pragma fragment frag
    #include "UnityCG.cginc"

    struct v2f {
    float4 pos : POSITION;
    float4 uv : TEXCOORD0;
    };

    sampler2D _MainTex;
    uniform half4 _Matte;
    uniform float _Thresh;
    uniform float _Cutoff;

    half4 frag (v2f i) : COLOR
    {
    //return _Matte;
    half4 color = tex2D(_MainTex, i.uv.xy);

    half3 keyMinus = half3( (_Matte.r - _Thresh), (_Matte.g - _Thresh), (_Matte.b - _Thresh) );
    half3 keyPlus = half3( (_Matte.r + _Thresh), (_Matte.g + _Thresh), (_Matte.b + _Thresh) );

    if ( ((color.r > keyMinus.r) (color.r < keyPlus.r)) ((color.g > keyMinus.g) (color.g < keyPlus.g)) ((color.b > keyMinus.b) (color.b < keyPlus.b)) )
    {
    return _Cutoff;
    }

    return float4(color.rgb, max(0, _Cutoff-0.01));
    }

    ENDCG
    } // pass
    } // subshader
    //Fallback "Transparent/Diffuse"
    } // shader
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
  8. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    Is it normal for Vertex Reflection to reflect upside-down? World Reflection works as expected, but I'm uncertain how to flip Vertex Reflection.
     
  9. MCIIID

    MCIIID

    Joined:
    Nov 13, 2010
    Posts:
    14
    Hey Stramit,

    This is looking like an awesome idea, and I've downloaded the shader editor to try it out myself. I recently put together a new desktop, and despite the graphics card being fairly new (or so my friend said when it we given to me. He said a year and a half old or so.) I can't seem to get the shader preview working. I downloaded the help window script as well, in hopes you could help me to fix the problem and get this working, because I would love to start building some shaders.

    I'm running the 30 pro trial before the installation has defaulted to indy.

    http://www.screencast.com/users/Akary1987/folders/Jing/media/d34afbb0-9859-49d6-a7b6-b1855ab6c64a
     
    Last edited: Nov 13, 2010
  10. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Can you PM me the graph that this is happening in? I can't seem to repro it in a shader I made.
     
  11. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    The preview requires render textures to be supported. If you look at the image you attached it says that it is using emulated 3.0 shaders and render textures are not supported. Can you check that in Edit -> Graphics Emulation it is set to 'no emulation'. Also make sure you have the latest graphics drivers installed (What card are you using?)
     
  12. MCIIID

    MCIIID

    Joined:
    Nov 13, 2010
    Posts:
    14
    It's an NVidia GeForce GTX 260 OC+Maxcore. It should be fully capable I would think. So...maybe I hit the wrong button in the trial activation. Does it require pro version to function?
     
  13. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Even without Pro it should show the proper driver. It's not. Are you sure you have the latest Nvidia drivers installed?
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Without Pro rendertextures don't work and as such the function won't work

    In case you hit such a wall, unity will normally claim that it is not supported, cause internally, the handling works in the way that if you don't have pro, the function that returns if a graphics feature is supported by the HW or not returns false for pro only features
     
  15. MCIIID

    MCIIID

    Joined:
    Nov 13, 2010
    Posts:
    14
    Well that's disappointing. Went and downloaded the latest drivers, installed, and restarted. Still shows as false, even without emulation. Something else I'm forgetting?
     
  16. MCIIID

    MCIIID

    Joined:
    Nov 13, 2010
    Posts:
    14
    Right, so, maybe I hit the wrong button after all, when it asked about the 30 day pro trial activation?
     
  17. MCIIID

    MCIIID

    Joined:
    Nov 13, 2010
    Posts:
    14
    aha, re-registered with the pro activated. Success!
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Cool :)
     
  19. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    That's great to hear, if you have any questions feel free to ask away.
     
  20. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Thanks for the detailed explanation!
     
  21. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Also, is it possible to blend 2 normals tex's (using TEX2DNormal), or should I avoid that and just use regular TEX2D, and unwrap it at the end just before input. As it stands I can't input 2 tex2dnrms into a Multiply node without it looking spastic.
     
  22. BenAllen

    BenAllen

    Joined:
    Sep 11, 2010
    Posts:
    13
    Hi,

    What is the equivalent to "Diffuse"? is it Albedo?
     
  23. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Yes
     
  24. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    /edit i am a moron ! split and assemble work just fine i just messed up some of my vert-colors for some debugging and never fixed em after-wards D:

    please disregard !


    however is it normal that a channel turns BLACK during a mask ?! should it you know ... disappear ?!
     
    Last edited: Nov 14, 2010
  25. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yep. The mask node turns the channels that are not masked to black. If you click the node there are options as to what channels you want to mask in or out.

    It's esentially doing: currentValue = currentValue * float4( maskX, maskY, maskZ, maskW);

    where the mask value is either 0 or 1 depending on the chekcbox.
     
  26. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Multiply? Don't you mean Add? If you want blend normals you need to add then, then renormalize. This can also be done with a lerp and normlaize. I don't know why you would be using a multiply.
     
  27. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Some time in the next few days Texel and I will be releasing a series of videos based on any questions you guys have on the editor. So if you have any questions on how to do something then ask away. We'll try and film as many as we can!
     
  28. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    I found on the Shader Fusion thread that he was using Depth-differences, and after a little prodding I found how to do this in SSE.
    I think it's probably very useful for softparticle shaders.
    I've added some controls, so I can define the height and thickness of the fade-point.
     

    Attached Files:

  29. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hey that's really cool clamps. I love soft particles they can make things like smoke look so much more realistic. I also like distortion via grab pass... I'll put one of those together after work tonight ;)
     
  30. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Speaking of grab pass....did any of you guys find a way to correct the false refraction that caused by grab pass?. The Bootcamp demo seems to fix this on their water shader, but i can find out how they do it.
     
  31. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    I'm loving this new version.

    I've been updating my graphs to use the new (1-v) node, rather than (one) and (subtract) to clean them up a bit, and I noticed that using (1-v) seems to yield one extra arithmetic operation than using (one) and (subtract). I don't know if this is just being reported wrong or if it's actually implemented in a less efficient way.

    Weird!
     
  32. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Ah cool, definite bug there.

    This is the workaround:


    Just make the result negative. I have fixed this in the codebase and it will be in 3.1 when it comes out.
     
  33. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi rea, is it possible that you can PM me the graph file that this was happening with for you? I tried to repro this issue before release but was unable to.

    Here is the graph I used:


    And here is how it looks (There is no transparency in this shader it is all done via the grab pass):


    What system / hardware are you on. Was this DX with AA turned on by any chance?

    Sgraph file I used attached (note you will need to have the camera script included with the editor attached to make it work properly - this sets up depth / normal render texture rendering):
     

    Attached Files:

    Last edited: Nov 15, 2010
  34. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'll have a look at this in the next day or so.
     
    Last edited: Nov 15, 2010
  35. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Is there a reason for the Add node in there ? (the one with only one input)
     
  36. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @stramit : when i mean about false refraction is the object above the water is refracted too...
    uhh....ok sorry i kinda confused here....what script for the camera? it is custom script ??
     
    Last edited: Nov 15, 2010
  37. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    If iam not mistaken the second value is the bump for distortion offset
     
  38. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Right, yes that makes sence actually.
     
  39. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    Hi all. I've been working on a tute for beginners like myself.
    It's your standard planet shader. I've found that planet shaders seem to be the teapot of the shader world these days, which is nice. It's good to have a standard.
    Here's some images from the tutorial.
     

    Attached Files:

  40. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    That's really cool. I can't wait to see the tutorial. :D
     
  41. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Oh sorry, I wasn't thinking when I posted that. For the depth difference node (which you are not using) the depth buffer is needed, for this you need to tell the camera to render depth / normals to an accessible texture (this is done implicitly for deferred rendering but nor for forward rendering). I included a script in the release to do this automagically (it's in ShaderEditorScripts). But that's beside the point as it's not needed for what you are doing.

    I'll have a look into this tonight for you. I have a suspicion that what you are doing has something to do with render queues and deferred rendering...
     
  42. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Hey Stramit

    I think i found a bug, but not sure whether it has something to do with the editor or unity itself, but the ScreenDepthDiff produces different results in the scene view and game view (also different in builds). I've used it in a water shader to make shallow parts more transparent with a distortet grabpass. Theproblem s that in the game view it gives a higher value, so my water is not fully transparent in the shallow parts as it is in the scene view. i kinda fixed by multiplying by 2 and subtracting 1 but then goes a little bit into the negative and produces some strange results.

    So just wondered if you have an idea how to fix this?
     
  43. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yeah. You can't trust the scene view (if you can even get it to work properly for shaders that use the depth diff node). You have to be in the game view with a real camera and the game playing. This is very frustrating I know, and I raised a bug about it but it is apparently intentional:

    http://intra.unity3d.com/fogbugz/default.asp?372424_h2smcrci

     
    Last edited: Nov 15, 2010
  44. Nick3d

    Nick3d

    Joined:
    Jan 28, 2010
    Posts:
    100
    Let's say I want to blend two different textures...one with tilling U1 V1 and one with tilling U6 V6, is there a way to do that using nodes?
     
  45. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,796
    I would like to see a tutorial using the custom lighting, because I don't quite understand it...

    I'm trying to do the blended normals SSS method (should calculate diffuse once with geometry normals, then with normal map normals then lerp those two (with the geometry one being tinted red). Should I do this with the simple lighting or not?...
     
  46. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Is there a way to create a double sided shader? Example, for stuff like coats without modelling thickness if you can't afford to...
     
  47. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    just had to say that this is an awesome script, thanks for sharing!
     
  48. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yep. Disable back face culling.

    $Screen shot 2010-11-16 at 6.26.30 PM.png

    (Cull mode none)
     
  49. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @Stramit

    The real problem is that the scene view rendered the shader as I inteded it :/ Well I'll see if i can work it out.

    Edit: Ohh BTW is thre away to disable the awesome bezier curves? :p 'cus when my shader get's real complicated it slows down the editor to abt 1 fps, 'cus of all the lines.

    EditEdit: and would be nice if you had the time to just whip a graph together that has dephtbased opacity.
     
    Last edited: Nov 16, 2010
  50. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    I tried rolling my own node that will refer to a function, but I couldn't see where that chunk of code for the function would be. By looking at the ParallaxNode I could see how you do the GetUsage thing - are there any nodes that rely on custom functions in the shader that I could look at?

    Planning on making the following:
    - Simplex noise
    - Overlay
    - Contrast