Jump to content
  • Advertisement

Archived

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

tcs

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
k, I''ll check your code out and see if I get the idea.
thanks for your time!

Tim

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!