• 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
0
Question by Imankit · Jul 24, 2013 at 07:02 AM · shaderfpsgraphicsperformancecg

Overlay Effect Shader - Very slow in mobile device

Hey I have written a CG shader for photoshop overlay effect for 3 textures(one base and other two are overlayed on it), it works fine on desktop but in ipad1 and iphone4 the fps is going down to 9-10 fps.. Is there a workaround.. Here is the code-

 Shader "Custom/Overlay" {
     Properties {
         _TexA ("TexA", 2D) = "w$$anonymous$$te" {}
         _TexB ("TexB", 2D) = "w$$anonymous$$te" {}
         _TexC ("TexC", 2D) = "w$$anonymous$$te" {}
     }
     
     SubShader {
         Tags { "RenderType"="Opaque" }
         Pass {
         Lighting Off Fog { Mode Off }
         CGPROGRAM
         
         #include "UnityCG.cginc"
         #pragma vertex vert_img
         #pragma fragment frag
         #pragma glsl_no_auto_normalization
         #pragma fragmentoption ARB_precision_$$anonymous$$nt_fastest
         sampler2D _TexA, _TexB,_TexC;
 
             fixed4 frag( v2f_img i ) : COLOR {
                 fixed4 a = tex2D(_TexA, i.uv);
                 fixed4 b = tex2D(_TexB, i.uv);
                 fixed4 c = tex2D(_TexC, i.uv);
 
                 fixed4 r = fixed4(0,0,0,1);
                 if (a.r > 0.5) { r.r = 1-(1-2*(a.r-0.5))*(1-b.r); }
                 else { r.r = (2*a.r)*b.r; }
                 if (a.g > 0.5) { r.g = 1-(1-2*(a.g-0.5))*(1-b.g); }
                 else { r.g = (2*a.g)*b.g; }
                 if (a.b > 0.5) { r.b = 1-(1-2*(a.b-0.5))*(1-b.b); }
                 else { r.b = (2*a.b)*b.b; }
                 r = lerp(a,r,b.a);
                 r = lerp(b,r,a.a);
                 fixed4 x = fixed4(0,0,0,1);
                 if (r.r > 0.5) { x.r = 1-(1-2*(r.r-0.5))*(1-c.r); }
                 else { x.r = (2*r.r)*c.r; }
                 if (r.g > 0.5) { x.g = 1-(1-2*(r.g-0.5))*(1-c.g); }
                 else { x.g = (2*r.g)*c.g; }
                 if (x.b > 0.5) { x.b = 1-(1-2*(r.b-0.5))*(1-c.b); }
                 else { x.b = (2*r.b)*c.b; }
                 x = lerp(r,x,c.a);
                 x = lerp(c,x,r.a);
                 return x;
             }
             ENDCG
         }
     }
 }


Your answers are very much appreciated.. Thanx

Comment
Add comment · Show 1
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 Imankit · Jul 30, 2013 at 11:13 AM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oijadt · Nov 08, 2013 at 08:17 AM

maybe try to use somet$$anonymous$$ng like t$$anonymous$$s: (a.r > 0.5) ? r.r=1 : r.r=2; instead of ifs intructions that are not effective in shaders.

Thanks for shader sources :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Good resources for learning how to write shaders, Cg, ShaderLab? 4 Answers

Do TEXCOORDS need to be in sequence? 1 Answer

Need help with this Shader; camera Solid color is being rendered on skybox. 0 Answers

Which way to write a shader in Unity is the best? 1 Answer

Shaders problems after moving to URP 0 Answers


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