Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Mortennobel · May 03, 2011 at 07:50 PM · shaderiosspecular

Specular shader on iOS

I'm trying to use the specular shader on iOS to create a Earth object. As texture I have a normal earth surface color in the RGB channel and a specular color in the alpha channel. (I have used the textures from http://learningwebgl.com/blog/?p=1778 ).

In the editor I get the desired effect:

Specular shader in Editor

But when I run the program on my iPad I get much different effect (much more specular):

Specular shader on iOS

I know that there are differences between shaders running different devices. But what is the exact reason why this don't work? And where can I find a detailed description of the differences between the two platforms?

Additional info:

  • I have used a mesh with many polygons (it seems the light are computed in the vertex shader).
  • I have tried to use different image compression methods for iOS, but it didn't change anything
  • I have used Unity 3.3 Pro + iPhone iOS (not Pro)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Peter G · May 03, 2011 at 08:33 PM 0
Share

I don't know if the entire lighting calculation is done in the vertex shader, but it makes sense that the specular highlight is calculated in the vertex shader for performance reasons. I haven't seen the GL ES 2.0 shaders Unity includes yet.

avatar image Mortennobel · May 03, 2011 at 08:41 PM 0
Share

I assumes that Unity uses GL ES 2.0, since GL ES 1.x does not support shaders (only fixed function pipeline). Since I use a highly detailed mesh, it doesn't really matter where the ligth-calculation is done.

avatar image KAKE · Jun 17, 2011 at 03:15 PM 0
Share

I'm experiencing this same phenomenon on iOS. It also is occurring on some Android devices but not others. Droid 2 looks like this, but the Galaxy Tab looks correct.

avatar image equalsequals · Jun 17, 2011 at 03:16 PM 0
Share

You get the same effect in ES2 as well.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by equalsequals · Jun 17, 2011 at 03:31 PM

There is a slight problem with the BlinnPhong lighting model and OpenGLES. If you check the source code of the Mobile shaders, you will see that they provide an alternative lighting model "MobileBlinnPhong".

I was able to isolate the issue to these lines in BlinnPhong:

 inline fixed4 LightingBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
 {
    fixed3 h = normalize (lightDir + viewDir); //normalize light direction added to the view direction
 
     fixed diff = max (0, dot (s.Normal, lightDir));
 
     float nh = max (0, dot (s.Normal, h)); //calculate the dot product of the surface normal and our normalized light+view, then make sure it is no smaller than 0 (black)
     float spec = pow (nh, s.Specular*128.0) * s.Gloss;
 
     fixed4 c;
     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
     c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
     return c;
 }

The mobile version MobileBlinnPhong:

 inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
 {
     fixed diff = max (0, dot (s.Normal, lightDir));
     fixed nh = max (0, dot (s.Normal, halfDir)); //Instead of injecting the normalized light+view, we just inject view, which is provided as halfasview in the initial surface shader CG parameters
     fixed spec = pow (nh, s.Specular*128) * s.Gloss;
 
     fixed4 c;
     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten*2);
     c.a = 0.0;
     return c;
 }

So by comparison we can see that the GPU seems to fumble on the standard BlinnPhong model, and UT's mobile version accounts for and corrects it.

For a quick fix, I suggest that any time you use OpenGLES (either 1.1 or 2.0) use a shader which employs the mobile-safe version of BlinnPhong lighting model as opposed to the standard.

If you need me to I'll go more in-depth, I just wanted to get this out quickly.

Hope this helps!

==

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image numberkruncher · Feb 28, 2012 at 01:37 AM 0
Share

@equalsequals Where can I find the best perfor$$anonymous$$g specular shader for use on iOS?

avatar image krides · Jun 11, 2012 at 10:02 AM 0
Share

Hey, I'm sorry for a noob question, but how (where) do you implement this code? I am really new to shaders and only a little familiar with ShaderLab, but it doesn't look like ShaderLab code to me. Oh and I'm having the same issue. Here's my shader code: http://pastebin.com/NhXfskDq

avatar image
0

Answer by ilya_ca · Nov 16, 2012 at 07:19 AM

Another great solution would be to create a specularity look-up table as described in here: http://aras-p.info/blog/2011/02/01/ios-shader-tricks-or-its-2001-all-over-again/ It gives per-pixel specularity without the performance hit.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Specular Shader On Lightmapped Objects [iOS] 1 Answer

Adding Spheremap reflection and Gloss/Shininess controls to a Sruface Shader 0 Answers

Specular bug on iOS/Android using Standard shader 2 Answers

MovieTexture on iOS 0 Answers

Why does specular highlight ignore vertex position? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges