Register Combiner code prob

was just browsing through the Opengl SDK and came accross this:

nvparse(
"!!RC1.0
"
"{
"
" rgb {
"
" spare0 = expand(col0) . expand(tex0);
"
" spare1 = expand(col1) . expand(tex0);
"
" }
"
"}
"
"{
"
" rgb {
"
" spare1 = spare1 * spare1;
"
" }
"
"}
"
"final_product = spare1 * spare1;
"
"out.rgb = spare0 + final_product;
"
"out.a = unsigned_invert(zero);
"
);

Would someone be able to explain step-by-step on what is happening here? (I know that it uses nvparse and all that, what i wanted to konw was what is actually happening to the texture…

Sure - this is a simple per-pixel lighting equation:

assuming col0 == L, col1 == H, and tex0 == N,

result = dot(L,N) + pow(dot(H,N),4);

Thanks -
Cass

Doh! slow typing. Cass was faster!

It is doing diffuse and specular lighting per-pixel!

So the tangent space light vector is col1(primary color)
the half-angle vector is in col2.

tex0 is your bumpmap.

the expand calls only mean that they are expanding the color [0,1] range to [-1,1] range. It simply does
2*color - 1.

in the first combiner, it dots the light vector with normal at the current point(which gives you diffuse light componenet).
then dots the half angle vector with the bumpmap(which gives you specular light component).

In the second combiner, the specular light component is squared.(if you remember, specular light is pow(n . v, exponent ) )

It is squared in the final_output to give better highlight.

Then the diffuse and specular contributions are added together.

You would then need a second pass to blend base color of your object and you would get per-pixel lighting.

[This message has been edited by Gorg (edited 02-06-2002).]

[This message has been edited by Gorg (edited 02-06-2002).]

Great! Thanks for you replies. now i understand

I’m guessing the textures had to be pre-loaded?

[This message has been edited by robert (edited 02-06-2002).]

of course it was … don’t worry about that … what i meant, is are the bump maps calculated or generated with image processing software?

Yes. You need to provide your own bump-maps.

Use your favorite method.

One good method is to create a very high polygon count object(just use NURBS) and have the modelling package export you a bump map for the object, or, if the modeller you use does not have this option, write your own routine that creates a bump map for the object.

Thanks! do you have any small demos demonstrating this type of combiners?

they are not combiners. You simply write code to load the model and create the bump map.

I am actually not sure how it goes, but some guy where I live made me a bunch of bumpmaps for some models and he said he used an high polygon model to generate it. He uses his own software. I have asked it the algorithm, but never answered.

Since I cannot get a hold of him anymore, I simply take a colored image, turn it to grayscale and add some bumps if needed.

I am trying to find a technique to generate bumps maps from high polygon models, but it doesn`t work well now. I did not search the web enough to say I did not any text, but so far I found nothing relating generating bump maps from polygon models yet.

my bad… i tend to say combiners for everything…

Thanks for your help

Hi

When I should cretae normal maps for doing bumpmapping i would “simply” generate as mentioned abov a highly tesselated vertex grid, similar as rendering terrain. Then you have to calc for each vertex the normal vector. This is the normalized sum of the adjacting face normals.

|—|---|—|
| /|B /| /|
| / | / | / |
|/ A|/ C|/ |
|—*---|—|
| D/| F/| /|
| / | / | / |

/ E / /

When you use 2 triangles to build a cell of your grid you have to build 6 face normals for the trinangles and sum them up.After that divide the sum by the length of the vector.
The face normals of the triangles A …F are for the vertex ‘*’.They are calculated by crossproducting 2 side vectors from each triangle(be aware of correct order/orientation)

Then you have to store them into an image and save it to disc.

Bye
ScottManDeath

How do you it with a round object? I know you need to unwrap the object, but how do you that exactly?