Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Niall Mullally · Oct 28, 2015 at 05:55 PM · unity 5shaderrenderingvolumehlsl

Unity5 shaders and loop unrolling

Hi

So Im doing volume rendering in Unity5 and I have a simple ray casting shader, Im able to put the number of loops to ~400 but it takes 10-20 minutes to compile as the shader unrolls the loop. It also times out when trying to increase the max loop count even when specifying [unroll(500)] before the for loop.

Having searched around I havent found a way to prevent this and wondered if there is a way to prevent the shader unrolling.

Theres not much to show in the shader, Just something like below a small for loop in the fragment shader that gets a value from a 3D texture which is then used to colour the pixel

 for(int i = 0 ; i < 50; i++)
 {
     float index = tex3D(_Volume,tempPos).a
     
     //do something with this to get the pixel colour at the current location
     
  }

Any help or insight would be greatly appreciated thanks.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by helarts · Nov 05, 2015 at 12:16 AM

I experienced random compiler issues with a for loop directly in the frag. Try to put it in a separate function and call it in the fragment shader, this way your code compiles in less than 2 seconds with 10000+ samples on my machine.

Edit: I just noticed [loop] before a for loop in a shader made by a colleague, he told me it enables dynamic branching instead of unrolling the loop, might worth a try

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

Answer by Niall Mullally · Nov 05, 2015 at 09:08 PM

Hi helarts Thanks for the reply!, Im affraid that doesnt seem to work,

Looking over the code snippet I stupidly left out the important part, It forces the unroll because apperently loops cant have gradient operations,

So in my for loop, Im trying to use i , each loop which it cannot handle and forces me to unroll

  for(int i = 0 ; i < 50; i++)
  {
      worldpos = start + (i * rayDirection);
 
      float index = tex3D(_Volume,tempPos).a
      
      //do something with this to get the pixel colour at the current location
      
   } 
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

U5 shader coming out solid black on newer iOS devices (iPad 2 Air / iPhone 6) 1 Answer

How to configure shaders? 1 Answer

Render object with different shader depending on the camera 2 Answers

Unity 5 Custom Deferred shader 0 Answers

How to access all the lights in a scene in custom shader? 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