Archived

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

Zimans

Need some optimizing help..

Recommended Posts

I finally got my lighting algorithm working correctly, but it doesn't seem to be the fastest.. I put 5 lights on my map and my framerate dropped to about 28fps... Normally it gets about 75-80 fps or so.. (BTW, this is a 2D app, not a 3D app, but I'm using D3D vertex lighting to draw it) Here's the fragment of code that does the light calculation. // Process Light Sources. EntityList = FirstEntity; while (EntityList != NULL) { // Loop through entities, if they emit light, process them into light map. if ((EntityList->Entity->LightIntensity > 0) && (EntityList->Entity->LightRadius > 0)) { Entity = EntityList->Entity; for (indexY=0; indexY < LMAP_HEIGHT; indexY++) { for (indexX=0; indexX < LMAP_WIDTH; indexX++) { Dist = sqrt (pow(((Entity->X - OffsetX) - (indexX * 32)), 2) + pow(((Entity->Y - OffsetY) - (indexY * 32)), 2)); // if within light radius, calc it. if (Dist < Entity->LightRadius) { // Calc modifier based on radius and intensity. Color = (float)Entity->LightIntensity / 50; Color = Color * ((float)1.0 - ((float)Dist / Entity->LightRadius)); if (Color < 0) Color = 0; // Do Red Value = LightMap[indexX][indexY].Red + (Color * ((Entity->LightColor.Red * 2) - 255)); if (Value > 255) Value = 255; if (Value < 0) Value = 0; LightMap[indexX][indexY].Red = (unsigned char)Value; // Do Green Value = LightMap[indexX][indexY].Green + (Color * ((Entity->LightColor.Green * 2) - 255)); if (Value > 255) Value = 255; if (Value < 0) Value = 0; LightMap[indexX][indexY].Green = (unsigned char)Value; // Do Blue Value = LightMap[indexX][indexY].Blue + (Color * ((Entity->LightColor.Blue * 2) - 255)); if (Value > 255) Value = 255; if (Value < 0) Value = 0; LightMap[indexX][indexY].Blue = (unsigned char)Value; } } } } EntityList = EntityList->NextEntity; } (heh, caught a few obvious ones myself) If anyone can make any suggestions I'd be appreciative. I myself think the sqrt func is the culprit. Any ways to make it faster? -Zims Edited by - Zimans on 7/23/00 3:09:20 PM Edited by - Zimans on 7/23/00 3:16:39 PM

Share this post


Link to post
Share on other sites
It mainly depends on your gfx card and whether it supports lightnig by hardware. Maybe you didn''t activate Hardware Acceleration? If so, you should try again with it enabled, it should increase your fps a bit. Btw, try deactivating vsync, this is often a way to increase framerate as it limits the framerate to the refreshing rate of your monitor, or, in the worst case, to a divid of it (like refreshrate / 2, refreshrate /3 ...)

Hope this helps

pi~

Share this post


Link to post
Share on other sites