normal of a triangle of a skinned animated mesh

Blitz3D Forums/Blitz3D Beginners Area/normal of a triangle of a skinned animated mesh

RemiD(Posted 2013) [#1]
Hello,

Do you know if the normal of a triangle of a skinned animated mesh is recalculated each frame ?
I guess that yes because some vertices may change their positions and thus the triangle will change its shape and its orientation.

So i guess that there is not point to try to precalculate the normals of the triangles of a skinned animated mesh because i will need to recalculate it each frame if the mesh is animated (most of the time it is...)

I will do some tests, but if you know, please let me know.

Thanks,


RemiD(Posted 2013) [#2]
Another question related to the previous one please :

If a mesh is not skinned, not animated, but its orientation changes, then all the normals of all the triangles have to be recalculated even if the mesh has not changed its shape ?

I am not sure, on one side i think that the normals of the triangles of the mesh have not changed locally but globally they have, and for vertex lighting, it is important to consider this.

I ask this because i am trying to create a custom vertex lighting system.

Thanks,


Yasha(Posted 2013) [#3]
Do you know if the normal of a triangle of a skinned animated mesh is recalculated each frame ?


Triangles don't have normals (as far as the engine is concerned - obviously a mathematical one exists); normals are a property of vertices. The vertex normals are internally translated and rotated for lighting in exactly the same way as their positions.

Since there's no way to get the calculated vertex position and normal out of the system again, this is pretty much meaningless info - you'll need to manage the skinning yourself in Blitz code if you want to keep track of vertex positions in order to work out the triangle normal.


If a mesh is not skinned, not animated, but its orientation changes, then all the normals of all the triangles have to be recalculated even if the mesh has not changed its shape ?


1) as above, triangles do not have normals

2) recalculating a vertex's global normal vector for lighting purposes is one of the things that's done entirely in hardware. You give DirectX a mesh with local normals and tell it the mesh's orientation in global space, and it does the magic itself (exactly the same as it would for vertex position). The global normal vectors (and vertex positions) never even exist on the CPU.

This also means that doing this in software might incur a major performance penalty, since it's something the system wasn't doing before.


I'm not sure I really understood the questions but you might find what you're looking for by browsing through the code of an existing engine: miniB3D should show you how to recalculate vertex position and normal data (or you could look at bOGL, which is simpler but still demonstrates lighting and skinning).

If you want to do anything particularly exotic with the lighting, you may need to work with an engine that lets you use vertex shaders, though.


RemiD(Posted 2013) [#4]
Thanks Yasha, i understand what you mean, my questions should have been about vertices normals instead of triangles normals.


The vertex normals are internally translated and rotated for lighting in exactly the same way as their positions.


As i understand, a vertex normal is recalculated depending on its vertex position and depending on the position of the other vertices composing the triangles which use this vertex.
So the vertices normals of a skinned animated mesh will have to be recalculated each frame. Ok.




recalculating a vertex's global normal vector for lighting purposes is one of the things that's done entirely in hardware. You give DirectX a mesh with local normals and tell it the mesh's orientation in global space, and it does the magic itself (exactly the same as it would for vertex position). The global normal vectors (and vertex positions) never even exist on the CPU.


Ok that's what i thought. The global vertices normals are calculated by the Blitz3d engine. (or by Direct3d ?)



Another question please :
If i use Minib3d, is there a way to change the way each normal is calculated and how the light affects each vertex ? I mean to modify the instructions of OpenGL so that the OpenGL always calculates the vertex lighting this way (like if i wa able to modify how Direct3d calculates the vertex lighting).
I guess that Minib3d uses the same lighting equation than Blitz3d ?

Thanks,


Yasha(Posted 2013) [#5]
If i use Minib3d, is there a way to change the way each normal is calculated and how the light affects each vertex ? I mean to modify the instructions of OpenGL so that the OpenGL always calculates the vertex lighting this way (like if i wa able to modify how Direct3d calculates the vertex lighting).


There are some things you can change. Since miniB3D (like B3D) does its skinning in software, you can change te way bones affect vertices, for instance. There are several different lighting formulas for you to use too.

This depends a huge amount on what you want to achieve though. OpenGL 1.1 is like DirectX7: fixed pipeline only. You can do some imaginative things by moving vertices around but it's fundamentally quite limited. For a truly different lighting engine you'll still need to be able to use shaders, which aren't made available in miniB3D either.

E.g. Using miniB3D, you can change the way bones scale normals or where they point; using shaders, you can ditch the concept of a normal altogether and use something completely different to control your lighting.


RemiD(Posted 2013) [#6]
I want to finish a complex 3d game with Blitz3d first, so i guess i will have to play with vertex normals and vertex colors to achieve the lighting i want.

But then i will have to take a look at shaders.
Thanks for the infos, :)