Terrain shape calculation in the vertex shader


I am trying to make a hexagon-based terrain (one hexagon, where currently player is located, is shown at the time), but I faced a few difficulties. Basically, I want to use normal TerrainGrid system and render on the screen only part of a given shape (hexagon) of the terrain. And then, when player moves to the next hexagon, previous one will be discarded and new one displayed.

I started with the following idea:
I took a texture with painted hexagon and by changing texture coordinates and drawing vertices only inside the hexagon (and discarding others) I could partially achieve my goal. But then I faced a problem when hexagon overlaps a few nearly located TerrainQuads, I could not force to draw the texture for different quads with different texture coordinates. Because for the shader doing this there is no indications or identifiers of different TerrainQuads, that I could use for changing texture coordinates.
Then I decided that I don’t need such a texture with the hexagon at all. I simply wrote an algorithm in the vertex shader calculating whether current vertex belongs to the hexagon of a given size or not and I passed hexagon index (in the virtual hexagon grid over the terrain) parameter to the shader from the update loop. And everything was fine until I reached the point where I needed to change hexagon index parameter when player moves to the next one (to see the next hexagon on the screen). Shortly, it simply did not work any more.
As I understand, when I pass the index for the first time, the system calculates 16 TerrainQuads how it should be (4 attached and 12 detached) and it draws my hexagon shape somewhere according to the passed parameter and all other vertices of these 16 quads are discarded. And then, while my hexagon moves within these original 16 quads it will not redraw them.
Maybe I am missing something or doing it completely wrong? (I am not yet advanced with the jMonkey) I will really appreciate any advice which direction I should investigate to overcome my problem and reach my goal.

Thank you in advance.

Well, I think I found the problem, maybe somebody could help me to solve it.

I tried to do the same (the second approach) with TerrainQuad terrain instead of TerrainGrid and it works perfectly. Then I started investigating the implementation of the TerrainGrid and it looks that when you set a material for the root, and then it clones this material for all TerrainQuads (internally), after that your original material (which was set in the main program) is a separate thing with all materials of quads, hence if you change some variable for the main material it obviously doesn’t change it for the cloned.
Is this observation correct? In this case how to avoid this behavior? I need to have access to the materials of the quads. How to get it?

I also found that it is possible to reset the material for the root element every time in the simpleUpdate and this material will be propagated to all quads, but isn’t it bad for the performance? and what if I use different materials for different quads (set them by adding listeners), then all these materials will be redefined by new one from the root. How to get access exactly to the materials of quads and tune variables for some particular quad?

Thank you

Ok, I solved the problem.
TerrainGrid.getChildren() returns visible quads properly, only one thing is important here, it takes a while that children appear in the root’s list, that is why immediately after launching this list is empty.