I am working on a simple terrain demo and I have a 256x256 height-map that stores not only height but also other information, each grid point having 8 floats.
I need this grid available in the video card memory ( so I can create a VBO or smth ).
The most important, in the vertex shader, when drawing the terrain, when getting the x and y ( Z is vertical ) of a vertex in the terrain, I will compute the cell grid in which the x-y point lies and then I need to be able to access in the vertex shader those 8 floats that are stored in the closest grid point of the 256x256 points "height map".
If someone has a suggestion on how to do it, any help is appreciated.
Im not sure if theres a better solution, but you could use a texture array or some other fancy object like that, and have 8 layers of float textures, so you then just sample each layer separately. (maybe theres a RGBA float format so you only need 2 textures?)
thanks for the answer, to make everything more clear, I was using uniforms for this and invoking a vertex shader for each terrain quad that project, in the XY plane, into an original grid location. That was very slow and wasn't taking advantage of the fact that the grid never gets modified.
Do you need full 32-bit float precision for all your data in vertex shader?
As Waterlimon told, you can pack this data to textures and sample in vertex shader (using nearest filtering).
If you only ever need 256x256 terrain you can use float textures. But if you think you will eventually need higher resolutions you should try to pack
at least some data elements into 8-bit RGBA textures to conserve some memory.