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 ronronmx · Feb 12, 2012 at 10:18 PM · shadertextureanimated-texture

Script vs Shader for animated texture

Quick question...I need to make an animated texture, and I was thinking of using a sprite-sheet and moving the UVs with code, with something like Animating Tiled Texture UVs.

But I was wondering what would be the best way to achieve this, by script like the above, or creating a special shader that basically does the same thing? And what about performance between both methods?

Thanks for any help, and for your time! Stephane

Comment
Add comment · Show 2
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 TheRibboninju · Jul 26, 2012 at 10:04 PM 0
Share

Currently working on an animation shader, I was looking for a free way to animate a texture myself. I will share my shader in the answers once I have a working solution.

According to my experiences, I like doing things using shaders rather than scripts. If you plan to have a lot of of animated textures, I would definitely go with shaders.

I haven't started experimenting with the shader quite yet, but I think you should start looking at http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.GetTexture.html and http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.SetTexture.html. Depending on how you want to do it, you can simply assign the shader a texture every frame, or maybe you could encode all the needed textures into the shader so that it can run it in sequence, which may or may not be faster. (but it sounds pretty fast)

To set a trigger to start and stop animation, or choose what kind of animation, you could probably assign the shader a small texture that acts as data storage, and you could use GetTexture and SetTexture to manipulate that data.

I'm sorry if I'm being very vague with my suggestions, I haven't really touched it quite yet, and I can't really tell you what is and isn't faster without knowing it myself, and only tell you places to start. I'll be back with you when I have more answers.

Also the link to "Animating Tiled Texture UVs" doesn't work at the moment so I can only make out the title of what you have shown me, so sorry if I miss anything obvious.

avatar image ronronmx · Jul 30, 2012 at 06:28 AM 0
Share

Thanks for the suggestions Ribbon! I have been using the "Advanced Animated Tiled UVs" script from the wiki (which is down right now so I can't get the link), and it's been working really good for me. I guess it really depends on each specific scenario...I'll definitively write a shader which animates textures because I know I'll need it at one point or another :)

5 Replies

· Add your reply
  • Sort: 
avatar image
-2

Answer by ScroodgeM · Jul 27, 2012 at 04:19 PM

http://docs.unity3d.com/Documentation/Manual/VideoFiles.html

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 FWCorey · Sep 25, 2012 at 07:37 PM

Wouldn't using a script on multiple instances of the same material create an extra draw call for each instance?

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 ronronmx · Sep 29, 2012 at 05:50 AM 0
Share

That's a good question, I would think that if using shared$$anonymous$$aterial, then no, otherwise, maybe...if anyone can give a final answer on this, it would be very helpful!

avatar image
0

Answer by ShenYuan · Sep 29, 2012 at 07:08 AM

In my point, put uv calculation into the GPU(shader) side may not be a good idea especially when your target platform is mobile or some devices with poor graphic processor.

What's more, calculate uv offset by using "modf(GameTime / Cycle)" can easily cause precision problem when the game need to be played for a long time or "Cycle" is too small. I myself have encountered this problem many many times. But if you made your calculation on the C# side, this gonna be a very very easy problem(just make a private sum time value instead of a global one, and reset it after every "Cycle").

I used to only put animate logic in shader when it happends on ParticleSystem. Because the particle system of my previous graphics engine only provide normalized particle age for each particle vertex. The only and efficient way for me is calculate them in shader.

Keep in mind "switch texture" will cost extra performance. If you have a lot of instanced materials using different texture in one frame, then DO NOT USE Material.SetTexture().

But sprite-sheet have a big disadvantage, all frames of the animation must load at the same time and you can not unload those "Out of sight frame" (because they are stored in one texture). This means a big waste of memory some time.

If you are trying to display a non-loop, long and high resolution animated frames, go for the Material.SetTexture(). Also don't forget use Resources.Unload() to handle the memory issue. Or just simply use VideoTexture(not available on iOS, but u can buy one plugin developed by PRIME31).

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 YoungXi · Jan 02, 2014 at 04:06 AM

Hi, Stephane: I know it has been a long time, but I still want know which one did you use to make the animated and tiled texture, Shader or Script? I already know how to do that with scripts, but I'm dying to know how to make it work also in a Shader. I tried, but it didn't work out well. So I wonder if you know anything, plz let me know :D. Happy new year! Young.

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 YoungXi · Jan 02, 2014 at 04:06 AM

Hi, Stephane: I know it has been a long time since the last reply, but I still want know which one did you use to make the animated and tiled texture, Shader or Script? I already know how to do that with scripts, but I'm dying to know how to make it work also in a Shader. I tried, but it didn't work out well. So I wonder if you know anything, plz let me know :D. Happy new year! Young.

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

10 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

How to automatically apply different textures on terrain based on height? 5 Answers

Difference between TRANSFORM_TEX and MultiplyUV 0 Answers

Double Layer Material 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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