You know it's kind of funny, i posted the same thing on Feature Requests 3 or 4 years past.
gekido said a few things to me about the impossibility of this...in the end he was right - The original engine wasn't supposed to do this and so this would eat the performance.
I had an approach that would use kind of static shadows which are then computed by the sin/cos of a triangle and so forth...(work a bit like stencil shadows). However, i couldn't program it so the idea was dropped.
Doing it the way the engine normally handles kills every bit of performance we once had:
The main problem, like said above, would be speed - You cannot simply alter all lightmaps or vertex colors of a map at one time and think that it doesn't have any efect on the framerate.
Think of it like that: the SunLight-Entity is mainly precomputed lighting. Recomputing the lighting of the whole level every frame takes a whole lot of work...
But i have a different approach now. But warnings: It may be really slow.
You could do it that way (rendering of one single triangle):
First you have to get the 'angles' of the triangle.
Then you calculate the difference between the angles of the Sunlight and the triangle. These will be the angles for the light.
If one of these angles is smaller than 0, drop the triangle.
If one of these angles is greater than 180, drop the triangle.
These are speed optimizations and also prevent that the other sides of the triangles get darker afterwards then they were before.
You divide each of the angles by 180 and multiply the angles with each other(x*y*z) (alternate you can also multiply them first and then divide the value gotten by 5832000, which is the same, because 5832000=180*180*180; this is also faster)
Afterwards you multiply the now gotten value by 2Pi. This is because of math because 2Pi represents 360 degrees in when you take the sin(), cos() or tan() of something;
Then you take the sin() of this value to interpolate the value.
You multiply this value with a set value (aka the brightness of the SunLight) and add it to all three vertex colors in order to brighten the face.
Or you port the engine to DirectX9 and use directional lights.
Pseudo code: (This is ALL pseudo code, i don't have any clue how the engine does this. Some poeple understand things better if they are written in c/c++...)
Code: Select all
#define X 0
#define Y 1
#define Z 2
float triangle_angles* = GetTriangleAngles(&triangle);
float SunLight_angles* = GetSunLightAngles(&SunLight);
float angles[3];
float last_angle;
angles[X]=(*+X)triangle_angles-(*+X)SunLight_angles;
if(angles[X]<0 | angles[X]>180)
return false;
angles[Y]=(*+Y)triangle_angles-(*+Y)SunLight_angles;
if(angles[Y]<0 | angles[Y]>180)
return false;
angles[Z]=(*+Z)triangle_angles-(*+Z)SunLight_angles;
if(angles[Z]<0 | angles[Z]>180)
return false;
//free memory
delete triangle_angles;
delete SunLight_angles;
last_angle=(angles[X]/180)*(angles[Y]/180)*(angles[Z]/180);
//This is when you want to interpolate the value geometrically, leave it
//out if you don't need this. It is then interpolated linear.
last_angle=sin(last_angle*M_2PI);
triangle->vertices[0].color+=ARGB(0,SunLight->GetBrightness(),SunLight->GetBrightness(),SunLight->GetBrightness());
triangle->vertices[1].color+=ARGB(0,SunLight->GetBrightness(),SunLight->GetBrightness(),SunLight->GetBrightness());
triangle->vertices[2].color+=ARGB(0,SunLight->GetBrightness(),SunLight->GetBrightness(),SunLight->GetBrightness());
//do this for every triange in the whole viewort and you are fnished...
And then of course, this has to be added to the SkyDomeEntity also....
Uff i just hope you understood that that was really something to think for me....*headache*
Everyone can see the difficult, but only the wise can see the simple.
-----