View Full Version : Register Combiner code prob

02-06-2002, 07:37 PM
was just browsing through the Opengl SDK and came accross this:

" rgb {\n"
" spare0 = expand(col0) . expand(tex0);\n"
" spare1 = expand(col1) . expand(tex0);\n"
" }\n"
" rgb {\n"
" spare1 = spare1 * spare1;\n"
" }\n"
"final_product = spare1 * spare1;\n"
"out.rgb = spare0 + final_product;\n"
"out.a = unsigned_invert(zero);\n"

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..

02-06-2002, 08:10 PM
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 -

02-06-2002, 08:14 PM
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).]

02-06-2002, 08:56 PM
Great! Thanks for you replies. now i understand http://www.opengl.org/discussion_boards/ubb/smile.gif

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

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

02-06-2002, 09:54 PM
of course it was http://www.opengl.org/discussion_boards/ubb/smile.gif.. don't worry about that http://www.opengl.org/discussion_boards/ubb/smile.gif.. what i meant, is are the bump maps calculated or generated with image processing software?

02-06-2002, 10:05 PM
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.

02-06-2002, 11:22 PM
Thanks! do you have any small demos demonstrating this type of combiners?

02-07-2002, 12:04 AM
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.

02-07-2002, 12:38 AM
my bad.. i tend to say combiners for everything..

Thanks for your help http://www.opengl.org/discussion_boards/ubb/smile.gif

02-07-2002, 12:11 PM

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.


02-07-2002, 01:48 PM
How do you it with a round object? I know you need to unwrap the object, but how do you that exactly?