system
1
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.
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"
}