Skip to main content

UvRaycaster

A class in Root.Township, the global namespace.

Finds the UV coordinate on a mesh along a ray by rendering one pixel with a special shader from a hidden camera. Client side; PaintBrush uses it to paint on character cosmetics.

Constructors​

MemberWhat it is
UvRaycaster()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private Camera cameraHidden camera used for the one-pixel render.
private Texture2D copyTo1 by 1 texture the rendered pixel is read into.
private int renderLayerLayer the target renderers are moved to while rendering.
private RenderTexture renderTexture1 by 1 render target for the camera.
private Shader shaderReplacement shader that probably writes UV into red and green and depth into blue.

Methods​

MemberWhat it is
Vector3? Raycast(Vector3 position, Vector3 direction, float distance, params Renderer[] renderers)Moves the given renderers to the render layer, renders along the ray, restores them, and returns the pixel's colour as a vector (null if nothing was hit).
Vector3? Raycast(Vector3 position, Vector3 direction, float distance, IEnumerable<Renderer> renderers, int count)Moves the given renderers to the render layer, renders along the ray, restores them, and returns the pixel's colour as a vector (null if nothing was hit).
Renderer RaycastGetClosest(Vector3 position, Vector3 direction, float distance, out Vector2 uv, params Renderer[] renderers)Checks renderers one by one and returns the closest hit with its UV. Only renders for skinned renderers and doesn't restore their layers.
1 private and internal method
MemberWhat it is
private void Awake()Sets the camera up to render only the render layer into a 1 by 1 texture, and disables it for manual renders.

Used in​

Members of other types that take, return or hold a UvRaycaster: