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
0
Question by daniel-eherbert · Apr 02, 2015 at 01:52 PM · shaderrenderingperformancepass

Is a shader with selective passes faster than a single-pass which uses lerp to enable/disable shader effects?

Been messing around with shaders a lot recently, both via code and via Shader Forge.

I noticed that in the standard and image effects shaders that Unity uses multiple shader pass declarations to contain functions of a shader (eg, different methods of blurring for bloom). The pass is then defined in the script which handles the processing.

From Unity's bloom script:

 Graphics.Blit (rtDown4, quarterRezColor, screenBlend, 6);

And part of the relevant shader:

  // 4: nicer & softer "screen" blend mode(cheapest)
 Pass {    
         // ..... snip .....
 }  
  // 5: "add" blend mode (cheapest)
 Pass {    
         // ..... snip .....
  }     
 // 6: used for "stable" downsampling (blur)
 Pass {    
      CGPROGRAM
      #pragma vertex vertMultiTap
      #pragma fragment fragMultiTapBlur
      ENDCG
  }   


Currently I've been achieving similar selective functionality by using Switches in Shader Forge (which essentially boil down to a lerp between two values based on a 0f/1f float you define in the shader parameters).

To (very, very simply) clarify how a switch works by adding a color to a texture:

 //_TheTexture = texture property, value set by material
 //_DoColoring = float, value of 0f or 1f set by material
 float4 frag (VertexOutput i) : COLOR {
     float4 outputColor = tex2D(_TheTexture, i.uv0);
     float4 color = float4(1, 0, 0, 1); //red

     outputColor = lerp(outputColor, outputColor * color, _DoColoring);

     return outputColor;
 }

Obviously that is a very crude example, but the A and B values of the lerp could have any amount of processing behind them.

Are the A and B values of the lerp both calculated if the lerp amount is 0 or 1, or is the alternate value (and processing) completely ignored? Obviously with a value between 0 and 1 both would need to be done...

I suppose there are other benefits to using selective passes (such as handling hardware support, being able to use cheaper versions of processing methods on slower systems, etc), but generally is that approach faster than leaving it all up to the GPU?

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 Tudor · Aug 31, 2015 at 11:40 AM 0
Share

I don't know much about how unity manages shader code at runtime, but I think it's a stretch to think that whenever it sees your_FLAG is 0, it traces back through the code to ignore every path that only writes to that lerp function.

But even if this happened, it would make no sense to think it would be faster than using if statements in the shader. If statements aren't super fast in shaders, but if you can use them to hide more than trivial computations, you should.

I don't know how selective use of shader Passes works (and how fast that is), and am also interested in hearing about it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can the Cull option in shader improve perfomances ? 2 Answers

Alpha channel vs modeled shape performance 0 Answers

Rendering a plane is dropping 10 fps 0 Answers

Low Performance when drawing many objects 2 Answers

uGUI Image without transparency/ opaque render queue 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