Skip to content

Instantly share code, notes, and snippets.

@wonkee-kim
Last active November 10, 2023 03:36
Show Gist options
  • Save wonkee-kim/c4f84a2c2b6b9965f87748c43620155b to your computer and use it in GitHub Desktop.
Save wonkee-kim/c4f84a2c2b6b9965f87748c43620155b to your computer and use it in GitHub Desktop.
Glowing Core Shader vertex version
Shader "GlowingEfx"
{
Properties
{
_Color("Color", color) = (1,1,1,1)
_GlowCenter("Glow Center", Vector) = (0,0,0)
_GlowSpread("Glow Spread", float) = 0
_GlowStrength("Glow Strength", float) = 1
_Refraction("Refraction", float) = 1
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
Blend SrcAlpha One
ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float glow : TEXCOORD3;
};
float4 _Color;
float3 _GlowCenter;
float _GlowSpread;
float _GlowStrength;
float _Refraction;
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
v.vertex.xyz += v.normal.xyz * sin(_Time.w*14.218) * 0.001;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
float3 localCamPos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)).xyz;
float3 localViewDir = normalize( localCamPos - v.vertex );
float3 p = v.vertex - localViewDir * _Refraction;
p -= _GlowCenter;
float glow = p.x*p.x + p.y*p.y + p.z*p.z;
glow = _GlowSpread - glow;
glow *= _GlowStrength;
glow = saturate(glow);
o.glow = glow * glow * glow;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
col.a *= i.glow;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment