Home

Awesome

Graphics-Raycast

GPU-based raycaster for Unity which raycasts against MeshRenderers, rather than colliders.

This method requires reading from the GPU to CPU and is much slower, but still has its uses.

alt text

Instructions

Call the static function, like you would with Physics.Raycast:

GraphicsRaycast.Raycast(Vector3 origin, Vector3 direction, out RaycastHit hit, float maxDistance, int layerMask = -1);

Optionally, you can draw a gizmo in a similar manner: GraphicsRaycast.DrawGizmo(bool hasHit, Vector3 origin, Vector3 direction, RaycastHit hit, float maxDistance = 25f, float size = 1f);

For it to work in a build, ensure the GraphicRaycastShader.shader file is in the "Always included shaders" list under Graphics Settings. Alternatively, move it into a folder named "Resources".

Limitations

Future improvements

License

MIT License (see LICENSE)