How it works...

The relevant parameters to draw a circle are its center, radius, and color. They are all available in the shader with the names _Center, _Radius, and _RadiusColor. By adding the worldPos variable to the Input structure, we are asking Unity to provide us with the position of the pixel that we are drawing expressed in world coordinates. This is the actual position of an object in the editor.

The surf() function is where the circle is actually drawn. It calculates the distance from the point being drawn and the center of the radius, and then it checks whether it is between _Radius and _Radius + _RadiusWidth; if this is the case, it uses the chosen color. In the other case, it just samples the texture map like all the other shaders ...

Get Unity 2018 Shaders and Effects Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.