#### Archived

This topic is now archived and is closed to further replies.

# fast Interpolation!

This topic is 6927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi ! I''m doing lightmaps for my engine. I''ve implemented a shadow cast alogrithm. Now I want to put the Labert lighting of OpenGL into my lightmap. I can calculate it for each vertex, but I have problems with the interpolation. I have the world coordinates for my current lumel in the lightmap and I have the normals, world coordinates and normals for each vertex. To do Goraud shadinf I have to interpolate between the three Labert light values for each vertex, I don''t want to calculate the distances with square roots, something that is faster would be good! Any ideas ??? Tim

##### Share on other sites
When I made my 3D engine 4 years ago I used lookup tables for my lighting calculations. This was a must because I had 100% dynamic lights. Unfortunately I don''t remember what formula I used to create this lookup table, but I remember that there was only need for one table. The table can then be used for every distance/angle combination imaginable by indexing into different positions and scaling the output.

If you know your math you should be able to come up with the formula for the lookup table. Otherwise you might be able to persuade me to look it up in my old code.

- WitchLord

##### Share on other sites
Do you have one lookup table per polygon, or one lookup table for the whole world ?

##### Share on other sites
After checking my code I found out that I actually use two lookup tables. Both tables describe the same thing but at different sampling intervals. The tables hold precalculated light intensity based on distance to light centre on polygon plane.

Here's the code for initalizing the lookup tables:

bool InitLightTable(){  int X;  // Allocate memory for the table  LightTable = new float[16384]; // 2^16/sizeof(float)  LightTable128 = new float[16384];  if( !LightTable // !LightTable128 )  {    // Out of memory    return false;  }  // Intensity = E/r^2*Sin(a) ,   Sin(a) = z/r  //  //                sqrt(X)  // Lighted point *-------+  //                 \ / a /  //                   \   / z  //                  r  \ /   //                       * Lightsource (Energy = E/constant)	  // Calculate intensity (E = 1, z = 1)  for( X = 0; X < 16384; X++ )  {    LightTable[X] = (float)(1.0f/((float)X/100.0f+1.0f)/sqrt((float)X/100.0f+1.0f));    LightTable128[X] = (float)(1.0f/((float)X*128.0f/100.0f+1.0f)/sqrt((float)X*128.0f/100.0f+1.0f));  }  // To get a desired light intesity at for example   // X = 10, E = 2 and z = 5, do either of:  //  // I = 2*LightTable[100*10/5^2]/5^2  // I = 2*LightTable128[(100/128)*10/5^2]/5^2  // Success  return true;}

As usual there are a couple of slashes that should be pipes, but I think you can figure out which.

- WitchLord

Edited by - WitchLord on 4/30/00 9:37:17 AM

##### Share on other sites
k, I''ll check your code out and see if I get the idea.

Tim

• 10
• 13
• 52
• 11
• 15