Search Unity

Strumpy Shader Editor [Now Open Source]

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

  1. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @Nick3d

    You need to click on the master node in the graph and give the shader a name.
    You can save the shader anywhere you want inside the asset folder.
    Then when you open a material in the inspector you can find the shader in the dropdown menu.
     
  2. Jordii

    Jordii

    Joined:
    Sep 14, 2010
    Posts:
    135
    Good grief, that looks awesome. Amazing work :)
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    You are using unity indie correct? The reason for this is that in the editor shaders to not get updated time values unless you are in 'play' mode. For the preview (which will not show up in indie) to work properly the preview shader is overridden and doesn't actually have _SinTime _CosTime it has the fields _EditorSinTime and _EditorCosTime. When the preview is rendered these values are manually passed through as any other paramater. This is so we can get a preview that updates in realtime and looks funky.

    When the shader is exported these values changed into the 'real' values, so they work properly at run time. I might add an override to this, if you think that would help you.
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Westmark nailed this. You need to name the shader by clicking the master node. It will then show up with this name in the material list.
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
  6. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    waiting for it to be released. But no pressure just go at your speed!
     
  7. easterislandnick

    easterislandnick

    Joined:
    Oct 27, 2010
    Posts:
    15
    I want to create a shader for breaking waves that will be seen from a top down view from quite a distance. Using a SinTime plugged into a Sin plugged into a UV_Pan I can get the texture to oscillate along the X but the amount is too much. Can I reduce the amount of movement in the X to create a gentle sway? Is it possible to have the texture move quickly in one direction then slowly in the other?

    Thanks. Great tool by the way!
     
  8. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    just multiply the sin result with something between 0 and 1 :)

    Oh wait i might be wrong :/
     
    Last edited: Oct 27, 2010
  9. Grady Lorenzo

    Grady Lorenzo

    Joined:
    Jan 18, 2010
    Posts:
    407
    excellent work. i've been needing a decent shader editor
     
  10. easterislandnick

    easterislandnick

    Joined:
    Oct 27, 2010
    Posts:
    15
    Hi Westmark, that works but its very slow now, can I speed up the cos time in any way?
     
  11. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @Eastereislandnick
    try doing the same for that.
    and use a range for multiplying so you can edit the value live :)
     
  12. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    For getting arbitrary values for specular, emission, etc., i will usually use a multiply node with the first box for using my texture, and the second box will be using a "Float" node...
     
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Woah this tool is amazing, i manage to create water shader with this tools even tough i have to edit the shader manualy after saving from the editor.
    $Clip_5.jpg

    and Here's the shader.
    View attachment $Refract.shader
    btw is there somebody in here who manage to fix the refraction artifact that caused from the grab pass??

    And here's the graph file. sorry for using 7zip on this, some how i can't upload .sgraph file. It says invalid file
    View attachment $Water_Refl_Refr_Grab2.7z
     
  14. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    not successful.
    i had attached the shader.
    if possible help me out.:D
     

    Attached Files:

  15. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hey that's really cool. Can you tell me what you had to edit afterwards. If it's something that can be added to the editor proper I am very open to adding it ;) Don't want people to have to change things manually if it can be avoided.
     
  16. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    The sintime and costime nodes work just like the sintime and costime shader input (they are the same). So if you want a faster time splat the x/y/z/w components ;)

    Here is the doc:

    Should make it a bit easier ;)
     
  17. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    well if iam not mistaken...

    Code (csharp):
    1.  
    2. Shader "CustomShader/Water_reflectrefract_2"
    3. {
    4.     Properties
    5.     {
    6. _Distort_scale("_Distort_scale", Range(0,0.5) ) = 0.1163522
    7. _Water_Bump("_Water_Bump", 2D) = "white" {}
    8. _Scale_Wave("_Scale_Wave", Float) = 0
    9. _Wave_speed("_Wave_speed", Range(0,20) ) = 20
    10. _Sampler2D1("_Sampler2D1", 2D) = "white" {}
    11. _WaterColor1("_WaterColor1", Color) = (0.1529412,0.6784314,0.854902,1)
    12. _ReflectionTex("_ReflectionTex", Cube) = "" {}
    13. _Reflection("_Reflection", Range(0,5) ) = 0.5
    14. _Fresnel("_Fresnel", Range(0,15) ) = 15
    15. _Reflection_Color("_Reflection_Color", Color) = (1,1,1,1)
    16. _specular("_specular", Range(0,10) ) = 0.5
    17. _Gloss("_Gloss", Color) = (1,1,1,1)
    18. _Gloss_Strength("_Gloss_Strength", Range(1,100) ) = 1
    19. _Fade("_Fade", Range(0,1) ) = 1
    20.  
    21.     }
    22.    
    23.     SubShader
    24.     {
    25.         Tags
    26.         {
    27. "Queue"="Geometry+0"
    28. "IgnoreProjector"="True"
    29. "RenderType"="Transparent"
    30.  
    31.         }
    32. GrabPass { }
    33.        
    34. Cull Off
    35. ZWrite On
    36. ZTest LEqual
    37.  
    38.  
    39.         CGPROGRAM
    40. #pragma surface surf BlinnPhongEditor alpha vertex:vert
    41. #pragma target 3.0
    42.  
    43.             struct EditorSurfaceOutput {
    44.                 half3 Albedo;
    45.                 half3 Normal;
    46.                 half3 Emission;
    47.                 half3 Gloss;
    48.                 half Specular;
    49.                 half Alpha;
    50.             };
    51.            
    52.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput  s, half3 lightDir, half3 viewDir, half atten)
    53.             {
    54.                 #ifndef USING_DIRECTIONAL_LIGHT
    55.                 lightDir = normalize(lightDir);
    56.                 #endif
    57.                 viewDir = normalize(viewDir);
    58.                 half3 h = normalize (lightDir + viewDir);
    59.                
    60.                 half diff = max (0, dot (s.Normal, lightDir));
    61.                
    62.                 float nh = max (0, dot (s.Normal, h));
    63.                 float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;
    64.                
    65.                 half4 c;
    66.                 c.rgb = (s.Albedo * _LightColor0.rgb * diff +  _LightColor0.rgb * spec) * (atten * 2);
    67.                 c.a = s.Alpha + _LightColor0.a * Luminance(spec) *  atten;
    68.                 return c;
    69.             }
    70.            
    71.             inline half4 LightingBlinnPhongEditor_PrePass  (EditorSurfaceOutput s, half4 light)
    72.             {
    73.                 half3 spec = light.a * s.Gloss;
    74.                
    75.                 half4 c;
    76.                 c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    77.                 c.a = s.Alpha + Luminance(spec);
    78.                 return c;
    79.             }
    80.            
    81.             struct Input {
    82.                 float4 screenPos;
    83. float2 uv_Water_Bump;
    84. float2 uv_Sampler2D1;
    85. float3 worldRefl;
    86. float3 viewDir;
    87. INTERNAL_DATA
    88.  
    89.             };
    90.            
    91.             void vert (inout appdata_full v, out Input o) {
    92.  
    93.             }
    94.            
    95. sampler2D _GrabTexture;
    96. float _Distort_scale;
    97. sampler2D _Water_Bump;
    98. float _Scale_Wave;
    99. float _Wave_speed;
    100. sampler2D _Sampler2D1;
    101. float4 _WaterColor1;
    102. samplerCUBE _ReflectionTex;
    103. float _Reflection;
    104. float _Fresnel;
    105. float4 _Reflection_Color;
    106. float _specular;
    107. float4 _Gloss;
    108. float _Gloss_Strength;
    109. sampler2D _CameraDepthTexture;
    110. float _Fade;
    111.  
    112.  
    113.  
    114.             void surf (Input IN, inout EditorSurfaceOutput o) {
    115.                 o.Albedo = 0.0;
    116.                 o.Normal = float3(0.0,0.0,1.0);
    117.                 o.Emission = 0.0;
    118.                 o.Gloss = 0.0;
    119.                 o.Specular = 0.0;
    120.                 o.Alpha = 1.0;
    121. float4  Tex2D2=tex2D(_GrabTexture,((IN.screenPos.xy/IN.screenPos.w).xyxy).xy);
    122. float4 Multiply4=float4(_Scale_Wave) * (IN.uv_Water_Bump.xyxy);
    123. float4 Multiply6=_Time * _Wave_speed.xxxx;
    124. float4 UV_Pan0=float4(Multiply4.x +  Multiply6.x,Multiply4.y,Multiply4.z,Multiply4.w);
    125. float4 Tex2DNormal0=UnpackNormal( tex2D(_Water_Bump,UV_Pan0.xy) );
    126. float4 Multiply2=float4(_Scale_Wave) * (IN.uv_Sampler2D1.xyxy);
    127. float4 UV_Pan1=float4(Multiply2.x,Multiply2.y +  Multiply6.x,Multiply2.z,Multiply2.w);
    128. float4 Tex2DNormal1=UnpackNormal( tex2D(_Sampler2D1,UV_Pan1.xy) );
    129. float4 Multiply7=Tex2DNormal0 * Tex2DNormal1;
    130. float4 Multiply0=Multiply7 * float4( 0.5);
    131. float4 Multiply1=_Distort_scale.xxxx * Multiply0;
    132. float4 Add0=((IN.screenPos.xy/IN.screenPos.w).xyxy) + Multiply1;
    133. float4 Tex2D0=tex2D(_GrabTexture,Add0.xy);
    134. float4 Multiply3=Tex2D2 * Tex2D0.w + Tex2D0 * (1-Tex2D0.w); [COLOR=royalblue]\\originally this line was Tex2D2 * Tex2D0\\[/COLOR]
    135. float4 Splat0=Tex2D0.z;
    136. float4 Saturate1=saturate(100/Splat0);
    137. float4 Multiply10=Saturate1 * _WaterColor1;
    138. float4 Multiply11=Multiply3 * Multiply10;
    139. float4 WorldReflection0_0_NoInput = float4(0,0,1,1);
    140. o.Normal = Multiply7; [COLOR=royalblue]\\ i have to move this line from below so the bump can be used in reflection [/COLOR]
    141. float4 WorldReflection0=float4( WorldReflectionVector (IN,  WorldReflection0_0_NoInput+o.Normal), 1.0); [COLOR=royalblue]\\added +o.Normal[/COLOR]
    142. float4 TexCUBE0=texCUBE(_ReflectionTex,WorldReflection0);
    143. float4 Multiply9=TexCUBE0 * _Reflection.xxxx;
    144. float4 Fresnel0_1_NoInput = float4(0,0,1,1);
    145. float4 Fresnel0=float4( 1.0 - dot( normalize( float4(IN.viewDir,  1.0).xyz), normalize( Fresnel0_1_NoInput.xyz ) ) );
    146. float4 Pow1=pow(Fresnel0,_Fresnel.xxxx);
    147. float4 Multiply8=Multiply9 * Pow1;
    148. float4 Multiply12=Multiply8 * _Reflection_Color;
    149. float4 Add1=Multiply11 + Multiply12;
    150. float4 Multiply5=_Gloss * _Gloss_Strength.xxxx;
    151. float4 ScreenDepthDiff0= LinearEyeDepth (tex2Dproj(_CameraDepthTexture,  UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;
    152. float4 Pow0=pow(ScreenDepthDiff0,_Fade.xxxx);
    153. float4 Saturate0=saturate(Pow0*2);
    154. float4 Master0_2_NoInput = float4(0,0,0,0);
    155. float4 Master0_6_NoInput = float4(1,1,1,1);
    156. o.Albedo = Add1;
    157. o.Specular = _specular.xxxx;
    158. o.Gloss = Multiply5;
    159. o.Alpha = Saturate0;
    160.  
    161.             }
    162.         ENDCG
    163.     }
    164.     Fallback "Diffuse"
    165. }
    166.  
    167.  
    That's all i think...
     
  18. Andrew Greenwood

    Andrew Greenwood

    Joined:
    Oct 13, 2010
    Posts:
    6
    Really good work for this project...
     
  19. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @Rahuxx

    Remove these 3 lines:

    Code (csharp):
    1. Cull Back
    2. ZWrite On
    3. ZTest Less
    and remove alpha from this line:

    Code (csharp):
    1. #pragma surface surf BlinnPhongEditor alpha vertex:vert
     
  20. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    thanks
     
  21. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    @Westmark

    I tried it the shader i attached earlier and it worked, but when i tried in other few i did not find solution.
    Please my master can you help?:D
     

    Attached Files:

  22. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    03.shader still has a transparent tag and alpha in pragma
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
  24. BenAllen

    BenAllen

    Joined:
    Sep 11, 2010
    Posts:
    13
    Hi. I have been following the tutorial. What a great program. I can really see the potential. The way the inputs and operators work, is really swish. If I understood the components of a shader better, this would be exactly how I would build an idea I have for a indie water shader. Does anyone know where there is an idiots guide to shaders? I would like to make a water shader that has the illusion of increasing colour intensity with distance from the camera (to create deep water), and also keep the surface effects of the island water (in the demo).

    Cheers.
     
  25. scarletsnake

    scarletsnake

    Joined:
    Nov 27, 2009
    Posts:
    106
    stramit, I've posted a detailed description of the shader that I would like to create, would you be willing to help?
     
  26. Mixamo

    Mixamo

    Joined:
    Oct 20, 2010
    Posts:
    163
    You, good sir, have just blown my face off with the level of awesomeness.
     
  27. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    I have a suggestion for enabling the free version to have a real time view if you are still looking into ideas on ways around the render to texture.

    Perhaps it is possible to have the editor create a shader named temp(that is located in your extensions folder) that when you click "update shader", it compiles directly to this temp.shader file that will then be used by the preview window. Then when the user is done modifying the shader the export function could just save the shader again offering the option of where to save and what to name it. Basically just adding a dummy file to allow the user to not have to constantly work with the save and export dialog boxes. The one click and instant update would in essence just streamline the free users work around.

    Just some ideas! Thanks again for such an awesome tool!
     
  28. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    @Westmark

    can you provide corrected shaders, as i am 0 in programing.
     
  29. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    @ Maker - this is possible right now. If you look in the \Assets\Editor\ShaderEditor\Resources\Internal\Temp you'll see "TempShader.shader"
    Apply this, and when you press Update, you'll see the updates in your scene.
     
  30. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Beta 3 will be released in conjunction with Unite. ;) I'm really happy with how it's shaping up and i have nothing to do except work on it for the next 1.5 weeks. YAY!
     
  31. Svyatoslav

    Svyatoslav

    Joined:
    Sep 28, 2010
    Posts:
    8
    Great ;)

    I'm making shader with ability to desaturate diffuse, i found reference code
    And now I'm stuck. How to make "float gray = color.r * 0.3 + color.g * 0.59 + color.b *0.11" with nodes?
     
  32. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Just take the output from color and multiply it by const float4(0.3,0.59,0.11,1.0), you'll then need to take the output of this and input it into 3 splat nodes, one splatting x, one y, one z. Then add the output from these 3 up.
     
  33. Svyatoslav

    Svyatoslav

    Joined:
    Sep 28, 2010
    Posts:
    8
    Thank you. )))
    Now it works.
     
  34. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    YAY! And if i may be so daft, what is in version 3?
     
  35. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Hello Stramit,

    any update is planned for this great tool?

    Kenshin
     
  36. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    He already said 3.0 will be out during Unite.
     
  37. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Oops... my fault, sorry! :(
     
  38. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    Yes, however, this does not allow the viewing of the shader in the creation window. I was suggesting a way to get the shader to be viewable in the real time viewer since the real time view also requires a quick compile with the need to press "update" to show the changes. Until then, I will use this method to view shaders in the scene view to test my work.
     
  39. Clamps

    Clamps

    Joined:
    Nov 7, 2009
    Posts:
    220
    @Maker - As far as I know, you'll always have to update the shader to get it to show changes, no matter the method. Changes have to be compiled before the engine can display them. Unless I'm misunderstanding your point.
     
  40. Svyatoslav

    Svyatoslav

    Joined:
    Sep 28, 2010
    Posts:
    8
    Snow sparkles shader
    $Snow_sparkle.jpg

    $Snow_sparkle_shader_part.jpg
    Is View Direction node changes when camera moving in scene, not rotating?

    How to get pixel's direction(camera vector + reflection vector) in world coordinates?
     
  41. jcarpay

    jcarpay

    Joined:
    Aug 15, 2008
    Posts:
    561
  42. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    From the documentation:
    float3 viewDir - will contain view direction, for computing Parallax effects, rim lighting etc.

    This is I believe in 'surface space'. Where 0,0,1 represents the (non normal mapped normal).

    It's not possible currently to get the world direction of a pixel. Due to the _World2Object matricies not being set properly in the pixel shader (see: http://intra.unity3d.com/fogbugz/default.asp?372312_gfv5bb1m ).
     
  43. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Speaking of shader bugs, Gloss and Spec seem to be reversed.
     
  44. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
  45. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Just wanted to say thanks for this sweet tool. Its made shader life a hell of a lot more bearable!

    Should we build up a spot on the wiki or something to build up a community library of sgraphs?
     
  46. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    @dave: sounds like a great idea :)
     
  47. FlaSh-G

    FlaSh-G

    Joined:
    Apr 21, 2010
    Posts:
    212
    Wow.
    I'm simply amazed.
    This is what I always missed in Unity compared to the Unreal Engine.

    Thanks. Really.
     
  48. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    That's a great idea! Go ahead and make it I'm sure it will help people out!
     
  49. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Ahh yes. This is due to unity. All the default shaders seem to have gloss and spec set up in an odd way and I wanted to keep it consistent with the editor. It is incorrect but maps to unity.
     
  50. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    $Screen shot 2010-11-07 at 6.48.39 PM.png

    Hrrm, new right click context menu? Seems to be a bit more user friendly ;)

    $Screen shot 2010-11-07 at 6.59.52 PM.png

    Multiple node select and movement?

    ;)