views:

512

answers:

2

As a learning experience, I'm writing an Immediate mode managed DirectX 9 application.

I'm manually calculating Vertex normals across all triangles in a scene to allow smooth Gouraud shading.

This works as expected, but I'm guessing this is not the most efficient approach. Is it possible to get the GPU to do this for me?

+1  A: 

Check this and this.

kek444
Note that these functions do not offload the work to the GPU, they're just helper functions that are all CPU based.
Ron Warholic
Some D3DX functions are horribly slow for some reason.
Virne
+2  A: 

You could in theory generate the vertex normals inside the vertex shader. That involves computation every single time you render a mesh using that shader though, so why not generate them in advance.

If you mean you want to generate them in advance of rendering, but use the GPU instead of the CPU, I would say that it's not worth the bother of speeding up something you are only going to do once. Besides, I'm not sure if DX9 has a way to get computed vertex information back from a shader (DX10 does).

All in all, the best thing to do in most cases is the traditional: compute vertex normals in the program that saves the data files that contain the meshes - do it as a pre-computation step. Usually you have them if the mesh came from a 3d package like Max or Maya, because there is artistic information in the normals, unless you know the whole mesh is supposed to be perfectly smooth (or faceted), it's not computable in the general case.

U62
Perhaps Ash is doing something different than rendering static objects. If geometry is generated or modified per frame, normals must be calculated too. Some marching cubes stuff for example.
Virne
But that usually calls for a custom-fit solution (marching cubes normals can be gotten in different ways for example) - so we'd need some context first if that's the case..
nj