Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staggartcreations/Graphics-Raycast
GPU-based raycaster for Unity
https://github.com/staggartcreations/Graphics-Raycast
Last synced: 3 months ago
JSON representation
GPU-based raycaster for Unity
- Host: GitHub
- URL: https://github.com/staggartcreations/Graphics-Raycast
- Owner: staggartcreations
- License: mit
- Created: 2019-05-12T12:38:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-23T12:08:17.000Z (over 1 year ago)
- Last Synced: 2024-07-28T21:46:54.294Z (4 months ago)
- Language: C#
- Size: 10.7 KB
- Stars: 145
- Watchers: 6
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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](https://i.imgur.com/625lQ2s.gif "")
Instructions
------------Call the static function, like you would with [Physics.Raycast](https://docs.unity3d.com/ScriptReference/Physics.Raycast.html):
`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](https://docs.unity3d.com/Manual/class-GraphicsSettings.html). Alternatively, move it into a folder named "Resources".
Limitations
-------
- Not compatible with any Scriptable Render Pipelines (uses SetReplacementShader)
- Does not work with any geometry drawn through `Graphics.DrawMeshInstanced`, as these are outside of the regular render loop.
- Does not work with objects using Unlit or Transparent materials, or other shaders not writing to the depth texture.
- Won't work when called through OnSceneGUI (the active render texture apparently cannot be modified during this stage).**Future improvements**
- Add override function to raycast from a camera's center. This could simply read the depth- and normals buffer and return the result, and would also work with anything rendered manually through the Graphics API. Very useful for a Depth of Field auto-focus function.License
-------MIT License (see [LICENSE](LICENSE.md))