I'm creating a mesh with a custom shader. Within the vertex shader I'm modifying the original position of the geometry vertices. Then I need to access to this new vertices position from outside the shader, how can I accomplish this?
相关问题
- How do shader compilers work?
- OpenGL Shaders. Pass array of float
- debugging webgl in chrome
- How does gl_ClipVertex work relative to gl_ClipDis
- Rotating an Object properly around a pivot point g
相关文章
- Get size of Object3D in Three.js
- Change color of mesh using mouseover in three js
- THREE.Object3D.add: object not an instance of THRE
- MeshLab: How to import XYZRGB file
- How to get OpenGL version using Javascript?
- Why do I need to define a precision value in webgl
- GLSL Shader to convert six textures to Equirectang
- Check a face is upwards/downwards towards mouse di
In lieu of transform feedback (which WebGL 1.0 does not support), you will have to use a passthrough fragment shader and floating-point texture (this requires loading the extension
OES_texture_float
). That is the only approach to generate a vertex buffer on the GPU in WebGL. WebGL does not support pixel buffer objects either, so reading the output data back is going to be very inefficient.Nevertheless, here is how you can accomplish this:
This will be a rough overview focusing on OpenGL rather than anything Three.js specific.
First, encode your vertex array this way (add a 4th component for index):
Storing the vertex index as the
w
component is necessary because OpenGL ES 2.0 (WebGL 1.0) does not supportgl_VertexID
.Next, you need a 2D floating-point texture:
Create an RGBA floating-point texture with those dimensions and use it as FBO color attachment 0.
Vertex Shader:
Passthrough Fragment Shader:
Draw and Read Back: