I’m new to Unity shaders and I’m using a Unity unlit shader to plot a function of x. For example, y = sin(x). This is very easy with the following code:
float4 frag(v2f i) : SV_Target
{
float4 color = float4(0, 0, 0, 1);
float y = 0.45 * sin(20 * i.uv.x) + 0.5;
float thickness = 0.02;
if (i.uv.y > (y - thickness) && i.uv.y < (y + thickness))
{
color = float4(1, 0, 0, 1);
}
return color;
}
What’s harder is getting the curve to have even thickness. The curve thickness will be thinner when the slope is greater.
I’ve mainly tried to make the thickness variable a function of the slope of the curve with poor results and poor performance. However, I’ve noticed that with Unity Shaders, there’s always a simple trick to these sort of problems. Any recommendations from Shader experts?