[SOLVED]Accessing Vertex Normals in Hardware Buffer

Rowan

14-03-2007 03:37:30

I tried this question in the main forum, but was told I should ask here, even though the 'vertexnormals' option is part of the TSM. Here is the link to that post :: http://www.ogre3d.org/phpBB2/viewtopic.php?t=29711

My question was ::

if it's possible to access the normal values set by the scene manager when the 'vertexnormals=yes' option is set in the config file.

I'm not an expert programmer so hopefully I'm not misunderstanding what this means, but I'm assuming there are 3 values per vertex stored somewhere representing a Terrain normal at that point ( usually used for lighting I assume ).

I'd like to access them and most likely just copy them to a buffer of my own to then manipulate for pathfinding.

Is this possible, and if so, I was hoping someone could help me with the actual code that would be required as I have little idea about hardware buffers.

Thanks


Sinbad pointed me to a wiki entry here ::
http://www.ogre3d.org/wiki/index.php/RetrieveVertexData, which was useful in some respects, but I am still none the wiser on how to access the normals as opposed to the vertexes & indexes.

Do the PLSM2 terrain entity meshes have an extra public attribute for normals? or am I completely off track?

I was planning on using this to save duplicate normal calculations for pathfinding over terrain, but I'm also thinking it would just be useful for any sort of pathfinding on a mesh.

If anyone knows how to do this I'd be much appreciated if you could give me a few pointers.

Thanks.

nindim

14-03-2007 03:55:55

I dont know if you can access the normals, but you could just calculate your own normals once you have the vertex/index information. Thats what I did in building my obj exporter for terrain tiles and it works nicely.

Rowan

14-03-2007 04:19:09

I'm actually currently calculating them from the heightmap file itself ( as a preprocess step), and was considering what you suggest as the next run-time step, but I remembered the vertexnormals option in the config settings, so I am assuming they are already calculated and stored somewhere.. or guessing really :)

So it would seem quicker to save a duplicate calculation if possible.

nindim

14-03-2007 10:58:50

I'm sure they probably are stored somehwere, probably wouldnt be too hard to retrieve them (with slight modifications to the PLSM2), buth then again, dont ask me to do it ;) I think Falagard used the vertex normals calculated by the PLSM2 for his plsplattignshader. Maybe u could take a look at his shaders and see. I dont think its really possible to get both vertex and index data as well as calculate normals at run time (at a reasonable speed), especially not at LOD0 (the only one the normals are realy valid at anyway for lighting etc). You'd probably be better still doing it as a pre process offline and storing then just loading in when needed.

Rowan

14-03-2007 12:05:23

I think you're probably right, it is seeming like a bit of a long shot. Maybe I can have a look back again at a later stage..

Thanks for the input!

syedhs

15-03-2007 05:54:42

Okay if I were you, I will do the followings:-

1) Replace VES_POSITION as in the wiki code with VES_NORMAL - therefore, instead of you retrieving the vertices, you are retrieving the normals.
2) Make sure that in your terrain.cfg, the the VertexNormal is set eg:-

VertexNormals=yes

Rowan

15-03-2007 09:19:38

I see, .. I completely missed that, thanks very much.

Now to figure out how to put it all together. :)

nindim

15-03-2007 09:31:51

Cool, I didn't know about that. Think you'd definately have to run it once, store them somehwere and just reference that. Woudla ssume that getting the normals along with the indices will take roughly the same time as the vertices + indices. All you can do is try it out though.

Could have saved myself a bit of grief it I'd known about this, I went and calculated them all myslef ;)