Skip to content

Instantly share code, notes, and snippets.

@inosyan
Last active January 7, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inosyan/94e5e40781346db1d20272e583022d0e to your computer and use it in GitHub Desktop.
Save inosyan/94e5e40781346db1d20272e583022d0e to your computer and use it in GitHub Desktop.
Shader "LightSphere" for Unity
Shader "LightSphere" {
SubShader {
Tags { "RenderType" = "Opacity" }
Cull Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos: SV_POSITION;
float2 uv: TEXCOORD0;
float4 worldPos: TEXCOORD1;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
fixed4 frag(v2f i): SV_Target {
float dist = distance(i.worldPos, _WorldSpaceCameraPos);
dist = int(dist * 10) / 10 / 1000.0;
return fixed4(
i.uv.x % dist / dist,
i.uv.y % dist / dist,
(dist * 100 % 1),
1);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment