Open ohlidalp opened 2 years ago
disclamer: I did not read up how flexbodies actually work.
This reminds me a lot of pose animation. You can find a working example of doing them on the GPU here: https://github.com/OGRECave/ogre/blob/master/Samples/Media/materials/programs/GLSL/HardwarePoseAnimationWithNormalsVp.glsl
before each render, the code collects positions of the flexbody nodes and sends them to GPU as a 'constant buffer'
you could use plain uniforms, e.g. uniform vec4 data[150]
and see how the hardware support for that is like.
True hardware constant buffers aka. UBOs aka Ogre shared_params are only available with D3D11 & GL3+. If you want broad hardware support, you will have to use vertex textures.
Note that you can also compute approximated tangents in the fragment shader: https://github.com/OGRECave/ogre/blob/07016dad53787106423087e9aabdb30d35bd4b19/Samples/Media/PBR/pbr-frag.glsl#L122
Presently, flexbody deformation is calculated entirely on CPU and then uploaded to GPU (each frame, even if not seen by camera). This puts enormous load on both the CPU and the RAM->VRAM bandwidth, resulting in bad FPS. Normal mapping is disabled solely to save FPS, otherwise the process of calculating tangents (needed for normal mapping) is the same thing as calculating the vertex positions. But the tangents would be additional 3x4 bytes per vertex and the performance impact would be too big.
This is how the system works:
How it could work entirely on GPU (i'm 99% sure):
PROS:
Cons: