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 saig · Apr 20, 2011 at 03:21 PM · shaderfor-loopprofile

for loop in shader

How do i use for loops in Unity shaders? I created a shader in RenderMonkey SM3 and now trying to port it to unity but i always get:

Program 'frag_surf', profile does not support "for" statements and "for" could not be unrolled

can some body help?

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
2

Answer by Owen-Reynolds · Apr 20, 2011 at 08:45 PM

Hardware shaders (running on the graphics card) don't have loops in them at all, but they can fake them, which is called "unrolling." For example, if you write:

float4 col = 0;
// combine 4 copies of the texture, shifted slightly over:
for(int i=0; i<4; i++)
  col += tex2D( sampler1, UV + float2(0, i*0.05));
col = col/4; // average all thee

The compiler (or a helpful human -- you) unrolls it into:

float4 col = 0;
// combine 3 copies of the texture, shifted slighty over:
col += tex2D( sampler1, UV);
col += tex2D( sampler1, UV + float2(0, 0.05));
col += tex2D( sampler1, UV + float2(0, 0.10));
col += tex2D( sampler1, UV + float2(0, 0.15));
col = col/3; // average all thee

A software shader (running on the CPU, simulating the graphics card,) runs slower but can do anything, including loops. I assume they are useful for ultra-processed renders.

Comment
Add comment · Show 1 · 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 thegreatzebadiah · Dec 18, 2012 at 11:30 PM 0
Share

Shader model 3.0 supports dynamic loops just fine, this is a Unity bug as far as I can tell, and a damn frustrating one at that. You can bump the shader model up to 4.0 and it will work if your hardware supports it, but AFAI$$anonymous$$ there's no actual limiting factor in the hardware that should prevent it working in shader model 3.0, just Unity being weird.

avatar image
0

Answer by thegreatzebadiah · Dec 19, 2012 at 12:12 AM

add:

 #pragma target 4.0

to the top of the Pass and it should work...assuming your hardware supports shader model 4.0

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

1 Person is following this question.

avatar image

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Any tools for profiling shaders? 1 Answer

Profile does not support "for" statements and "for" could not be unrolled. 1 Answer

Cg and "for" statements, what's the deal? 2 Answers

Shader Graph not showing when included in build? 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