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 Andrew_Kenady · Apr 24, 2014 at 02:23 PM · shaderfpsperformanceprofilerdrawcalls

Improving custom shader performance?

Hello! I'm having an issue with a custom shader we've written for liquids in our game, and it's becoming a bit of a headache.

alt text

Basically, we've got 3 liquids in our game: Lava, water, and ink. We have a quad set up over the extents of each of our levels which has the liquids shader on it to display that level's liquids. The liquids are rendered based on a render texture from a secondary camera above each level that looks at a specific "liquid mask" layer under the level (Think Super Mario Sunshine style). However, this isn't what seems to be impacting fps...

When I was writing the shader, I kept hitting the 64 arithmetic instruction limit when trying to render all 3 liquids in one pass, so I tried to find a way to split the shader into 3 parts. I eventually found that I could just make multiple 'CGPROGRAM's and use one for each of the liquids. This let me do exactly what I needed to do, but cut our FPS by about 65% on our target platform (mobile).

alt text

I tried adding a "LavaEnabled", "WaterEnabled", etc. property to the shader (which will only compute the surface emission if the value is true) and turning them on and off, but the profiler shows no significant FPS boost. The only thing that seems to get FPS back is to comment out some of the CGPROGRAM blocks in the shader.

Is there a better way to skip CGPROGRAM calls in the shader when unnecessary?
(Edit: Is there a better way to make a multi-pass surface shader than by making multiple 'CGPROGRAM's?)

Why does the liquids mesh take so long to render when math isn't being called in the "surf" function of the shader (e.g. when the "Enabled" values are false)?

I'm a total beginner at shaders, so let me know if I'm doing something stupid! haha. Any help is appreciated.

Thanks in advance!

unity1.png (231.5 kB)
unity3.png (61.4 kB)
Comment
Add comment · Show 5
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 Andrew_Kenady · Apr 25, 2014 at 01:20 PM 0
Share

Any help? Sorry to bump but I've run out of ideas and need some input :(

avatar image deltamish · Apr 25, 2014 at 01:46 PM 0
Share

i dont know too much about Shader writing .But just because you have moved the math part to Cg files doesnt mean it is not being called or optimized.

When ever an object is not enabled unity automatically stopy rendering shader passes for them.

Tip

try to move the math calculation to a Script and use System.$$anonymous$$ath to do the calculation (if posssible of course)

Curiosity what math function have you written Cause if its just a simple render as Lit there are many alternates(Very Very Efficient ones)

avatar image Andrew_Kenady · Apr 25, 2014 at 03:57 PM 0
Share

Well the problem is, even if I'm not doing any math at all, multiple CGPrograms is slowing down the shader. If I just have an empty CGProgram with just an empty "surf" function, it's nearly as bad as one with my math running. Only when I comment out the entire thing does my speed come back. So I guess I need to figure out how I can do a multi-pass surface shader in a more efficient way.

avatar image Ed unity · May 05, 2014 at 04:41 PM 0
Share

Ins$$anonymous$$d of using multiple CGPrograms, use multi_compile:

https://docs.unity3d.com/Documentation/Components/SL-$$anonymous$$ultipleProgramVariants.html

avatar image Andrew_Kenady · May 05, 2014 at 04:48 PM 0
Share

Hmm... That seems like it would work if I were trying to make a shader that could produce any one of the 3 liquids (lava, water, ink), but I'm not sure how I could use that to produce all 3 simultaneously.

0 Replies

· Add your reply
  • Sort: 

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2019.3 LWRP strange Performance Issue on android 0 Answers

Performance load of OnGUI 0 Answers

Alpha channel vs modeled shape performance 0 Answers

Why is there difference in fps and time to render a frame in statistics window and profiler? 0 Answers

Huge "Device.Present" performance hit in profiler 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