Search Unity

Where is mobile specular shader?

Discussion in 'iOS and tvOS' started by Fourthings, Feb 11, 2012.

  1. Fourthings

    Fourthings

    Joined:
    Feb 15, 2010
    Posts:
    313
    I'm sure this is a dumb question but I can't find an answer, there is a bumped specular but no regular specular shader in the mobile shaders package.

    Where can I find a simple specular shader that will work nicely on iOS? Nothing fancy, just a few pool balls.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There isn't a mobile specular only. But the normal unity spec shader works on mobile - bit slow if you're not careful.

    For pool balls, a spec shader (gloss map shader) isn't the right thing to use. Instead you'd get a much, much nicer effect from a clever cubemap blended in.
     
  3. Fourthings

    Fourthings

    Joined:
    Feb 15, 2010
    Posts:
    313
    Ah ok, well I know pretty much nothing at all about shader development, but I figure today is a good day to start.

    Can you explain what exactly you mean by "a clever cubemap blended in. " And would this tutorial series be a good place to start?
     
  4. Fourthings

    Fourthings

    Joined:
    Feb 15, 2010
    Posts:
    313
    Bump, can anyone be a bit more specific about what Hippocoder was getting at? I've been following that tutorial series and have yet to come across cubemaps.
     
  5. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Cube mapping, from my limited understanding of the concept, is a cube texture (6 sides) where each side captures different information about the environment. (Bottom side holds information about the floor, Right side about right side of room, Top is the ceiling, and so on.) Which can be mapped onto an object and act as reflections of the room.
     
  6. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    I'm glad someone else wants to find this out too!!

    I don't understand why there's so little information on this subject? Hippocoder mentions there's no mobile specular shader but no one answers the obvious question, WHY??

    Are we to think that current gen ios devices can't handle specular? Perhaps even, that ios users simply don't like specular and prefer worlds made up of flat diffuse materials!?
     
    Ruslank100 likes this.
  7. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Nobody made one. I'd make it and sell it on the Asset Store, but Unity doesn't provide the information to do so. Writing your own specular shader is easy; integrating it with the undocumented lighting code is painful.
     
    Last edited: Feb 26, 2012
  8. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    Thanks for the reply Jessy, at least that's cleared things up slightly.

    I guess it does end up asking more questions though. Why don't Unity provide this information? Why haven't they just released a standard one themselves?

    I'm frustrated because specular is so basic from an art sense. Not having a solution for it is just rubbish.
     
  9. Fourthings

    Fourthings

    Joined:
    Feb 15, 2010
    Posts:
    313
    Yeah it frustrated me too as there is a bump map specular in the mobile shaders pack, but no regular specular, I'm no shader writer but I can image it would be a quick and easy edit to convert the bumped spec to a regular spec, couldn't find the source for the bumped spec shader tho.
     
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    They provide what they want to provide. But they say it doesn't run fast enough to be used. :-\

    There is no sense. They lack direction. They provide the dog food but tell us not to eat it. I can only assume it's politics; some group of people with UT is trying to sabotage its usability in order to get something it wants. ;)
     
  11. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    Haha, not fast enough!? What is this 1998? ;)

    Well it sucks and I can't believe more people don't kick up a fuss about it.
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I believe it's because they're too busy to do it, or don't think it's high enough priority. If they had any sense they'd just hire jessy :p
     
  13. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Hmm... I wonder if the mobile bump-specular shader with no normal map texture applied runs the speed of what a mobile specular shader would? It still seems to render fine but I don't know if the shader is ignoring the bumpmapping part of the code or still expensively running through it.
     
  14. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Look, if Unity were to just give me the information I want, about light probes and lightmapping, I'd write this shader, put it on the Asset Store for free, and document it. It just hasn't been worth my time to dig through the nigh-unreadable compiled surface shaders for that. They don't want to concede that GLSL is the way to go on mobile platforms, but they have Shadowgun on their front page. It's discordant.
     
  15. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    This is exactly the problem we're encountering. We're going to have to run a test soon to try and get to the bottom of it. One with all our assets using diffuse, one with them all using bumped spec.

    What makes this so important is that Specular is a necessity not a bonus for the current gen of titles. It's quite frankly ridiculous that it's not properly implemented currently. Hasn't it been brought up at Unity conferences? What have they said about it? Or don't artists go to these things?

    Jessy, have you thought about contacting Unity directly and ask for the information you want? Making it for free would be brilliant but if not I'd still be prepared to pay a reasonable amount for it, say $20. At that price you'd get a lot of takers.
     
  16. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I don't know what "contacting Unity directly" is; what are you thinking? I watch for help; once in a blue moon, we get some really helpful posts from UT developers, the likes of which are unfortunately no longer the norm.
     
  17. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    Well, I mean any contact addresses you can find?
    support@unity3d.com
    answers.unity3d.com
    feedback.unity3d.com

    or how about PM'ing that Robert guy (in thethread you linked to) and asking for the info you need? Or his advice on how you could make a Specular shader given the current restrictions?

    There must be so many devs out there crying out for this shader, it can't be just us? The current iphone/ipads are capable of some eye watering graphics. But without simple shaders like this artists like me can't create them. It is so frustrating!!
     
  18. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    The ramp LUT controls the specular with one directional light.

    You can turn your directional light on or off to create specular light, if you don't want bumpmap, and for faster execution, you can always sorta get rid off the novertexlight, and then have that sort of fake specular light. As far as I can see, this is fastest thing it will go with lightprobe, I wish I can get CG or GLSL shaders to work with probes, but that itself is a trivial at this point with almost no examples on how to take in the probe data.

    Code (csharp):
    1.  
    2. Shader "Mobile/Bumped Specular (with lookup texture and 1 Directional Light)" {
    3. Properties {
    4. _SpecularTex ("Specular Lookup Texture", 2D) = "white" {}
    5. _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    6. _BumpMap ("Normalmap", 2D) = "bump" {}
    7. }
    8. SubShader {
    9. Tags { "RenderType"="Opaque" }
    10. LOD 300
    11.  
    12. CGPROGRAM
    13. #pragma surface surf MobileBlinnPhong exclude_pathrepass noforwardadd halfasview novertexlights
    14.  
    15. sampler2D _SpecularTex;
    16.  
    17. inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
    18. {
    19. fixed diff = clamp(dot (s.Normal, lightDir), 0.0, 1.0);
    20. fixed nh = clamp(dot (s.Normal, halfDir), 0.0, 1.0);
    21. fixed spec = tex2D(_SpecularTex, fixed2(nh, 0.0)).x * s.Gloss;
    22.  
    23. fixed4 c;
    24. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten*2);
    25. c.a = 0.0;
    26. return c;
    27. }
    28.  
    29. sampler2D _MainTex;
    30. sampler2D _BumpMap;
    31.  
    32. struct Input {
    33. float2 uv_MainTex;
    34. };
    35.  
    36. void surf (Input IN, inout SurfaceOutput o) {
    37. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    38. o.Albedo = tex.rgb;
    39. o.Gloss = tex.a;
    40. o.Alpha = tex.a;
    41. o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTex));
    42.  
    43. float3 worldNormal = WorldNormalVector(IN,o.Normal);
    44. o.Emission += o.Albedo*ShadeSH9(float4(worldNormal,1));
    45.  
    46. }
    47. ENDCG
    48. }
    49.  
    50. FallBack "Mobile/VertexLit"
    51. }
    52.  
     
  19. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
    We are always glad to provide you guys with the information you need. First we need to know what's needed though. Could you please point me to the thread where you asked for more info?

    Please feel free to poke us with direct messages if you feel that we have missed an important thread.

    Depending on the type of information the right place for it might be documentation, but some details about inner workings of some systems do not need to be documented, since no one will ever read about them.
    So yeah, once you ask for help in a certain area and we feel that more people can benefit from the answer and it also fits with the type of information that should be in the docs -- we'll put it there.
     
  20. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Going off-topic a bit to follow up what hippocoder says. Remember that Phong-style "specular highlights" were just a hack; an approximation of what is really happening - lightsources being reflected. We now have the ability to quickly render reflections with cubemaps, which will typically look better, especially if you have some nice Fresnel-type falloff depending on viewing angle.
     
  21. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    No. I've forgotten the various times I've brought it up, I didn't have any luck searching here, and I stopped harping on it recently because I was getting no response. The earliest I found myself brining up the topic was July 2010 on the Unity iPhone beta list. Martin Kraus made this whole wikibook, and mentioned on this forum sometime in the past year how he was going to give up on the topic, considering how poorly Unity was supporting his worthy endeavor.

    There are probably few of us who want the information, but if you help us, the rest of the community can benefit. For example, we'll put mobile-targeted shaders on the asset store that will add to Unity's value. Here's some of the stuff, hitherto undocumented, which needs to be:

    How to use "Keywords" and defines, without the obfuscation of surface shaders:
    Code (csharp):
    1. Keywords { "DIRECTIONAL" "LIGHTMAP_ON" "DIRLIGHTMAP_OFF" "SHADOWS_OFF" }
    2. #if defined(SHADER_API_GLES)  defined(SHADER_API_MOBILE)
    unity_LightmapMatrix doesn't work anymore. You didn't tell us, when it switched to the superior unity_LightmapST. The "documentation" for such changes usually presents itself as a warning/error in Unity's console, but for this, we had to delve into compiled surface shaders. Also, why is it the only variable without an underscore before the ST??

    Spherical harmonics/light probes. I can copy/paste/optimize, but I'd love to understand what I'm doing. If the documentation is going to contain non-Unity-specific, but great information, like the Vector Cookbook, then I think a similar resource for spherical harmonics is reasonable to request.

    If by "we", you mean people who target hardware that won't be relevant to this thread for several years. ;)
     
    Last edited: Mar 17, 2012
  22. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    Kuba, I really appreciate you participating in this thread and I'd just like to say 'there will be a lot of people benefiting from the answers you provide Jessy and others like him with'
    I really hope something comes of this thread, as personally, I'm finding it incredibly hard to create artwork with sometimes both hands held behind my back. For example, I don't want to go off-topic but the lack of being able to 'fade out' certain shaders (namely mobile/additive ones for SFX) is another fundamental artist resource which has been taken away from me.
    Anyway, I hope we can keep this thread going with constructive posts and that a proper Mobile/Specular shader (colour editable too!) can soon be created. I was doing this in 1996 so being able to do it now would be greatly appreciated! :)
     
  23. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Hi Kuba, Thanks for taking the bold step forward to address this type of issue.

    When it comes to shaders I'll take all the information unity will provide and then sum. I can understand that Unity may want to minimise the documentation for the sake of clarity. Perhaps an extension to advanced subsection would be a nice compromise. So those that are seeking the information can get to it. Even if its just a list of all keywords and defines it would be a start. Having to search through debug compiled shaders and the unity cginc files is painful and slow. Its hard to search for something when you don't know what its called or if it even exists.

    As for what is the right place for the information. In my opinion the documentation is always the right place. Forums are just too dynamic and misleading. Often the context in which the information was created changes or becomes invalid due to time or future updates ect. A definitive this is how we expect things to work and equally as important this is what we know isn't working is invaluable.

    like Jessy I've been very keen to get right into the inner workings of unitys shader system. Ive hit some brick walls in places Id never thought to have found them. I kept quiet about them except for contacting Unity directly, because I thought publicly describing some of these issues would have been counter productive. I'm very glad to say that many of them were fixed in 3.5. I hope more will be fixed in the next release.

    Often all we are after is enough information to be in the same headspace as Unity itself.
     
  24. gomox

    gomox

    Joined:
    Apr 27, 2010
    Posts:
    100
    Jessy, perhaps you could tell Kuba exactly what information you'd require to make a proper Mobile/Specular shader? What is the information you are currently missing or is it all contained in your last post?

    I agree that all this info should be available in a community wide document but I'm also well aware how long something like that can take to complete. Unless of course Unity would like to make public the relevent sections from their own wiki..?
     
  25. mufasa123

    mufasa123

    Joined:
    May 25, 2014
    Posts:
    3
    Here's a mobile specular shader that I made editing the original specular shader. All I changed was I removed the ability to edit the main color of the material which is common with the other mobile shaders and increases performance. Link: Mobile Specular Shader
     
    Anisoropos, mh114 and WillNode like this.
  26. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    423
    thanks mufasa!, i just tried your shader and it works perfectly.
    and I think you did better to upload that shader to Asset store.
     
  27. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89
    Hi mate can you provide me also the shader because the link is kind of broken now. Thank you