Search Unity

What shaders would you guys want?

Discussion in 'Shaders' started by tatoforever, Aug 28, 2012.

  1. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Hello guys,
    Shaders is a hot topic here in the forums.
    We all know that Unity build-in shaders are more for general use case than game specific which make them sometimes heavy and slow.
    I've lately got a bit of time to write some shaders so I would like to know what you guys want to have?
    Shaders will be written in Cg / HLSL, so you'll be able to use them in any platform.
    Keep in mind that I'm not a graphic guru (not yet :rolleyes: ), I got a CgFX knowledge but low level graphics programming inside Unity still relative new to me, so don't ask for a CE3 GI system (or similar craziness)! The goal is to dive deep and get dirty with low level graphic programming while providing the community more specialized/optimized shaders.
    So bring them on! :cool:

    [EDIT]
    For those who can contribute with petitions feel free to provide shaders/solutions. :)
     
    Last edited: Sep 21, 2012
    AlanMattano likes this.
  2. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Efficient water shader is always needed, Water4 looks good but could be a lot better : p
     
  3. poncho

    poncho

    Joined:
    Dec 10, 2010
    Posts:
    65
    tatoforever, could you give some links of what to learn to make shaders?
    thats one of the paths i think i could choose, between post procesing graphics, AI, Physics or 3dMath, still not sure of what to specialize and an intro could help for that
     
  4. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Water is high on my list, but as I'm a Unity Indie user, I could stand to go for something that looks/reacts better than the Simple Water shader.
     
  5. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
  6. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    This. A good looking water for Unity Free.
     
  7. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    I could count them so many to keep you busy for next two or three years:D But really,transparent shader with moving UVs in one dirrection (with normal, spec and diffuse) which could be used as water, or shader with moving Uvs in one dirrection with nrml, spec, diffuse and emissive for lava, or emissive shader that has been implemented in Shader package for Unity on Asset store or UDK emissive example. Those would be great for start:D
     
  8. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    @janpec,
    I see how people are dying for better water effects in Unity. Indeed, what you described could be a very good starting position and it can be easily achieved. I've been thinking in implementing this sort of water that features water flow using a special normal map texture to describe water direction (aka flow):
    www.valvesoftware.com/publications/2010/siggraph2010_vlachos_waterflow.pdf
     
  9. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    I would pay hundred bucks for a shader like that.


    It's open source. Maybe someone could translate that into Unity shader code and clean it up a bit. I just tried the sample .blend file which is provided in the video description and it works like charm with a decent framerate.
     
  10. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    There's actually already a shader that did that, I tried it. Works pretty well./
     
  11. Sir-Tiddlesworth

    Sir-Tiddlesworth

    Joined:
    Oct 19, 2011
    Posts:
    908
    I would pay $100 for a shader like this.

     
  12. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    @nipoco,
    Where's the sources of that water system? Also, i don't think it's just one water shader but severals shaders/code as there's seems to be access to the camera depth to do some edge blending between the terrain and the water plane.
    However, the XNA Ocean effect could possibly be done in just one shader without problem. :D

    [EDIT] Got it, I'm going to take a look at their sources and see what comes out of it but I'm a bit more interested in the XNA one (as stated before, it can be done in one shader without any camera or script setup). Once we get something right, then I'll start adding new features like underwater view, etc). :D
     
    Last edited: Aug 29, 2012
  13. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    The problem with the XNA shader is, it apparently does not have any caustics or a proper underwater view. For me it looks pretty similar to the community ocean shader (can't find the link right now) Just with a better displacement map.

    And it is DX11 right? The BGE shader is OpenGL.

    But thanks for your efforts :)
     
  14. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    @nipoco,
    The XNA ocean shader can be done with DX9 too. What I'm going to do is research a bit more their procedural waves algorithm, it looks like they are using some sort of detail waves inside the big waves to make it ultra-detailed. And it looks like the waves are computed in the pixel shader. Once i get that basic water, I'll add a system for the underwater view, depth/fog, caustics, DOF, etc.
    Tanks for the links. :D
     
    Last edited: Aug 29, 2012
  15. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Yes the waves looking pretty neat in the XNA shader. If that could be combined with the BGE caustics, SSS, chromatic aberration etc. That would be an awesome ocean shader.

    Really eager to see what you can do here. :D
     
  16. hellraizerhhh

    hellraizerhhh

    Joined:
    May 26, 2010
    Posts:
    619
    Use tasharen (sp) water and call it a day, that thing is beautiful :)
     
  17. xceed

    xceed

    Joined:
    Aug 2, 2012
    Posts:
    9
    a good toon shader, borderlands style.
     
  18. i-tech

    i-tech

    Joined:
    Jan 2, 2011
    Posts:
    195
    A shader that would allow me to blend textures based on vertex colors and would support shadows (would need to be bumped specular shader)
     
  19. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Last edited: Aug 29, 2012
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    I've already got something like this, I will post it later. ;)
     
  21. ATNEDev

    ATNEDev

    Joined:
    Jul 13, 2012
    Posts:
    54
    I guess a universal realistic water shader would be helpful. Also, I would personally like a parallax shader...
     
  22. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Looking forward to what you can come up with : )
     
  23. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Oh just remembered one more. If you know maybe Marmoset toolbag, there is really one cool feature in specular shader which is some sort of fresnel tweaking and it creates really powerfull and nice results. So on top of specular strenght slider and specular color slider if you could add this ability to control fresnel it would be cool. If you would be interested please take a look download demo of Marmoset and you will see what i mean.
     
  24. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Fresnel power and brightness can be exposed to properties (instead of hardcoding) but where can i download the Marmoset demo?
    Cheers,
     
    Last edited: Aug 29, 2012
  25. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
  26. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    @janpec,
    Ok i see. Yes, i can make those values tweakable by the user (in the same way as Marmoset) with sliders. I'll start working on the water system later in the day. :D
     
  27. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Don't forget the WIP screens while you work : D
     
  28. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Doh! :rolleyes:
     
  29. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I have a shader I am using in my game that does specular fresnel... I can post a screenshot if you want...
     
  30. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Here is an example of specular fresnel I made for Unity... I also saw this on Oblivion I think... $FresnelSpec2.jpg
     
  31. primaerfunktion

    primaerfunktion

    Joined:
    Jan 16, 2012
    Posts:
    98

    Attached Files:

  32. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Thanks for that link - I'll try that out!
     
  33. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Anyone interested in creating custom shaders (based on requests) for this thread, you are free to do it!
    Multiple choices are always better than only one! :rolleyes:
     
  34. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    @tatoforever How is specular thingy comming along?
     
  35. FlorianSchmoldt

    FlorianSchmoldt

    Joined:
    Jul 2, 2012
    Posts:
    334
  36. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Flow mapped water like this one:
     
  37. FlorianSchmoldt

    FlorianSchmoldt

    Joined:
    Jul 2, 2012
    Posts:
    334
    sexy but beside the shader, it needs a complicated script/tool to create the map itself
     
  38. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Yeh i dont think that tatoforever had in mind shaders that take months to writte:p
    This flowmap sure is great, but for rivers moving UVs are good replacement, we need other shaders more urgently.
     
  39. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Well, to be honest, shaders can be written from hours to days (depending on shader complexity) if you know what you'll be doing (how-to, algorithms, etc).
    However, complex effect's that involves more than just a shader (post-effects) requires a bit more time as there's code involved in. Don't get fooled by CE3 or UE3, Unity is pretty capable of, it's just that Unity devs are a bit lazy (excuses in advance) to create such nice water systems! lol
    What I'm doing right now is trying to learn all Unity shader semantics and build-in functions. I've always written CgFX/HLSL shaders inside 3ds max and maya, it is pretty straight forward and everything is... "standard" but with Unity shading dev is different. For example, uniforms, samplers, inputs, semantics is not that far away but not exactly as in 3ds Max/Maya. Fortunately i got something already working that I'll post soon. :D
    Btw janpec, you where asking for a custom bumped_specular shader? Or ocean/water shader?
     
  40. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    I just found a flowmap generator tool, really simply to use! I'm planning get waterflow from a sampler instead of hardcoding a static direction (looks more natural). Also, it'll feature correct Fresnel reflections. :D
     
  41. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
  42. DMJohn0X

    DMJohn0X

    Joined:
    Apr 17, 2012
    Posts:
    18
  43. pixellegolas

    pixellegolas

    Joined:
    Apr 10, 2011
    Posts:
    223
    I looked at borderlands quite much and I think it is a basic outliner but details are all in the textures, so really nothing fancy just good texturing :)
     
  44. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Yeh besides outliner there isnt anything special in Borderlands going on. Their style is determined by textures, if you take a look what they do is they either push AO or turn normal maps edges (black ones / deep ones) into color texture which is quite obvious.
     
  45. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    One thing i would really need with the water shader is the possibility to make it into ice : p
    But ant shade is a good shader, keep up the great work : D
     
  46. FlorianSchmoldt

    FlorianSchmoldt

    Joined:
    Jul 2, 2012
    Posts:
    334
  47. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Teck Lee Tan has created a flowmap paint script for Unity. Currently released as a stand-alone flow map painter for textures.

    http://teckartist.com/?p=96
     
  48. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    I forgot the link but there is one awesome flowmap scene made with Source engine, looked really great.

    Anyways tatoforever how is that specular shader comming along?
     
  49. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    If it's specular with fresnel you're after, here.

    Most surfaces have an extremely low fresnel value, it's only really things like metal have a higher value.

    Some sample values in linear space (from here);
    Quartz 0.045593921
    ice 0.017908907
    Water 0.020373188
    Alcohol 0.01995505
    Glass 0.04
    Milk 0.022181983
    Ruby 0.077271957
    Crystal 0.111111111
    Diamond 0.171968833
    Skin 0.028

    To get the values you should use if you're using gamma rather than linear space (in player settings) then you need to raise these values to the power of 1/2.2 (i.e. 0.45 recurring)
    e.g. Skin becomes 0.028 ^ ( 1 / 2.2 ) = 0.19686238464

    Code (csharp):
    1.  
    2. Shader "Custom/Bumped Diffuse Fresnel" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,1,1,1)
    5.         _MainTex ("Diffuse (RGB)", 2D) = "white" {}
    6.         _SpecularTex ("Specular (R) Gloss (G)", 2D) = "gray" {}
    7.         _BumpMap ("Normal (Normal)", 2D) = "bump" {}
    8.         _Fresnel ("Fresnel Value", Float) = 0.028
    9.     }
    10.  
    11.     SubShader {
    12.         Tags { "Queue" = "Geometry" "RenderType" = "Opaque" }
    13.  
    14.         CGPROGRAM
    15.             #pragma surface surf FresnelSpec fullforwardshadows exclude_path:prepass
    16.             #pragma target 3.0
    17.  
    18.             struct SurfaceOutputFresnelSpec {
    19.                 fixed3 Albedo;
    20.                 fixed3 Normal;
    21.                 fixed3 Emission;
    22.                 fixed Specular;
    23.                 fixed2 SpecularCustom;
    24.                 fixed Alpha;
    25.             };
    26.            
    27.             struct Input
    28.             {
    29.                 float2 uv_MainTex;
    30.             };
    31.            
    32.             sampler2D _MainTex, _SpecularTex, _BumpMap;
    33.             float _Fresnel;
    34.                
    35.             void surf (Input IN, inout SurfaceOutputFresnelSpec o)
    36.             {
    37.                 o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    38.                 o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    39.                 o.SpecularCustom = tex2D(_SpecularTex, IN.uv_MainTex).rg;
    40.             }
    41.  
    42.             inline float CalcFresnel (float3 viewDir, float3 h, float fresnelValue)
    43.             {
    44.                 float fresnel = pow(1.0 - dot(viewDir, h), 5.0);
    45.                 fresnel += fresnelValue * (1.0 - fresnel);
    46.                 return fresnel;
    47.             }
    48.        
    49.             inline float CalcSpec ( float spec, float specLevel, float gloss, float fresnel )
    50.             {
    51.                 return pow(spec, gloss * 128) * specLevel * fresnel;
    52.             }
    53.        
    54.             inline float3 CalcFinalColor (float3 albedo, float3 lightColor, float NdotL, float spec, float atten)
    55.             {
    56.                 return lerp ( albedo * lightColor * saturate ( NdotL ), lightColor, spec ) * atten;
    57.             }
    58.  
    59.             inline fixed4 LightingFresnelSpec (SurfaceOutputFresnelSpec s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    60.             {
    61.                 viewDir = normalize(viewDir);
    62.                 lightDir = normalize(lightDir);
    63.                 s.Normal = normalize(s.Normal);
    64.                 float NdotL = dot(s.Normal, lightDir);
    65.                 float3 h = normalize(lightDir + viewDir);
    66.  
    67.                 float specBase = saturate(dot(s.Normal, h));
    68.  
    69.                 float fresnel = CalcFresnel (viewDir, h, _Fresnel);
    70.  
    71.                 float spec = CalcSpec (specBase, s.SpecularCustom.r, s.SpecularCustom.g, fresnel);
    72.  
    73.                 fixed4 c;
    74.                 c.rgb = CalcFinalColor (s.Albedo, _LightColor0.rgb, NdotL, spec, atten);
    75.                 c.a = 1.0;
    76.                 return c;
    77.             }
    78.  
    79.         ENDCG
    80.     }
    81.     FallBack "Bumped Diffuse"
    82. }
    83.  
     
    Last edited: Sep 18, 2012
  50. chrisso

    chrisso

    Joined:
    Sep 4, 2012
    Posts:
    139
    Volumetric shaders, volumetric billboards..?