Giter Club home page Giter Club logo

graphics-raycast's Introduction

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

  • 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)

graphics-raycast's People

Contributors

staggartcreations avatar jonny10 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.