- Home /
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.
I'd go with the custom shader option. Look up CG language, see if they have any matrix rotation functions- that should do you.
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
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!
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"
}
If you want something that looks unexpectedly awesome, replace 'atan2' with 'float2'. That's the mistake I made earlier...
Wow syclamoth's shader works perfectly! Thank you so much!
Your answer
Follow this Question
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