How do I adjust individual vertices in the vertexShader

51 Views Asked by At

I want to line up several terrain chunks. These can increase or decrease their resolution depending on where you are. I already have all that. Also that the parts of the terrain fit together, because in javascript I know exactly where which point is. It only gets interesting when I want to bring movement into play. Because I want to do that in the vertexShader because the GPU is much faster than the CPU. The challenge I now face is how do I know in the vertex shader which vertex I have from the geometry? The vertex shader has no information, it simply goes through the vertices one after the other. I guess I'm not allowed to use a setIndex and have to define the vertex order differently so that I then have an array in which I have a separate index for each vertex. In order to then query the edge vertices in the shader, I would need for loops and that would cost a lot of computing power. Does anyone have experience with modulating several adjacent geometry pieces so that the edges always lie on top of each other?

If you line up areas with different resolutions, you have to linearly interpolate the intermediate points on the edges of the higher-resolution area so that they are on the same edge as the lower-resolution neighboring area. At the moment I still have no idea how to get this implemented in the vertex Shader.

I have put a repository on github here for experimentation. If you play with the resolution you change the subdivision of the buffer geometry

enter image description here

https://github.com/Spiri0/chunk

P.S. I uploaded a new version to github. I figured out how to address each vertex in the shader. For this I have created a new index array that I count up with the creation of the geometry vertices. I then pass this as an additional attribute to the bufferGeometry. I have tried to keep it as simple as I can based on my current understanding. I haven't reached my goal yet, but at least I always know exactly at which vertex I'm in the shader.

enter image description here

0

There are 0 best solutions below