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 Essential · Nov 12, 2013 at 12:18 AM · shaderrainanimated-textureangrybots

Possible to pause a shader?

I'm playing with this shader from the AngryBots project, which animates rain splashing onto the ground by moving an animated texture. My game pauses independently from Time.timeScale as I use the timeScale in the menus, so I instead set animated objects to stop. But this is animating inside of a shader — how can I get this to stop?

 Shader "AngryBots/FX/RainSplash" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Intensity ("Intensity", Range (0.5, 4.0)) = 1.5
     }
     
     CGINCLUDE
 
         #include "UnityCG.cginc"
 
         sampler2D _MainTex;
         
         uniform half4 _MainTex_ST;
         uniform half4 _Color;
         uniform half4 _CamUp;
         
         uniform fixed _Intensity;
         
         struct v2f {
             half4 pos : SV_POSITION;
             half2 uv : TEXCOORD0;    
             fixed4 color : TEXCOORD1;
         };
 
         v2f vert(appdata_full v)
         {
             v2f o;
             
             half timeVal = frac(_Time.z * 0.5 + v.texcoord1.x) * 2.0;
             
             o.uv.xy = v.texcoord.xy;
             
             // animation of 6 frames:
             o.uv.x = o.uv.x / 6 + floor(timeVal * 6) / 6;
             
             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);    
             
             o.color = saturate(1.0 - timeVal) * _Intensity;        
             
             return o; 
         }
         
         fixed4 frag( v2f i ) : COLOR
         {    
             fixed4 outColor = tex2D(_MainTex, i.uv) * i.color;
             return outColor;
         }
     
     ENDCG
     
     SubShader {
         Tags { "Queue" = "Transparent" }
         Cull Off
         ZWrite Off
         Blend One OneMinusSrcColor
 
     Pass {
     
         CGPROGRAM
         
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest 
         
         ENDCG
          
         }
                 
     } 
     FallBack Off
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by undead-steve · Nov 12, 2013 at 12:57 AM

On obvious idea would be to pass in a shader param instead of using _Time. Drive the animated shader value with your param and then you can set the param externally from regular code as needed.

Comment
Add comment · Show 4 · 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 Essential · Nov 12, 2013 at 01:34 AM 0
Share

That sounds like a good approach. I'm not too well versed in Shader lingo though. Would I change the following line…

 half timeVal = frac(_Time.z * 0.5 + v.texcoord1.x) * 2.0;

to something like this?...

 half timeVal = _$$anonymous$$yNewTimeValue;
avatar image undead-steve · Nov 12, 2013 at 02:50 AM 0
Share

Yep. Define a property up at the top and a matching uniform in the body of the shader. Use $$anonymous$$aterial.SetFloat("_$$anonymous$$yNewTimeValue", ) to update the time as needed from game code.

Setting params every frame is definitely more expensive than just running off the builtin time value. Its unlikely to be disastrous if you are only doing it for a couple of objects.

avatar image Essential · Nov 15, 2013 at 01:55 AM 0
Share

Working great, thanks! :)

Now I just wish there was a way to print info from a shader to the console so I could see how it's all working…

avatar image undead-steve · Nov 15, 2013 at 06:27 PM 0
Share

You can't do that but you can come up with a debug visualization. You can use #defines to enable or disable parts of a shader, so you could show the real deal or something that was useful for debugging by setting a shader keyword. See the last few posts in this thread

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

17 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

Related Questions

How does AngryBots InterlacePatternBlend shader work? 1 Answer

3D Mesh Deformer in Unity3D 2 Answers

Why does AngryBots `QualityManager` alter shader LOD twice? 0 Answers

Script vs Shader for animated texture 5 Answers

Shaderforge: Tiled animated texture 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