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 jamiller · Mar 20, 2012 at 08:15 AM · shadersuvsuvanimation

Rotating "layer" on a logo

Hello, I've been trying to create this seemingly simple effect for a while now, but I come up short on all the ways I know to solve this. Here is a graphic on what I am trying to achieve:

http://www.distortions.com/work/rotation_problem.jpg (Sorry, can't get the attachment feature to work)

This logo is floating in 3D on a plane or could be made onto an flat oval geometry. The camera is fixed and never moves.

Here are the avenues I've tried:

A) Build an oval plane, have it floating slightly in front of the static logo, rotate the UVs around the center. Problem? I cannot find any way to rotate UVs, even after lots of searching.

B) Build a flat circle plane, parent it to an empty game object, then scale the parent so it affects circle into an oval shape by squashing the Y axis. Now animate the child circle's rotation. The parent will influence it to keep the oval shape while it rotates (like a half filled beach ball rolling). Problem? This works fine inside of Unity Editor when previewing the animation! I thought I had my answer! But when I run the game it no longer keeps the squashed orientation of the parent, but instead rotates the oval as if I was rotating the parent, breaking the effect.

C) Build an additive or transparent shader that has two maps: the starburst UV mapped, and a projected alpha or multiply (white oval on black BG), then I can rotate the object but the alpha wills stay aligned to world up creating the effect I want. Problem? I'm not that advanvanced at writing shaders and can't find any similar examples.

Is the answer in one of these solutions or are there other avenues I could try? I don't want to do an animated texture animation as its intended to rotate slowly and smoothly.

Comment
Add comment · Show 3
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 syclamoth · Mar 20, 2012 at 08:40 AM 0
Share

I'd go with the custom shader option. Look up CG language, see if they have any matrix rotation functions- that should do you.

avatar image syclamoth · Mar 20, 2012 at 08:44 AM 0
Share

Wait, checking up on this. It occurs to me that a rotation is indistinguishable from a translation, when applied to a single pixel. I might have something for you in a $$anonymous$$ute

avatar image syclamoth · Mar 20, 2012 at 08:59 AM 0
Share

I have a shader that does... something. I think my logic is off- it looks cool though! CG shader language has all the tools you need- sin, cos, vector manipulation. I just think I'm going about it the wrong way. I can't keep working on this atm, but here's what I've got so far- maybe it can help you.

EDIT: I've removed the old one, check my answer for the updated finished version!

1 Reply

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

Answer by syclamoth · Mar 20, 2012 at 09:34 AM

Oh my god that was dumb. I made a typo on one of the commands! Here's your shader. Have fun!

 Shader "Custom/Rotate" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _RotatingTex ("Decal (Additive)", 2D) = "black" {}
         _RotateSpeed ("Rotation Speed", float) = 20
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
         sampler2D _RotatingTex;
         float _RotateSpeed;
         
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             float2 posOffset = IN.uv_MainTex - float2(0.5, 0.5);
             float angle = atan2(posOffset.y, posOffset.x);
             float magnitude = sqrt(posOffset.x * posOffset.x + posOffset.y * posOffset.y);
             angle += _Time * _RotateSpeed;
             float2 resultantPos = float2(0.5, 0.5) + (float2(sin(angle), cos(angle)) * magnitude) ;
             half4 base = tex2D (_MainTex, IN.uv_MainTex);
             half4 additiveRotation = tex2D (_RotatingTex, resultantPos);
             o.Albedo = base.rgb + additiveRotation.rgb;
             o.Alpha = base.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }
Comment
Add comment · Show 2 · 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 syclamoth · Mar 20, 2012 at 09:35 AM 0
Share

If you want something that looks unexpectedly awesome, replace 'atan2' with 'float2'. That's the mistake I made earlier...

avatar image jamiller · Mar 20, 2012 at 12:16 PM 0
Share

Wow syclamoth's shader works perfectly! Thank you so much!

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

Triplanar node in shader graph UV map seam for normal map 0 Answers

Unknown input semantics TEXCOORD/4 1 Answer

A Shader to Duplicate and Flip a texture 0 Answers

broken cube after normal extrusion shader 0 Answers

Lightmap options in a 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