Created
August 1, 2017 08:13
-
-
Save kodai100/5d0e908af23ff7c25a279b60eadc9a5a to your computer and use it in GitHub Desktop.
Graph Plotting Shader for Unity ShaderLab
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 "Custom/GraphPlotter" { | |
Properties{ | |
_Division("Size", Range(10, 300)) = 0 | |
_Radius("Radius", Range(0, 1)) = 1 | |
_Color("Color", Color) = (0, 0, 0, 0) | |
} | |
SubShader{ | |
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } | |
CGINCLUDE | |
#pragma target 5.0 | |
#include "UnityCG.cginc" | |
int _Division; | |
float _Radius; | |
fixed4 _Color; | |
struct appdata { | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
v2f vert(appdata IN) { | |
v2f OUT; | |
OUT.pos = UnityObjectToClipPos(IN.vertex); | |
OUT.uv = IN.uv; | |
return OUT; | |
} | |
// x = ?y | |
float plotXFunc(float2 uv, float pct) { | |
return smoothstep(pct - 0.02, pct, uv.x) - smoothstep(pct, pct + 0.02, uv.x); | |
} | |
float plotYFunc(float2 uv, float pct) { | |
return smoothstep(pct - 0.02, pct, uv.y) - smoothstep(pct, pct + 0.02, uv.y); | |
} | |
fixed4 frag(v2f IN) : SV_Target{ | |
float2 uv = IN.uv; | |
/*float x = -4 * 0.2 * pow(uv.y - 0.5, 2) + 0.5 + 0.2; | |
float res = plotXFunc(uv, x);*/ | |
float y = smoothstep(0, 1, uv.x); | |
float res = plotYFunc(uv, y); | |
return fixed4(res * _Color.rgb, _Color.a); | |
} | |
ENDCG | |
Pass { | |
Blend SrcAlpha OneMinusSrcAlpha | |
Cull Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment