Hi,
So I wrote a basic terrain editor. My terrain has a shader which uses normals (NORMAL semantic) to calculate lighting and the texture blending. However, whenever I alter the mesh's vertices's positions manually, then the shader won't update the lighting/texture on the mesh itself until I've completely deleted the mesh and re-loaded it.
Example below.
1. I begin editing the terrain mesh: http://img23.imageshack.us/img23/4955/ss23742013.png .
2. I finish editing my terrain mesh, but the shader won't "update" the mesh. I save the terrain as a heightmap: http://img27.imageshack.us/img27/7295/ss23754945.png .
3. I re-load the terrain scenenode completely from the new heightmap and voila, this is what I see: http://img828.imageshack.us/img828/2070/ss23769729.png .
How would I solve it? I scoured over the forums and I've tried the meshBuffer->setDirty() method and also sceneManager->getMeshManipulator()->recalculateNormals( meshBuffer ) but neither of those seem to work.
Mesh normals not changing or messed up after altering mesh?
-
- Posts: 758
- Joined: Mon Mar 31, 2008 3:32 pm
- Location: Bulgaria
Re: Mesh normals not changing or messed up after altering me
Just a quick guess, but you can try calling
after you`ve altered the mesh in order to force normals recalculation. If it works this way, you can call it only if a key/button was pressed or sth alike, as it may be a bit costly operation to call frequently.
Code: Select all
terrainNode->setScale(terrainNode->getScale());
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Re: Mesh normals not changing or messed up after altering me
Thanks, it worked. It is quite costly. For now I've figured out an alternate (call setScale only once I'm doing editing vertices).
However, why doesn't sceneManager->getMeshManipulator()->recalculateNormals( meshBuffer); work? It doesn't seem to be as costly as setScale.
However, why doesn't sceneManager->getMeshManipulator()->recalculateNormals( meshBuffer); work? It doesn't seem to be as costly as setScale.
-
- Posts: 758
- Joined: Mon Mar 31, 2008 3:32 pm
- Location: Bulgaria
Re: Mesh normals not changing or messed up after altering me
Shortly said, its because it operates the buffer in a bit different way, which in your case doesn`t do what you need as you have discovered yourself. Note that after you edit the vertices you call setPosition() on the terrain to apply the changes to the terrain (you`re using the example from the code snippets), you don`t need to call both setPosition() and setScale() or it will be even slower. If you call setScale() the current frame, make sure you don`t call setPosition() as well, because you don`t really need to.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."