PDA

View Full Version : Question about bumpmapping.



Baggio
04-14-2005, 05:28 AM
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?

knackered
04-14-2005, 05:48 AM
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)

Matt Zamborsky
04-14-2005, 10:02 AM
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.

Trahern
04-14-2005, 11:38 AM
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.

knackered
04-14-2005, 01:08 PM
It's just a crossproduct per vertex.
Do it in the vertex shader.

bChambers
04-15-2005, 07:00 AM
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.

mogumbo
04-15-2005, 07:11 AM
I have always had the best performance doing as much as possible in the vertex shader. Is this not the case on some hardware?

zed
04-15-2005, 11:27 AM
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

Jan
04-16-2005, 03:56 AM
Originally posted by bChambers:
In general, do as much in the fragment shader as possible.

What you can't do in the fs, do in the vertex shader.
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.

bChambers
04-16-2005, 12:16 PM
Originally posted by Jan:

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

What you can't do in the fs, do in the vertex shader.
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.Note the "In general," :)

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