Search Unity

What shaders would you guys want?

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

  1. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    With banding would be great, please. I'm trying to go for an more rigidly-retro effect with it.
     
  2. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Alright,
    I'll see if i can make it tomorrow, when i get some free time. :D
     
  3. spendew

    spendew

    Joined:
    Feb 12, 2012
    Posts:
    104
    First off, thank you for your enormous contribution to the community.

    Would you be able to do another take on the team fortress 2 shader? The current one is great and all but there are no variations (bump, spec .ect), just the one with all options. Also I am pretty sure Unity is giving me errors with it.

    Or even if you had an idea for another heavily stylized lighting similar to it.
     
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    I can't create a whole range of variations for all possible use cases as my time is very limited. People ask me some specific shaders and I write them. What exactly do you need? :rolleyes:
     
  5. spendew

    spendew

    Joined:
    Feb 12, 2012
    Posts:
    104
  6. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Ok, you need a TF2 toon shader with an outline shader (aka borderlands style) as the one shared few posts back?
     
  7. spendew

    spendew

    Joined:
    Feb 12, 2012
    Posts:
    104
    Not necessarily, but that ok it'll do!
     
  8. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Sorry, but I need more specific information about your request. What do you exactly want?
     
  9. spendew

    spendew

    Joined:
    Feb 12, 2012
    Posts:
    104
    I think the best way to put it is a toon style shader that uses a ramp and rims. But also has the option to be bumpMapped, specular, parallax ect.
     
  10. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Hi Tatoforever!

    Still hot for this one? ^__^!

    I am gonna send a first build for apple review this week end.
    Then no rush if you want to give it a try.

    I can share a build with you if you want to give it at the new version of the app, just drop me a line o_<.


     
  11. unseenthings

    unseenthings

    Joined:
    Nov 12, 2009
    Posts:
    32
    sama.van -- what shader did you end up using? I'd love to get this shader as well -- whether it was one built here or from the asset store, I'm trying to do the same thing.

    Thanks.
     
  12. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    For now they are just static screena!! T__T!!

    It would be for an iOS viewer, then performance aren't a problem on my side, I have a bunch of free memory.

    The most important is quality!!

    I think Unreal engine does have it, isn't it?
     
  13. Lyker

    Lyker

    Joined:
    Feb 27, 2013
    Posts:
    60
    Can I just simply request a shader here? And if I'm lucky you will create it? :D

    If so, I searched everywhere around the internet but couldn't find anything good.
    I'd like something like a heat haze. It should be some kind of "distortion in light". Which will represent a ghost.

    If there is already something like this that will work in Unity 4, please tell me.

    Any help is appreciated. :)
     
  14. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
  15. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    Hi,

    I'm testing another approach with a single shader, the current code looks like this :

    Code (csharp):
    1. Shader "Custom/RoundMask" {
    2.  
    3.    Properties {
    4.        _Color ("Main Color", Color) = (1,1,1,0.5)
    5.        _MainTex ("Texture", 2D) = "white" { }
    6.    }
    7.  
    8.    SubShader {
    9.  
    10.       Tags {"Queue"="Transparent"}
    11.    
    12.        Pass {
    13.      
    14.             Blend SrcAlpha OneMinusSrcAlpha
    15.          ZTest Always Cull off ZWrite off
    16.          Fog { Mode off }
    17.          
    18.          CGPROGRAM
    19.          #pragma target 3.0
    20.          #pragma vertex vert
    21.          #pragma fragment frag
    22.          #pragma fragmentoption ARB_precision_hint_fastest
    23.          #include "UnityCG.cginc"
    24.          
    25.          
    26.          float4 _Color;
    27.          sampler2D _MainTex;
    28.          uniform half4 pos1;
    29.          uniform half4 pos2;
    30.          uniform half4 pos3;
    31.          uniform half4 pos4;
    32.          
    33.          float4 _MainTex_ST;
    34.  
    35.          struct v2f {
    36.              float4  pos : SV_POSITION;
    37.              float2  uv : TEXCOORD0;
    38.          };
    39.  
    40.           //-----------------------------
    41.          // VERTICES
    42.          v2f vert (appdata_base v)
    43.          {
    44.              v2f o;
    45.              o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    46.              o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
    47.              return o;
    48.          }
    49.                  
    50.          //----------------------------
    51.          // FRAG
    52.          half4 texcol;
    53.          float2 pos;
    54.          half m1 = 0;
    55.          half dist = 0;
    56.          float inner = 0;
    57.          
    58.          half4 frag (v2f i) : COLOR
    59.          {
    60.              texcol = tex2D (_MainTex, i.uv);
    61.             m1 = 0;
    62.             inner = pos1.z * 0.7;
    63.            
    64.             if(m1<1){
    65.                   dist = distance(i.uv, float2(pos1.x, pos1.y));
    66.                if(dist < inner) discard;
    67.                if(dist < pos1.z) m1 += smoothstep(pos1.z, inner,dist);
    68.             }
    69.            
    70.             if(m1<1){
    71.                   dist = distance(i.uv, float2(pos2.x, pos2.y ));
    72.                   if(dist < inner) discard;
    73.                if(dist < pos2.z) m1 += smoothstep(pos2.z, inner,dist);
    74.             }
    75.            
    76.             if(m1<1){
    77.                   dist = distance(i.uv, float2(pos3.x, pos3.y ));
    78.                   if(dist < inner) discard;
    79.                if(dist < pos3.z) m1 += smoothstep(pos3.z, inner,dist);
    80.             }
    81.            
    82.             if(m1<1){
    83.                dist = distance(i.uv, float2(pos4.x, pos4.y ));
    84.                if(dist < inner) discard;
    85.                if(dist < pos4.z) m1 += smoothstep(pos4.z, inner,dist);
    86.             }
    87.            
    88.             texcol.a = 1.0 - m1;
    89.          
    90.              return  texcol ;
    91.          }
    92.          ENDCG
    93.  
    94.        }
    95.    }
    96. }  

    I've tried to optimize it as much as I could with my current little shaders knowledge, but it's still too slow on iOS devices (less than 20fps), and only with 4 holes :(
    Since I'm aiming for around 20 holes... I'm far from success ^^;

    Here, the frag function is evaluated for each pixel on screen, wich might be really slow, does any solution exists to limit it to the current texture pixel resolution instead ?
    like a render to texture, but in the shader... (I'm using the free version, so I don't have access to the RenderToTexture function)

    So I'm looking for any advice to optimize this shader furthermore, or for any alternative solution ;)

    thanks ^^
     
  16. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Sorry for the late reply, I din't got any post subscription from this thread (possibly due to the forums changes).
    Did you tried Aubergines one? Did it worked? Whatever shader you have right now, I would like to give it a look.
    Cheers,
     
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    If i understand well you are trying to create a selection effect for an iOS RTS game right?

    Optimizations:
    The problem here is the "if" branching (and you got multiple ones running in a fragment shader), even desktop GPUs will suffer running this shader. You have to reduce your fragment operations and remove all your if branching (or at least use only 1).
     
  18. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    You mean it will be faster for the gpu to actually do the distance evaluation than skipping it with a if branching ??
     
  19. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    As a rule of thumb: way faster. GPUs are massively parallel, and rarely get any sort of benefit from branching at the fragment level. If two neighbouring fragments take different paths in your code, the result is often slower than if you just did all the work in both.
     
  20. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    Ok !
    Thanks a lot for this invaluable information :)

    Anyway, removing all the "if" doesn't improves the performances so much :/
     
  21. jessica1986

    jessica1986

    Joined:
    Feb 7, 2012
    Posts:
    621
    Hello i need 2 small helps

    1. How do i add this light efffect in my scene using a shader [NOTE:: This will be used in mobile] ??
    View attachment 46602

    can you help me making a shader to do this with an emissive value ??

    How can i achieve this ?

    Direct link to image- http://i.imgur.com/KQne5kj.jpg

    I cant use flare coz its only runtime, it will effect my game performance on mobile


    2. Need help on MADFINGER > DIFFUSE > SIMPLE Shader

    Hello,

    I am very new in Shaders, you can say i know absolutely nothing. I am making a mobile game and after going through Shadowgun's example scene, i copied its shaders and mainly i used

    MADFINGER > DIFFUSE > SIMPLE Shader

    When i pressed edit, i saw this code -

    Code (csharp):
    1. Shader "MADFINGER/Diffuse/Simple" {
    2. Properties {
    3.       _MainTex ("Base (RGB)", 2D) = "white"
    4.    }
    5.    SubShader {
    6.       Pass {
    7.             SetTexture [_MainTex]
    8.       }
    9.    }
    10. }
    11.  
    I wish to have an option to add normal map in here. Please help me how do i do it ?
    and guide me like what can i do more in here to enhance the looks.
     
    Last edited: Mar 14, 2013
  22. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    1. It's likely just a billboarded plane with an alpha texture on it. Try playing with the halo settings for your lights.


    2. I'm not certain you can. Not easily, anyway (I guess you could use an object space directional light vector fed in through script and an object space normal map?).

    You'd be better off with a minimal vert/frag shader that handles normal mapping properly.
     
    Last edited: Mar 14, 2013
  23. Athomield3D

    Athomield3D

    Joined:
    Aug 29, 2012
    Posts:
    193
    Hey mate, i just want a normal shader with diffuse, spec, normal and gloss maps slots
     
  24. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    I have searched all thread and didn't found anything about movle textures with alpha (and anti aliasing support). Is that possible with shader? I have found a solution here on foruns but with no antialiasing support :(
     
  25. unimechanic

    unimechanic

    Joined:
    Jan 9, 2013
    Posts:
    155
  26. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Thank you for the sample. I see there is no antialiasing support yet....

    Please check attachment for my test movie. It's RGB with alpha channel side by side. Any chance to read it's alpha channel?

    $Pa4EGWR.png
     
  27. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi there,

    I'm trying to get a simple shader that blends 2 textures based on an slider. So for instance, the float slider value is 0.5 would mean that both are merged equally while having set it to 0f, only one texture would be visible or 1f the other would be visible. I managed to get it but the problem is that Lighting is ignored. I use a directional light and no shadows are displayed on my object. I'm guessing I have to add the shadows to at least one of the textures but I dont' know how to do it. I tried this from the wiki but the shadows are still not working. Any ideas?

    Code (csharp):
    1.  
    2.  
    3. Shader "Blend 2 Textures" {
    4.  
    5.  
    6.     Properties
    7.  
    8.  
    9.     {
    10.  
    11.  
    12.         _Blend ("Blend", Range (0, 1) ) = 0.5
    13.  
    14.  
    15.         _MainTex ("Texture 1", 2D) = ""
    16.  
    17.  
    18.         _Texture2 ("Texture 2", 2D) = ""
    19.  
    20.  
    21.     }
    22.  
    23.  
    24.    
    25.  
    26.  
    27.     SubShader
    28.  
    29.  
    30.     {
    31.  
    32.  
    33.         Lighting On
    34.  
    35.  
    36.         Cull Back// it will only render the front
    37.  
    38.  
    39.        
    40.  
    41.  
    42.         Material
    43.  
    44.  
    45.         {
    46.  
    47.  
    48.             Ambient (2,2,2)
    49.  
    50.  
    51.             Diffuse (1,1,1)
    52.  
    53.  
    54.         }
    55.  
    56.  
    57.        
    58.  
    59.  
    60.         Pass
    61.  
    62.  
    63.         {
    64.  
    65.  
    66.             SetTexture [_MainTex]
    67.  
    68.  
    69.            
    70.  
    71.             SetTexture [_Texture2]
    72.  
    73.             {
    74.  
    75.  
    76.                 ConstantColor (0,0,0, [_Blend])
    77.  
    78.  
    79.                 combine texture lerp(constant) previous
    80.  
    81.  
    82.             }
    83.  
    84.  
    85.            
    86.  
    87.  
    88.             SetTexture [nothing]
    89.  
    90.  
    91.             {
    92.  
    93.  
    94.                 combine previous * primary
    95.             }
    96.         }
    97.  
    98.     }
    99.  
    100.  
    101.     FallBack "Diffuse"
    102.  
    103.  
    104.  
    105.  
    106.  
    107. }
    108.  
    109.  
    110.  
     
  28. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Browse few pages back, someone already asked and it was posted. If you can't find it, let me know, I'll work out something quickly. :rolleyes:
     
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    I'm on it. :rolleyes:

    PS: Mind you if i write it in cg? I don't like shaderlab. ^^
     
  30. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
  31. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    @tatoforever,

    What about movie with alpha? Do you think it's possible or it is in fact a Unity limitation? (see my post above)
     
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    I don't have quicktime installed so i can't read the videos in the example project and see if it works but I've changed the shader to make it read the alpha channel.
    Furthermore, if you can get me a .vorbis video (or any video that Unity can read without any external package) I'll be able to a deeper research on the subject.
    Anti aliasing in the video is possible yes but first i need to get the first part working! Please let me know if it works! ;)
     
  33. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
  34. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    @vicenterusso,
    I just tested the videos you've sent, alpha does actually works with the default shader (the one in "MovieTextureAlpha.zip") . What's the problem you are having?
     
  35. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Yes it works indeed, but the shader it's not reading the alpha values. Check the alpha values from this picture (black / gray / white):

    http://i.imgur.com/OXPRSO8.png

    And check the results to the left. See? There's no anti aliasing...
     
  36. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    That's not anti-aliasing issue, that's a common texture issue with alpha channels.
    See the black halos/edges:

    $2161.alpha_5F00_problem.jpg

    $wrongalphaqf0.jpg

    $Untitled2.jpg

    Unfortunately, it's really hard to get rid of those artifacts without any sort of filtering which will make the whole shader heavier.
     
  37. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    So you're saying it's impractical, and therefore "impossible"?

    Edit: I'm sorry, but re-reading your answer I think we are talking about 2 diferent things. To be clear, what I need is a movie with alpha and anti aliasing, to be played as a 2D Sprite, not a 3D environment.
     
    Last edited: Apr 8, 2013
  38. Annihlator

    Annihlator

    Joined:
    Oct 15, 2012
    Posts:
    378
    My guess is that shader is based on alpha testing instead of alpha blending.
    The difference is that alpha testing is more an alpha-cutoff value that's being used.
    (Judging from the pictures posted and looking into the shader source the assumption is correct, but i'm not sure how to modify this shader accordingly)
    your movie does not have anti-aliasing, it has alpha-blending ;)
     
  39. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Thank you for your correction about the terms, I'm not a CG guy so I'm not familiar with these terms. Anyway, do you think it is still possible? This is a very usefull technique for certain types of game and I still can't belive that no one talked about it before :(
     
  40. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    The movie also has anti-aliasing.

    As in, the anti-aliased RGB blends to black at the same rate the alpha does. Whereas the RGB should be solid colour and the alpha should take care of all of that. Net result is you'll get black halos around everything anyway.

    It's worsened because that shader is alphatest, but it won't get fixed easily without fixing the video.
     
  41. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Can you please be more specific? I need to give that info to the graphics guy.

    Anyway, heres the [bird video with alpha side by side] if anyone's interesting to test.
     
  42. 747823

    747823

    Joined:
    Apr 10, 2013
    Posts:
    43
    Alphatest means the pixels of the surface are either 100% transparent or 100% opaque, even if the alpha channel is smooth there is a "cutoff" point in the shader (probably 0.5?) at which it becomes either transparent or opaque. It is never blended with objects behind it. This produces aliasing that is not corrected by MSAA. Your best choice for fixing the aliasing is probably to use an FXAA or similar fullscreen shader. I wouldn't worry about antialiasing the alphatest in the shader.

    For the black edges it is probably because the rgb part fades to black at the same place as the alpha texture fades. Sorry I did not really read the specifics but the color of your textures should extend all the way to the edge even if they are alpha channeled. I.e. if you have a leaf texture with an alpha the cuts out the shape of the leaf, the entire image should be approximately the same color as the leaf, do not put the leaf on a different colored background and think the alpha channel will cut it out, because you will get those artifacts you saw from texture filtering and mipmapping.

    Here, I made an image example:


    I know yours is a movie but the same thing is true of it.

    ---

    And now a request! I hope this is simple enough... I would like a shader that renders transparent "fog" inside of the model based on its actual depth, and can be set to whatever color, and also renders the fog correctly when the camera is inside of it.

    For example example a sphere of this material containing a cube of some other material and no lights in the scene might look like this:


    I'm not sure how difficult this is but actually some of the reason I would want to have a shader like this is to see for myself how it is created. I guess it would just have two parameters: base color and depth scale, but if its surface was also rendered with transparency and reflection it would be very nice for stuff like small pools of water, etc. I was planning to write that part of the shader myself though, but I am pretty new to shader programming and would really like an example of this kind of depth-based shader to understand how to do it.
     
    Last edited: Apr 10, 2013
  43. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368

    You basically need two shaders:
    - First one will render the camera depth as a RT for depth comparison (you can then apply the texture globally to any shader that need it). An other shortcut is to enable depth mode in your camera (if you are using forward rendering) and use the sampler2D "_CameraDepthTexture" already setup globally by Unity. This texture is automatically generated if you are in Deferred Rendering mode.
    Opaque objects in your scene will be rendered twice, If performance is really critical, you probably want to do it yourself and pickup which objects will get rendered (to fill your depth buffer) and then use global shader keywords to set the texture.
    - The second one will describe the mesh surface properties, edge blending (using the depth texture), reflection, diffraction, etc (your water shader mind-you).
    If i get some free time by this week-end I'll work out something for ya. By the mean time, if you got Unity Pro, check out Water4 in Standard Package, it does exactly what I've described. :)
     
    Last edited: Apr 10, 2013
  44. Darkmonk

    Darkmonk

    Joined:
    Nov 3, 2010
    Posts:
    50
    Hi guys, hopefully you can help me with a shader request, I am looking for a layered shader similar to how the terrain blending materials work but i need it to blend using the vertex colours on the object instead of using a texture file.

    Basically I would like to have 4 texture slots A-D and when i vertex paint my object depending on the colour of the vertex the specified texture will be visible, for example if the object is all black in the vertex colours then i want to see texture A BUT where i paint red i want to see texture B and so on. here is a little image to better show what im after
    $ShaderRequest.jpg

    At the moment all textures can use the first UV channel for placement

    Do you know if one already exists like this or is it straight forward to write ? I am an artist so writing a full shader is not possible for me so hopefully somebody knows of one or can help out.

    Thanks
     
  45. SRH

    SRH

    Joined:
    Feb 28, 2011
    Posts:
    160
    It straightforward... try this one View attachment $BlendTexturesByVertex.shader (fixed version)
     
    Last edited: Apr 10, 2013
  46. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hey tatoforever, for some reason the forum didn't warn me about your post. Thanks for the shader, i'll take a look right now :)
     
  47. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Let me know if it works for you! :rolleyes:

    PS: If you got the chance, can you please report this problem to Aurore? I'm also not receiving new updates on subscribed threads.
     
  48. Darkmonk

    Darkmonk

    Joined:
    Nov 3, 2010
    Posts:
    50
    Hi, cool thanks ive given it a test but there seems to be a couple of issues.

    The black and red layers seem to be working fine but the Blue layer is completly black and the green layer seems to be getting added on top of the red one and the brightness is blowing out the textures, here is an image to show the test objects i am using, as you can see the objects on the right are vertex colour only versions of the left ones just so you can compare.

    $ShaderProblem1.jpg
     
  49. Darkmonk

    Darkmonk

    Joined:
    Nov 3, 2010
    Posts:
    50
    $ShaderProblem1.jpg

    for some reason my attachment did not show on the previos post so here it is again, sorry about that
     
  50. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Looks like there's a type on line 36, and the blue and green texture are both being modulated by the green vertex channel. You can fix it like this:
    Code (csharp):
    1. o.Albedo = base * (1-colorStrength) + red * blendFactors.r + green * blendFactors.g + blue * blendFactors.b;