Question about bumpmapping.

I have a list of vertex which are unique, and the each face links to the proper vertex, which means that many faces will share the same vertex. Now I know I have to calculate tangent and binormals, is there any problem with my structure? Can I share store the binormal and tangent with the vertices or do I need one tangent per vertex of every single face?

Just treat them the same way you treat normals. That is, if the angle between connected faces exceeds a certain ‘sharpness’ threshold you must duplicate the vertex in order to get 2 distinct normals to show this sharpness. Otherwise, just average up all the surface normals of the faces that share the vertex, and while you’re at it average up all the tangents/binormals. Finally though, make sure you go through every vertex and orthonormalise the 3 basis vectors (normal,binormal,tangent) so that they are all perpendicular to each other, otherwise you’ll get problems in the lighting equation. Orthonormalise can be done like this:-
normal = crossprod(binormal,tangent)
binormal = crossprod(normal,tangent)
tangent = crossprod(normal,binormal)

but be aware of bad created model. The worse situation is when the model has one vertex shared between two faces, which dont have sharp edge, and the texcoordinates are maping on every triagel in opposite direction. You get null tangent or binormal . So be aware of this kind problems.

I have also one question about bump mapping. I would like to know your opinion what is better. To precompute binormals and send them to the vertex shader orto compute only tangents and binormals compute in verex shader. I know that it probably depends on final product and hardware, but i would like to know your experience with this.
I have seen many demos and made some test but from these tiny apps I cant tell how it will behave in real application.
Thanks.

It’s just a crossproduct per vertex.
Do it in the vertex shader.

In general, do as much in the fragment shader as possible.

What you can’t do in the fs, do in the vertex shader.

What you can’t do in the vs, precompute.

Computational power is increases at a much more rapid pace than bandwidth; hence, communication is more expensive than computation.

I have always had the best performance doing as much as possible in the vertex shader. Is this not the case on some hardware?

i disagree
doing stuff in the fragment shdaer gives the best visual results, but is generally slower than doing it in the vertex shader and passing the (interpolated) results to the fragment shader.
with various things ive even moved them from the vertex shader to the cpu

Originally posted by bChambers:
[b]In general, do as much in the fragment shader as possible.

What you can’t do in the fs, do in the vertex shader.
[/b]
This is bad advice!

If a calculation is independent of where it is done (vs or fs), than do it in the vs!
If you need high quality and there is a difference, if you do it in the fs, than you are forced to do it in the fs.

I would say:

  1. If you can precompute it, do it on the CPU.
  2. If you can’t precompute it, but can do it in the vs, do it in the vs.
  3. Else, do it in the fs.

In this particular case the thing is, that you might save quite a lot of bandwidth and doing it in the vs is not expensive, so in this case you might want to do it in the vs, instead of precomputing it.

Jan.

Originally posted by Jan:
[b] [quote]Originally posted by bChambers:
[b]In general, do as much in the fragment shader as possible.

What you can’t do in the fs, do in the vertex shader.
[/b]
This is bad advice!

If a calculation is independent of where it is done (vs or fs), than do it in the vs!
If you need high quality and there is a difference, if you do it in the fs, than you are forced to do it in the fs.

I would say:

  1. If you can precompute it, do it on the CPU.
  2. If you can’t precompute it, but can do it in the vs, do it in the vs.
  3. Else, do it in the fs.

Jan.[/b][/QUOTE]Note the “In general,” :slight_smile:

You are, of course right; when the result of a computation is independant of location (ie, the same result would be obtained by any fragment, anywhere), then precompute and pass it as a uniform to the vertex shader. Or, optionally, as a per-vertex piece of data.

So, I would revise the above to be:

  1. Calculations that are independant of the surface location may be precomputed on the CPU and passed as uniforms to your GLSL proggy.
  2. Everything else should be done in the fragment shader for quality.
  3. If you must sacrifice quality to improve the rendering speed, look for calculations that can be done in the vertex shader. While improving your speed, bear in mind that this will also affect the visual quality.

…Chambers