Created
July 12, 2021 01:23
-
-
Save partybusiness/f0a8b2063b0ba7768cbea1f37a340f11 to your computer and use it in GitHub Desktop.
Lines shoot into a single point. Inspired in part by an effect from Revolutionary Girl Utena.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/GatheringEnergy" | |
{ | |
Properties | |
{ | |
_LineWidth("Line Width", float) = 1.5 | |
_LineLength("Line length", float) = 10.0 | |
_LengthMult("Length Multiplier", float) = 0.2 | |
_InwardSpeed("Inward Speed", float) = 4.0 | |
_Seed("Random Seed", float) = 0.0 | |
_Slices("Radial Slices", int) = 9 | |
} | |
SubShader | |
{ | |
Tags{ | |
"RenderType" = "Transparent" | |
"Queue" = "Transparent" | |
} | |
LOD 100 | |
Blend One One | |
Cull Off | |
ZWrite Off | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
float _LineWidth; | |
float _LengthMult; | |
float _LineLength; | |
float _InwardSpeed; | |
float _Seed; | |
float _Slices; | |
fixed pythagWidth(float p) { | |
return sqrt(pow(ddy(p), 2) + pow(ddx(p), 2)); | |
} | |
fixed fuzzEdges(float val, float maxWidth, float minWidth) { | |
return smoothstep(maxWidth, minWidth, val); | |
} | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = v.uv; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed2 centreUV = i.uv - 0.5; | |
fixed angle = atan2(centreUV.y, centreUV.x); | |
fixed noandist = length(centreUV); | |
fixed dist = length(centreUV) * _LengthMult + _Time.x * _InwardSpeed; | |
fixed2 uv = fixed2((dist*10)%1, (angle+ 3.14159)/(3.14159*2)); | |
uv.y = (uv.y * _Slices); //number of slices | |
fixed2 widths = fixed2(pythagWidth(dist*10), pythagWidth(angle)) * fixed2(_LineLength,_LineWidth); | |
fixed2 floorUV = floor(uv); | |
uv = uv - floorUV; | |
fixed rand = (floorUV.y + _Seed); | |
fixed2 offset = lerp(0.2, 0.8, fixed2((rand * 73.35)%1, (rand * 123.12 ) % 1));//randomize | |
widths.x = widths.x * lerp(0.6, 1.6, (rand * 2556.14) % 1); | |
fixed2 offUV = abs((uv - offset)); | |
uv = abs(uv - 0.5); | |
fixed2 output = offUV / widths; | |
output = fixed2(smoothstep(1.2, 0.9, output.x), smoothstep(1.2, -0.2, output.y)); | |
fixed val = output.y*output.x*smoothstep(0.45, 0.35, uv.y) *clamp(0.5 - noandist, 0, 1) *2.0; | |
return fixed4(val, val, val, 1); | |
} | |
ENDCG | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment