🔒 Locked
radiosity again
Advertisement
Original Post
hi! a have trouble - don't work.... how a do it?... ////////////////// main for(;;) // for(int g=0;g<1000;g++) { float rad = Radiosity(i,llumels,LightmapSequencelist); if(rad<0.001 && rad!=0.0) break; } /////////////// float Radiosity(int cur,vector &vertices,LightSequence* LightmapSequencelist) { // out->Insert("Getting max radiance\n"); int max = MaxRadiance(vertices); // out->Insert("found %i\n",max); float rad = MAX(vertices[max].emitColor[0], MAX(vertices[max].emitColor[1], vertices[max].emitColor[2]) ); // out->Insert( "Distributing energy\n"); DistributeEnergy(cur,max, vertices,LightmapSequencelist); //cout << "Calculating color" << endl; //CalcColors(Polygoner, vertices); // max = MaxRadiance(vertices); return rad; } #define MAX(a,b) a>b?a:b int MaxRadiance(vector &polygons) { int index = 0; int maxindex = 0; int vecsize = polygons.size(); float brightestEmission = 0.0f; vec3_t zero={0,0,0}; for(index = 0; index < vecsize; index++) { Lumel *b =& polygons[index]; if(VectorIdent(b->emitColor,zero,3)) continue; float thisEmission = b->emitColor[0]+b->emitColor[1]+ b->emitColor[2]; if( thisEmission > brightestEmission) { brightestEmission=thisEmission; maxindex = index; } } //cout << max.length() << endl; // VectorSet(polygons[maxindex].color,255,0,0); return maxindex; } void DistributeEnergy(int cur,int index, vector &polygons, LightSequence* LightmapSequencelist) { Lumel *I = &polygons[index]; int vecsize = polygons.size(); Lightmap *l; for( int i = 0; i; l=&LightmapSequencelist[J->lightmapid].lightmaplist[0]; Shader *s=world->materials.GetShader(l->original_polygon_materialnum); //Determine all the form factors float Fij=FormFactor(I,J); if( Fij<=0.0f ) continue; vec3_t ncol={ //(s->surfaceColor[0]/255.0f), //(s->surfaceColor[1]/255.0f), //(s->surfaceColor[2]/255.0f) 1,1,1 }; // The energy received J->color[0]+=ncol[0]*I->emitColor[0]*Fij;//*(I->original_area/J->original_area); J->color[1]+=ncol[1]*I->emitColor[1]*Fij;//*(I->original_area/J->original_area); J->color[2]+=ncol[2]*I->emitColor[2]*Fij;//*(I->original_area/J->original_area); J->emitColor[0]+=ncol[0]*I->emitColor[0]*Fij; J->emitColor[1]+=ncol[1]*I->emitColor[1]*Fij; J->emitColor[2]+=ncol[2]*I->emitColor[2]*Fij; // J->color[0]=fabs(Expose(J->color[0],10)); // J->color[1]=fabs(Expose(J->color[1],10)); // J->color[2]=fabs(Expose(J->color[2],10)); // J->emitColor[0]=fabs(Expose(J->emitColor[0],10)); // J->emitColor[1]=fabs(Expose(J->emitColor[1],10)); // J->emitColor[2]=fabs(Expose(J->emitColor[2],10)); // float t=1; // VectorScale(J->color,t,J->color); // VectorScale(J->emitColor,t,J->emitColor); // ClampColor(J->color,255); // ClampColor(J->emitColor,255); // VectorPrint(J->color,3); } } VectorClear(I->emitColor); // float d=0.01; // I->emitColor[0]-=d; // I->emitColor[1]-=d; // I->emitColor[2]-=d; return; } float FormFactor(Lumel *sample1,Lumel *sample2) { float ffactor, dist, angle1, angle2; float dir[3]; // âûõîäèì åñëè ïåðâûé ýëåìåíò óæå "ïîãàñ" if (!sample1->enabled) return 0; if (DotProduct(sample1->norm,sample2->norm) > 0.009f) return 0; // âåêòîð îò ïåðâîãî ýëåìåíòà êî âòîðîìó VectorSub (sample2->pos, sample1->pos, dir); dist = VectorLength (dir); VectorNormalize (dir); // êîñèíóñ óãëà ìåæäó íîðìàëüþ ïåðâîãî ýëåìåíòà è ëó÷îì angle1 = DotProduct (dir, sample1->norm); // âåêòîð îò âòîðîãî ýëåìåíòà ê ïåðâîìó VectorNegateAB(dir,dir); angle2 = DotProduct (dir, sample2->norm); if( angle1 <= 0.0|| angle2 <= 0.0|| dist <= 0.01 ) return 0; //ffactor = angle1 * angle2 * acos(angle2) / (PI * dist * dist + acos(angle2)); ffactor =(( angle1 * angle2) / (PI * dist * dist))*(sample2->original_area/sample1->original_area); // if(ffactor<0) ffactor=-ffactor; return ffactor; } i work with lightmaps! and i have lumels instahead patches! every lumel have area,which calculate from lightmap grid area! For the beginning - here all is correct?
WHAT do you mean by "doesnt work" ?? you should be more concrete if you want help.
...and please use the source tags for code.
...and please use the source tags for code.
oh yeahh.. sorry..
so... if i use radiosity for lightmaps - lightmaps always is quadratical grids!
For the beginning - i can to calculate rad in this case?
so... if i use radiosity for lightmaps - lightmaps always is quadratical grids!
For the beginning - i can to calculate rad in this case?
For the moment, make sure you have your Cornell Box rendered using quadratic patches. THEN, you can start worrying about triangle patches and issues related to them (proper division of big triangles, finding correct size of a triangle patch, texture fitlering issues,...).
So do you have your Cornell Box rendered already ? Are you through calculation of Form Factors, Visibility and Color Mapping ?
Which method do you use ? Progressive Refinement ? Gathering or shooting ?
Please be more specific, your questions are very vague. Telling - "it doesn
And yes, use {code} tags if you`re submitting code.
So do you have your Cornell Box rendered already ? Are you through calculation of Form Factors, Visibility and Color Mapping ?
Which method do you use ? Progressive Refinement ? Gathering or shooting ?
Please be more specific, your questions are very vague. Telling - "it doesn
t work" is pretty easy. Provide us with screenshots whats going wrong.And yes, use {code} tags if you`re submitting code.
I do not use any patches division !
At me all will consist from lightmaps
So it is possible?
And a problem in that:
When I calculate form factor there the area appears! But in a case with lightmaps the area of that? All area of all polygon - or lightmap grid - or lightmap patch quad element area
I do not use while to a component of visibility!
At me all will consist from lightmaps
So it is possible?
And a problem in that:
When I calculate form factor there the area appears! But in a case with lightmaps the area of that? All area of all polygon - or lightmap grid - or lightmap patch quad element area
I do not use while to a component of visibility!
Uff, your English is terrible to understand, but I
BTW, Do you use this Form Factor equation ?
F i,j = ((cosQ * cosR ) / (PI*r2 )) * H i,j * dA j
ll try anyway:
Quote:I do not use any patches division !
So, you are working directly with triangles OR do you have your scene data already divided into patches ?
Quote:At me all will consist from lightmaps
IF I understand you well, you are trying to compute the radiosity values and map them directly into texels in a texture ? Hm, that doesnt seem like a good approach at start since there are many issues that can influence your texel values and I wouldnt complicate it at beginning with textures. Id recommend you start with simple walls all divided into patches (quads) and each patch shall have a color value - it is great for testing because its long before you take into account exposure and stuff that you start seeing first results.
Quote:So it is possible?
Yes, but its uselessly complicated overhead for the radiosity starter.Quote:Do you mean "Differential Area" here ?
And a problem in that:
When I calculate form factor there the area appears! But in a case with lightmaps the area of that? All area of all polygon - or lightmap grid - or lightmap patch quad element area
Quote:So you
I do not use while to a component of visibility
re not checking whether the patch is visible to any other patch ? The only drawback is that you wont get shadows, but theyre not important at the beinning anyway. Besides youll get faster results this way because you won`t waste CPU time with Visibility calculation among tens of thousands of patches.BTW, Do you use this Form Factor equation ?
F i,j = ((cosQ * cosR ) / (PI*r2 )) * H i,j * dA j
sorry for my damned english...
F i,j = ((cosQ * cosR ) / (PI*r2 )) * H i,j * dA j
yes! same...
but if i use lightmaps - what for dA j
F i,j = ((cosQ * cosR ) / (PI*r2 )) * H i,j * dA j
yes! same...
but if i use lightmaps - what for dA j
dA j - you can replace it with area of the patch. Look at it this way : The FormFactor is dimensionless, right ? Since the only obvious dimension in the formula is r2 it can be taken out only by dA j which represents an area too, so in the end there is no dimension in the formula (H i,j is also obviously dimensionless) !
However, it is just approximation based on the fact that your patches are very small, i.e. if imagine a soldier 2 meters high standing beside the wall of same height&width, the wall should be divided into 1024 patches at least. Still, if the opposing patch is very close (i.e. two patches inside a Form-Factor formula are very near each other), you`ll get artifacts. So some experimenting with sizees of patches and distances between light sources and walls is necessary anyway.
However, it is just approximation based on the fact that your patches are very small, i.e. if imagine a soldier 2 meters high standing beside the wall of same height&width, the wall should be divided into 1024 patches at least. Still, if the opposing patch is very close (i.e. two patches inside a Form-Factor formula are very near each other), you`ll get artifacts. So some experimenting with sizees of patches and distances between light sources and walls is necessary anyway.
http://evillgames.nm.ru/R.f.d043.jpg
what do you think about this....
what do you think about this....
thanks..
i try cornell box....:-)
i have lot of problems
1) i don't use exposure
2) red wall color don't reflect on big cube-this is wrong(may be...)
what i must do,that to see red wall reflection on big cube....?
At present, global illumination works not perfect...:-((
rgb values i receive so:
J->color[0]+=I->emitcolor[0]*factor;
J->color[1]+=I->emitcolor[1]*factor;
J->color[2]+=I->emitcolor[2]*factor;
j->color*=reflectance_color;
J->emitcolor[0]+=I->emitcolor[0]*factor;
J->emitcolor[1]+=I->emitcolor[1]*factor;
J->emitcolor[2]+=I->emitcolor[2]*factor;
j->emitcolor*=reflectance_color;
J->color and I->emitcolor - floating falues (0..1)
red wall has reflectance_color == 1,0,0
p.s i see red wall reflections,when I do gamma 300(specially very high)
[Edited by - evillgames on November 8, 2004 1:54:16 PM]
i try cornell box....:-)
i have lot of problems
1) i don't use exposure
2) red wall color don't reflect on big cube-this is wrong(may be...)
what i must do,that to see red wall reflection on big cube....?
At present, global illumination works not perfect...:-((
rgb values i receive so:
J->color[0]+=I->emitcolor[0]*factor;
J->color[1]+=I->emitcolor[1]*factor;
J->color[2]+=I->emitcolor[2]*factor;
j->color*=reflectance_color;
J->emitcolor[0]+=I->emitcolor[0]*factor;
J->emitcolor[1]+=I->emitcolor[1]*factor;
J->emitcolor[2]+=I->emitcolor[2]*factor;
j->emitcolor*=reflectance_color;
J->color and I->emitcolor - floating falues (0..1)
red wall has reflectance_color == 1,0,0
p.s i see red wall reflections,when I do gamma 300(specially very high)
[Edited by - evillgames on November 8, 2004 1:54:16 PM]
That is, i don't see red wall reflections because i don't use exposuring?
First of all, this "red wall reflection", as you call it, is called Color Bleeding. As such, it is visible only after very many iterations. It is a subtle effect visible when almost all energy has been distributed. Try making more iterations than you do now. I don
[Edited by - VladR on November 10, 2004 5:24:51 AM]
t know what your threshold currently is when you stop distirbuting/shooting energy, but try to make it around 92% - 99% - i.e. you stop distributing energy when about 95% of original energy in scene has been distributed (92% should be enough for Cornell Box actually). Sure it may take a day to calculate it (depending on your CPU/RAM), but then you should be able to see the color bleeding.
Also, if you dont use exposure, it might be problematic to see the effects of Color Bleeding too. How are you currently mapping Energy vales of patches into RGB Values ?[Edited by - VladR on November 10, 2004 5:24:51 AM]
rgb values i receive so:
J->color[0]+=I->emitcolor[0]*factor;
J->color[1]+=I->emitcolor[1]*factor;
J->color[2]+=I->emitcolor[2]*factor;
j->color*=reflectance_color;
J->emitcolor[0]+=I->emitcolor[0]*factor;
J->emitcolor[1]+=I->emitcolor[1]*factor;
J->emitcolor[2]+=I->emitcolor[2]*factor;
j->emitcolor*=reflectance_color;
J->color and I->emitcolor - floating falues (0..1)
red wall has reflectance_color == 1,0,0
-------------------------------------------------------------
after, when i write this in lightmap i do:
void WriteImage(Lightmap *l,int Width,int Height)
{
l->m_lm = new unsigned char[Width * Height * 4];
for(int iX = 0; iX < (Width * 4); iX += 4)
{
for(int iY = 0; iY < Height; iY += 1)
{
l->m_lm[iX + iY * Height * 4] = (char)(l->lumels[iX / 4][iY].color[0]*255); // Red
l->m_lm[iX + iY * Height * 4 + 1] = (char)(l->lumels[iX / 4][iY].color[1]*255); // Green
l->m_lm[iX + iY * Height * 4 + 2] = (char)(l->lumels[iX / 4][iY].color[2]*255); // Blue
l->m_lm[iX + iY * Height * 4 + 3] = 255; // Alpha
}
}
}
-----------------------------------------------------
l->lumels it's a I and J(see above)
J->color[0]+=I->emitcolor[0]*factor;
J->color[1]+=I->emitcolor[1]*factor;
J->color[2]+=I->emitcolor[2]*factor;
j->color*=reflectance_color;
J->emitcolor[0]+=I->emitcolor[0]*factor;
J->emitcolor[1]+=I->emitcolor[1]*factor;
J->emitcolor[2]+=I->emitcolor[2]*factor;
j->emitcolor*=reflectance_color;
J->color and I->emitcolor - floating falues (0..1)
red wall has reflectance_color == 1,0,0
-------------------------------------------------------------
after, when i write this in lightmap i do:
void WriteImage(Lightmap *l,int Width,int Height)
{
l->m_lm = new unsigned char[Width * Height * 4];
for(int iX = 0; iX < (Width * 4); iX += 4)
{
for(int iY = 0; iY < Height; iY += 1)
{
l->m_lm[iX + iY * Height * 4] = (char)(l->lumels[iX / 4][iY].color[0]*255); // Red
l->m_lm[iX + iY * Height * 4 + 1] = (char)(l->lumels[iX / 4][iY].color[1]*255); // Green
l->m_lm[iX + iY * Height * 4 + 2] = (char)(l->lumels[iX / 4][iY].color[2]*255); // Blue
l->m_lm[iX + iY * Height * 4 + 3] = 255; // Alpha
}
}
}
-----------------------------------------------------
l->lumels it's a I and J(see above)
Obviously you are just remapping 0-1 (float) range into 0-255 (int) range. Try using some form of exposure. There was one thread here lastly eabout exposure functions about a year ago. Google it. BTW, range 0-1 is very bad from the accuracy standpoint, because you are cumulating floating-point inaccuracies from very first distribution. Use larger values (0-100, or 0-1000) range to partly compensate for floating point inaccuracies.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement