- Procedure getLightColor(l:TLight;v,Nor:TglVertex3f;var color:TglVertex3f);
- var
- distance,len,angle:GLfloat;
- tmp:TglVertex3f;
- begin
- if (glPointProduct(glSubtractVector(l.Pos,v), Nor) < 0.0) then
- Nor := VectorNegativ(Nor);
- tmp:=glSubtractVector(l.pos,v);
- len:=glVectorLength(tmp);
- if len > l.density then exit;
- distance:=(l.density-len)/l.density;
- color.x:=color.x+Distance*l.color.x;
- color.y:=color.y+Distance*l.color.y;
- color.z:=color.z+Distance*l.color.z;
- if color.x>1 then color.x:=1;
- if color.y>1 then color.y:=1;
- if color.z>1 then color.z:=1;
- end;
- {$DEFINE SAVE_BITMAPS}
- procedure CalculateLightmap(pol:TPolygon;num:Integer);
- var
- i,x,y:Integer;
- nor:TglVertex3f;
- actualvertex:TglVertex3f;
- actualcolor:TglVertex3f;
- begin
- ...
- for x:=0 to LSIZE-1 do
- for y:=0 to LSIZE-1 do
- begin
- actualcolor.x:=0;
- actualcolor.y:=0;
- actualcolor.z:=0;
- for i:=0 to High(Lights) do
- begin
- actualvertex:=VectorInterpolate(
- VectorInterpolate(pol.face[0].v,pol.face[2].v,y/LSIZE),
- VectorInterpolate(pol.face[2].v,pol.face[1].v,y/LSIZE),x/LSIZE);
- getLightColor(Lights[i],actualVertex,nor,actualcolor);
- end;
- Lightmaps[num].data[x,y].r:=Round(actualcolor.x*255);
- Lightmaps[num].data[x,y].g:=Round(actualcolor.y*255);
- Lightmaps[num].data[x,y].b:=Round(actualcolor.z*255);
- end;
- ...