Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility for generating geometry from a vertex shader #420

Open
gkjohnson opened this issue Apr 24, 2022 · 3 comments
Open

Add utility for generating geometry from a vertex shader #420

gkjohnson opened this issue Apr 24, 2022 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@gkjohnson
Copy link
Owner

gkjohnson commented Apr 24, 2022

See https://twitter.com/edankwan/status/1518294689400725507

  • render attributes to MRT using 1px points in a grid
  • use primitive id to derive point location
  • provide offset based on previously rendered geometry.
  • wait for render completion with gl query (optionally synchronous)
  • read pixels back from buffer
  • have final geometry
@gkjohnson gkjohnson added the enhancement New feature or request label Apr 24, 2022
@gkjohnson gkjohnson added this to the v0.x.x milestone Apr 24, 2022
@chasedavis
Copy link

chasedavis commented Feb 3, 2023

I was trying to implement Bvh via drei's abstractions and realized that it may not work with a vertex shader driving transformations on the mesh I'm trying to compute bounds for. After some snooping I saw that this issue might be tracking it already. Can I ask if that is the case or if maybe I am going about it wrong?

Screen.Recording.2023-02-03.at.12.24.06.AM.mp4

Basically in my r3f scene I'm shaping it like this demo one:

  useHelper(ref, MeshBVHVisualizer)
...
      <Bvh>
        <Rays>
          <mesh raycast={() => null} ref={ref}>
            <planeGeometry />
            <CustomShaderMaterial />          <---- driving the mesh deformation, scale, and rotation in vertex shader here
          </mesh>
        </Rays>
      </Bvh>

This project is looking really amazing, so hats off @gkjohnson! Is there another approach I can take where three-mesh-bvh is compatible with custom vertex shader in the scene?

@gkjohnson
Copy link
Owner Author

Is there another approach I can take where three-mesh-bvh is compatible with custom vertex shader in the scene?

Unfortunately no - the BVH is built is and queried on the CPU so any vertex transformation dynamically generated on the GPU are inaccessible on the CPU unless its been written to a buffer and transferred back which is what this issue suggests. The only other alternative is to perform all your vertex transformations on the CPU, instead.

If you'd like to work on a class that enables this as a contribution I'd be happy to provide guidance.

This project is looking really amazing, so hats off @gkjohnson!

Thank you!

@CodyJasonBennett
Copy link
Contributor

This is very easy with and possibly the optimal use-case for transform feedback, which captures the primitive assembly of the vertex shader. Can either stay on the GPU like I do here, or be readback onto the CPU. Needs a patch to three to access GPU buffers mrdoob/three.js#26777, or use of GLBufferAttribute.

https://github.com/CodyJasonBennett/gpu-culling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants