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 numberkruncher · Feb 24, 2012 at 04:57 PM · animationshaderangrybots

How does AngryBots InterlacePatternBlend shader work?

The _Time variable is used to produce the animation, but what is _Time.xx and _InterlacePattern_ST.zw and how does this actually work?

I am also a little confused, how can both xy coordinates be calculated at same time?

Source from AngryBots for reference: #include "UnityCG.cginc"

 sampler2D _MainTex;
 sampler2D _InterlacePattern;
                     
 half4 _InterlacePattern_ST;
 half4 _MainTex_ST;
 fixed4 _TintColor;                
                     
 struct v2f {
     half4 pos : SV_POSITION;
     half2 uv : TEXCOORD0;
     half2 uv2 : TEXCOORD1;
 };
 
 v2f vert(appdata_full v)
 {
     v2f o;
         
     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);    
     o.uv.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
 
     o.uv2.xy = TRANSFORM_TEX(v.texcoord.xy, _InterlacePattern) + _Time.xx * _InterlacePattern_ST.zw;
                 
     return o; 
 }
     
 fixed4 frag( v2f i ) : COLOR
 {    
     fixed4 colorTex = tex2D (_MainTex, i.uv);
     fixed4 interlace = tex2D (_InterlacePattern, i.uv2);
     colorTex *= interlace;
         
     return colorTex;
 }
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 numberkruncher · Feb 24, 2012 at 05:51 PM 1
Share

*NOTE: For some reason this website is adding http:// into the source below ... It is not in the question text! Additionally it seems to be ignoring any edits that I make. I couldn't even add this comment into the question body.

avatar image Jessy · Feb 24, 2012 at 07:05 PM 1
Share

http://answers.unity3d.com/questions/220301/why-do-edits-no-longer-appear-on-this-site.html

1 Reply

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

Answer by Owen-Reynolds · Feb 24, 2012 at 10:00 PM

_Time.xx means two copies of the time, bundled up as a Vector2. So if time is 7.4, then time.xx is (7.4,7.4). The x doesn't mean x-coordinate -- it just goes there. Imagine if you HAD to store your age in a Vector4 named A. The best you could do would be "A.x=age, and uh, ignore y, z and w." (NOTE: I didn't know _Time was built in -- does that work?)

The same way you can add a pair of Vector3's in Unity, graphics cards add side-by-side. The simplified line: uv2.xy += Time.xx; says to add time to uv.x and also to uv.y. This slides the uv coords right and up, which makes the texture move diagonal as you move.

If you took out Time, but added a line below: o.uv.x += _Time.x; then the texture slides sideways. Change to o.uv.y and you get up/down (adding time to the y-tex coord.)

I don't know what the interlace pattern is, but IP.zw says the last two slots. If the interlace pattern was (10, 6, 0.1, 0.7), then IP.zw is (0.1, 0.7) and it would slide the texture 1/10th of a tile L/R and 70% of a tile U/D (based on the unwrap.)

Comment
Add comment · Show 3 · 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 Jessy · Feb 24, 2012 at 10:20 PM 2
Share

About _Time. Your links are broken.

avatar image numberkruncher · Feb 24, 2012 at 11:20 PM 0
Share

Cheers, that also makes several other things a lot clearer. So presumably _AnyFloat4.xyz will return a Float3 where the order can be customised _AnyFloat4.yzx if appropriate. I wondered why many shaders were doing this.

avatar image Owen-Reynolds · Feb 25, 2012 at 05:37 PM 1
Share

Jessy -- aarrg! I typed the letters IP, a dot, then zw and the parser decided to make it look like a link. Testing, do single quotes fix it: IP.zw.

Thanks on time. I use a unity manual page just like yours, but showing only the top half.

$$anonymous$$runch: yes. changing the order is called a swizzle. For example, uv.xy = uv.yx; is a short way to flip x/y tex coords.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamically animating mesh according to heightmap image sequence 1 Answer

Possible to pause a shader? 1 Answer

Need to know when a transition starts in mecanim. 1 Answer

Using a shader to oscillate plant 1 Answer

Replicate CSS3 animation in Unity 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