Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can i calculate normals in gpu?

Tags:

c++

gpu

opengl

I have an opengl application that loads a dxf and draws it on the screen, each time i need to calculate normals. is there a way to calculate normals in GPU instead of CPU ? if so how ?

like image 977
ufk Avatar asked Jul 27 '10 19:07

ufk


1 Answers

You can calculate "flat-shaded" (one normal per face) normals from within geometry shader. One for each triangle, "on the fly", using cross-products. You cannot generate "smooth" normals that way, because GS doesn't have info about neighbors.

If mesh is parametric (say, metaballs), normal can be calculated by sampling few nearby function values. This can also be done on GPU.

You can also calculate normals in shader if mesh is based on heightmap or something similar.

IF GPU supports CUDA, OpenCL or something similar, AND if it can process arbitrary arrays of data, then you can probably also compute normals on the GPU, using traditional tehcniques.

Also, I think that 5 years ago (or so) I saw a paper titled something like "normal smoothing on GPU" or "normal generation on GPU". It had a flat-shaded reflective polygonal heart on the first page. Unfortunately, I cannot locate that paper, and I'm not exactly sure if it existed (or where I saw it). You may be able to find it(if it exists) in GDC papers, SIGGRAPH papers, ATI SDK or NVidia SDK.

like image 195
SigTerm Avatar answered Oct 01 '22 16:10

SigTerm