Unity Twist Effect Black Hole

 

Unity Twist Effect Black Hole

Shader "Hidden/Twist Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader
{
Pass
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest

#include "UnityCG.cginc"

uniform sampler2D _MainTex;

uniform float4 _MainTex_ST;

uniform float4 _MainTex_TexelSize;
uniform float _Angle;
uniform float4 _CenterRadius;

inline float TriWave(float x)
{
return abs(frac(x) * 2-1 )-0.5;

}
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 uvOrig : TEXCOORD1;
};

v2f vert (appdata_img v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy - _CenterRadius.xy;
o.uv = TRANSFORM_TEX(uv, _MainTex); //MultiplyUV (UNITY_MATRIX_TEXTURE0, uv);
o.uvOrig = uv;
return o;
}

float4 frag (v2f i) : COLOR
{
float2 offset = i.uvOrig;
float t = TriWave(_Time.y * 0.05);
float angle = 1.0 - length(offset / (_CenterRadius.zw*t ));
angle = max (0, angle);
angle = angle * _Angle * t;
float cosLength, sinLength;
sincos (angle, sinLength, cosLength);

float2 uv;
uv.x = cosLength * offset[0] - sinLength * offset[1];
uv.y = sinLength * offset[0] + cosLength * offset[1];
uv += _CenterRadius.xy;

return tex2D(_MainTex, uv) * (1 - abs(angle * 0.5));
}
ENDCG

}
}

Fallback off

}

 

Unity Twist Effect Black Hole

 Unity Twist Effect Black Hole

Shader "Hidden/Twist Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Pass
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float4 _MainTex_TexelSize;
uniform float _Angle;
uniform float4 _CenterRadius;
inline float TriWave(float x)
{
return abs(frac(x) * 2-1 )-0.5;
}
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 uvOrig : TEXCOORD1;
};
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy - _CenterRadius.xy;
o.uv = TRANSFORM_TEX(uv, _MainTex); //MultiplyUV (UNITY_MATRIX_TEXTURE0, uv);
o.uvOrig = uv;
return o;
}
float4 frag (v2f i) : COLOR
{

float t = clamp(TriWave(_Time.y * 0.05), 0.3, 0.8);
float2 offset = i.uvOrig;
float angle = 1.0 - length(offset / (_CenterRadius.zw *t));
float a = angle;
angle += _Time.y;
angle = max (0, angle);
angle = angle * _Angle;
float cosLength, sinLength;
sincos (angle, sinLength, cosLength);

float2 uv;
uv.x = cosLength * offset[0] - sinLength * offset[1];
uv.y = sinLength * offset[0] + cosLength * offset[1];
uv += _CenterRadius.xy;

return tex2D(_MainTex, uv) * (1 - abs(a * 0.5));//(abs(a * 0.5)-1) //black hole
}
ENDCG
}
}
Fallback off
}

 

Combine with NeoOcean in vertex shader

Unity Twist Effect Black Hole

Unity Twist Effect Black Hole

Unity Twist Effect Black Hole

 

 Unity Twist Effect Black Hole

 

inline void Vortex(inout half3 localSpaceVertex)
{
half3 vortexC = mul(_World2Object, half4(_LocalVortex.x, 0, _LocalVortex.z,1)).xyz;
half2 offset = localSpaceVertex.xz - vortexC.xz;
half angle = max(0,1.0 - length(offset / (_LocalVortex.ww)));
half rot = -angle * 6.28;
half rotcos, rotsin;
sincos (rot, rotsin, rotcos);
localSpaceVertex.x = vortexC.x + rotcos * offset.x - rotsin * offset.y;
localSpaceVertex.y += _LocalVortex.y * angle;
localSpaceVertex.z = vortexC.z + rotsin * offset.x + rotcos * offset.y;
}

相关文章:

  • 2021-11-24
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-06-28
  • 2021-09-15
猜你喜欢
  • 2021-10-23
  • 2022-03-04
  • 2021-06-08
  • 2021-05-29
  • 2021-09-16
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案