Major update, all implemented a bit in a hurry, and probably will need bugfixes at some point.

Extended the range of the depth and cdepth parameters as reqested by leope.
Bumpmapping should now be a bit more similar to the Blender render.

Added support for all remaining lightsources in yafray, tried to make use of
as much of the existing Blender parameters as possible.

Blender Lamp: added switch to enable rendering with shadowbuffer ('softlight' in yafray).
All other parameters are similar to the Blender settings, for yafray both the
bias parameter and the shadowbuffer size can be lower than equivalent Blender
settings, since the yafray buffer is floating point. Remember that 6 shadowmaps
are created in this case, so can use quite a bit of memory with large
buffer settings.
When 'ray shadow' is enabled for this lamp type, it is possible to set a light
radius to create a spherical arealight source ('spherelight' in yafray),
when this is 0, it is exported as a pointlight instead.

Blender Spot: as in Blender now supports 'halo' rendering.
Halo spots always use shadowbuffers, so when enabled the buttons for shadowmap
settings will appear. The 'ray shadow' button can still be used to disable
shadows cast onto other objects, independent of halo shadows.
One thing to remember, halo's don't work with empty backgrounds, something must
be behind the spotlight for it to be visible.

And finally, the photonlight:
probably the most confusing (as more things related to yafray), the photonlight
is not a real lightsource, it is only used as a source to shoot photons from.
Since indirect lighting is already supported (and looks better as well)
only caustics mode is supported.
So to be able to use this properly other lightsources must be used with it.
For the photonlighting to be 'correct' similar lightsettings as for the 'source'
light are needed.
Probably the best way to do this, when you are happy with the lighting setup
you have, and want to add caustics, copy the light you want to enable for
caustics (shift-D) and leave everything as is, then change the mode to
'Photon'.
To not waiste any photons, the photonlight behaves similar to the spotlight,
you can set the width of the beam with the 'angle' parameter. Make sure
that any object that needs to cast caustics is within that beam, make
the beam width as small as possible to tightly fit the object.
The following other parameters can be set:
-photons: the number of photons to shoot.
-search: the number of photons to search when rendering, the higher,
the blurrier the caustics.
-depth: the amount of photon bounces allowed, since the primary use is for
caustics, you probably best set this to the same level as the 'ray depth'
parameter.
-Blur: this controls the amount of caustics blur (in addition to the search
parameter), very low values will cause very sharp caustics, which when used
with a low photonnumber, probably lead to only some noisy specks being rendered.
-Use QMC: Use quasi monte carlo sampling, can lead to cleaner results, but also
can sometimes cause patterns.

Since the photonlight has no meaning to Blender, when using photonlights and
switching back to the internal render, the light doesn't do anything, and no
type button will be selected. The lightsource can still be selected, but unless
switching to yafray, no parameters can set.

Apologies to Anexus, I had no time to really do something with your code,
I'll still look at it later, to see if I can improve anything in my implementation.
This commit is contained in:
2004-07-28 22:37:12 +00:00
parent fcd19e73df
commit e9b0238d0c
10 changed files with 331 additions and 73 deletions

View File

@@ -63,6 +63,11 @@ typedef struct Lamp {
/* texact is for buttons */
short texact, shadhalostep;
/* yafray: photonlight params */
int YF_numphotons, YF_numsearch;
short YF_phdepth, YF_useqmc, YF_bufsize, YF_pad;
float YF_causticblur, YF_ltradius;
struct MTex *mtex[8];
struct Ipo *ipo;
@@ -77,6 +82,8 @@ typedef struct Lamp {
#define LA_SPOT 2
#define LA_HEMI 3
#define LA_AREA 4
/* yafray: extra lamp type used for caustic photonmap */
#define LA_YF_PHOTON 5
/* mode */
#define LA_SHAD 1
@@ -89,10 +96,13 @@ typedef struct Lamp {
#define LA_SQUARE 128
#define LA_TEXTURE 256
#define LA_OSATEX 512
#define LA_DEEP_SHADOW 1024
#define LA_DEEP_SHADOW 1024
#define LA_NO_DIFF 2048
#define LA_NO_SPEC 4096
#define LA_SHAD_RAY 8192
/* yafray: lamp shadowbuffer flag, softlight */
/* Since it is used with LOCAL lamp, can't use LA_SHAD */
#define LA_YF_SOFT 16384
/* area shape */
#define LA_AREA_SQUARE 0

View File

@@ -265,6 +265,11 @@ typedef struct LampRen
float mat[3][3]; /* 3x3 part from lampmat x viewmat */
float area[8][3], areasize;
/* yafray: photonlight params */
int YF_numphotons, YF_numsearch;
short YF_phdepth, YF_useqmc, YF_bufsize;
float YF_causticblur, YF_ltradius;
struct LampRen *org;
struct MTex *mtex[8];
} LampRen;

View File

@@ -1901,6 +1901,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
shadfac[3]= ir= 0.0;
for(a=0; a<R.totlamp; a++) {
lar= R.la[a];
/* yafray: ignore shading by photonlights, not used in Blender */
if (lar->type==LA_YF_PHOTON) continue;
if(lar->mode & LA_LAYER) if((lar->lay & vlr->lay)==0) continue;
@@ -1996,6 +1998,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
for(a=0; a<R.totlamp; a++) {
lar= R.la[a];
/* yafray: ignore shading by photonlights, not used in Blender */
if (lar->type==LA_YF_PHOTON) continue;
/* test for lamp layer */
if(lar->mode & LA_LAYER) if((lar->lay & vlr->lay)==0) continue;

View File

@@ -1656,6 +1656,17 @@ void RE_add_render_lamp(Object *ob, int doshadbuf)
area_lamp_vectors(lar);
}
else lar->ray_totsamp= 0;
/* yafray: photonlight and other params */
if (R.r.renderer==R_YAFRAY) {
lar->YF_numphotons = la->YF_numphotons;
lar->YF_numsearch = la->YF_numsearch;
lar->YF_phdepth = la->YF_phdepth;
lar->YF_useqmc = la->YF_useqmc;
lar->YF_causticblur = la->YF_causticblur;
lar->YF_ltradius = la->YF_ltradius;
lar->YF_bufsize = la->YF_bufsize;
}
lar->spotsi= la->spotsize;
if(lar->mode & LA_HALO) {

View File

@@ -1278,8 +1278,8 @@ static void render_panel_yafrayGI()
if (G.scene->r.GImethod==2)
{
if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
uiDefButI(block, NUM, B_DIFF, "Depth:", 180,175,110,20, &G.scene->r.GIdepth, 1.0, 8.0, 10, 10, "Number of bounces of the indirect light");
uiDefButI(block, NUM, B_DIFF, "CDepth:", 180,150,110,20, &G.scene->r.GIcausdepth, 1.0, 8.0, 10, 10, "Number of bounces inside objects (for caustics)");
uiDefButI(block, NUM, B_DIFF, "Depth:", 180,175,110,20, &G.scene->r.GIdepth, 1.0, 100.0, 10, 10, "Number of bounces of the indirect light");
uiDefButI(block, NUM, B_DIFF, "CDepth:", 180,150,110,20, &G.scene->r.GIcausdepth, 1.0, 100.0, 10, 10, "Number of bounces inside objects (for caustics)");
uiDefButS(block,TOG|BIT|0, B_REDR, "Cache",70,125,89,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache irradiance samples (faster)");
uiDefButS(block,TOG|BIT|0, B_REDR, "Photons",180,125,89,20, &G.scene->r.GIphotons, 0, 0, 0, 0, "Use global photons to help in GI");
if (G.scene->r.GIcache)

View File

@@ -1953,6 +1953,9 @@ void do_lampbuts(unsigned short event)
case B_SHADRAY:
la= G.buts->lockpoin;
la->mode &= ~LA_SHAD;
/* yafray: 'softlight' uses it's own shadbuf. flag.
Must be cleared here too when switching from ray shadow */
la->mode &= ~LA_YF_SOFT;
allqueue(REDRAWBUTSSHADING, 0);
break;
}
@@ -2088,8 +2091,9 @@ static void lamp_panel_spot(Object *ob, Lamp *la)
block= uiNewBlock(&curarea->uiblocks, "lamp_panel_spot", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Shadow and Spot", "Lamp", 640, 0, 318, 204)==0) return;
// hemis and ray shadow dont work at all...
if(la->type==LA_HEMI) return;
/* hemis and ray shadow dont work at all... */
/* yafray: ignore photonlight as well */
if ((la->type==LA_HEMI) || (la->type==LA_YF_PHOTON)) return;
if(G.vd) grid= G.vd->grid;
if(grid<1.0) grid= 1.0;
@@ -2155,6 +2159,90 @@ static void lamp_panel_spot(Object *ob, Lamp *la)
}
/* yafray: adaptation of lamp_panel_spot above with yafray specific parameters */
static void lamp_panel_yafray(Object *ob, Lamp *la)
{
uiBlock *block;
block= uiNewBlock(&curarea->uiblocks, "lamp_panel_yafray", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Yafray: Shadow and Photons", "Lamp", 640, 0, 318, 204)==0) return;
/* hemis not used in yafray */
if(la->type==LA_HEMI) return;
uiSetButLock(la->id.lib!=0, "Can't edit library data");
/* photonlight params */
if (la->type==LA_YF_PHOTON) {
uiBlockSetCol(block, TH_BUT_SETTING1);
uiDefButS(block, TOG|BIT|0, B_DIFF,"Use QMC",10,180,80,19,&la->YF_useqmc, 0, 0, 0, 0, "Use QMC sampling (sometimes visible patterns)");
uiBlockSetCol(block, TH_AUTO);
uiDefButF(block, NUMSLI,B_LAMPREDRAW,"Angle ", 100,180,200,19,&la->spotsize, 1.0, 180.0, 0, 0, "Sets the angle of the photonlight beam in degrees");
uiDefButI(block, NUM,B_DIFF,"photons:", 10,150,290,19, &la->YF_numphotons, 10000, 100000000, 0, 0, "Maximum number of photons to shoot");
uiDefButI(block, NUM,B_DIFF,"search:", 10,130,290,19, &la->YF_numsearch, 100, 1000, 0, 0, "Number of photons to mix (blur)");
uiDefButS(block, NUM,B_DIFF,"depth:", 10,100,290,19, &la->YF_phdepth, 1, 100, 0, 0, "Maximum caustic bounce depth");
uiDefButF(block, NUM,B_DIFF,"Blur:", 10,70,290,19, &la->YF_causticblur, 0.01, 1.0, 1, 0, "Amount of caustics blurring (also depends on search)");
return;
}
uiBlockSetCol(block, TH_BUT_SETTING1);
uiBlockBeginAlign(block);
/* in yafray arealights always cast shadows, so ray shadow flag not needed */
if (la->type!=LA_AREA)
uiDefButS(block, TOG|BIT|13, B_SHADRAY,"Ray Shadow",10,180,80,19,&la->mode, 0, 0, 0, 0, "Use ray tracing for shadow");
/* in yafray the regular lamp can use shadowbuffers (softlight), used by spot with halo as well */
/* to prevent clash with blender shadowbuf flag, a special flag is used for yafray */
if (la->type==LA_LOCAL)
uiDefButS(block, TOG|BIT|14, B_SHADBUF, "Buf.Shadow",10,160,80,19,&la->mode, 0, 0, 0, 0, "Lets light produce shadows using shadow buffer");
uiBlockEndAlign(block);
/* shadowbuffers used only for 'softlight' & spotlight with halo */
if (((la->type==LA_LOCAL) && (la->mode & LA_YF_SOFT)) || ((la->type==LA_SPOT) && (la->mode & LA_HALO))) {
/* Shadow buffer size can be anything in yafray, but reasonable minimum is 128 */
/* Maximum is 1024, since zbuf in yafray is float, no multiple of 16 restriction */
uiDefButS(block, NUM,B_DIFF,"ShadowBufferSize:", 100,110,200,19, &la->YF_bufsize, 128, 1024, 0, 0, "Sets the size of the shadow buffer");
/* samples & halostep params only used for spotlight with halo */
if ((la->type==LA_SPOT) && (la->mode & LA_HALO)) {
uiDefButS(block, NUM,B_DIFF,"Samples:", 100,30,100,19, &la->samp,1.0,16.0, 0, 0, "Sets the number of shadow map samples");
uiDefButS(block, NUM,B_DIFF,"Halo step:", 200,30,100,19, &la->shadhalostep, 0.0, 12.0, 0, 0, "Sets the volumetric halo sampling frequency");
}
uiDefButF(block, NUM,B_DIFF,"Bias:", 100,10,100,19, &la->bias, 0.01, 5.0, 1, 0, "Sets the shadow map sampling bias");
/* here can use the Blender soft param, since for yafray it has the same function as in Blender */
uiDefButF(block, NUM,B_DIFF,"Soft:", 200,10,100,19, &la->soft,1.0,100.0, 100, 0, "Sets the size of the shadow sample area");
}
else if ((la->type==LA_LOCAL) && (la->mode & LA_SHAD_RAY)) {
/* for spherelight, light radius */
uiDefButF(block, NUM,B_DIFF,"Radius:", 200,10,100,19, &la->YF_ltradius, 0.0,100.0, 100, 0, "Sets the radius of the lightsource, 0 is same as pointlight");
}
if (la->type==LA_SPOT) {
uiDefButS(block, TOG|BIT|1, B_LAMPREDRAW,"Halo", 10,50,80,19,&la->mode, 0, 0, 0, 0, "Renders spotlight with a volumetric halo");
uiBlockSetCol(block, TH_AUTO);
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI,B_LAMPREDRAW,"SpotSi ", 100,180,200,19,&la->spotsize, 1.0, 180.0, 0, 0, "Sets the angle of the spotlight beam in degrees");
uiDefButF(block, NUMSLI,B_MATPRV,"SpotBl ", 100,160,200,19,&la->spotblend, 0.0, 1.0, 0, 0, "Sets the softness of the spotlight edge");
uiBlockEndAlign(block);
if (la->mode & LA_HALO) uiDefButF(block, NUMSLI,0,"HaloInt ", 100,135,200,19,&la->haint, 0.0, 5.0, 0, 0, "Sets the intensity of the spotlight halo");
}
else if ((la->type==LA_AREA) || ((la->type==LA_LOCAL) && (la->mode & LA_SHAD_RAY))) {
/* area samples param also used for 'spherelight' */
uiBlockBeginAlign(block);
uiBlockSetCol(block, TH_AUTO);
uiDefButS(block, NUM,B_DIFF,"Samples:", 100,180,200,19, &la->ray_samp, 1.0, 16.0, 100, 0, "Sets the amount of samples taken extra (samp x samp)");
/* shadow sampling types not used in yafray, removed */
}
else uiDefBut(block, LABEL,0," ", 100,180,200,19,NULL, 0, 0, 0, 0, "");
}
static void lamp_panel_lamp(Object *ob, Lamp *la)
{
@@ -2251,6 +2339,9 @@ static void lamp_panel_preview(Object *ob, Lamp *la)
uiDefButS(block, ROW,B_LAMPREDRAW,"Spot", 200,125,80,25,&la->type,1.0,(float)LA_SPOT, 0, 0, "Creates a directional cone light source");
uiDefButS(block, ROW,B_LAMPREDRAW,"Sun", 200,100,80,25,&la->type,1.0,(float)LA_SUN, 0, 0, "Creates a constant direction parallel ray light source");
uiDefButS(block, ROW,B_LAMPREDRAW,"Hemi", 200,75,80,25,&la->type,1.0,(float)LA_HEMI, 0, 0, "Creates a 180 degree constant light source");
/* yafray: extra type, photonlight */
if (G.scene->r.renderer==R_YAFRAY)
uiDefButS(block, ROW,B_LAMPREDRAW,"Photon", 200,50,80,25,&la->type,1.0,(float)LA_YF_PHOTON, 0, 0, "Creates a special caustics photon 'light', not a real lightsource, use with other lights");
}
@@ -2960,7 +3051,20 @@ void lamp_panels()
lamp_panel_preview(ob, ob->data);
lamp_panel_lamp(ob, ob->data);
lamp_panel_spot(ob, ob->data);
/* switch to yafray lamp panel if yafray enabled */
if (G.scene->r.renderer==R_INTERN)
lamp_panel_spot(ob, ob->data);
else {
/* init vars */
Lamp* lp = ob->data;
if (lp->YF_numphotons==0) lp->YF_numphotons=1000;
if (lp->YF_numsearch==0) lp->YF_numsearch=10;
if (lp->YF_phdepth==0) lp->YF_phdepth=1;
if (lp->YF_causticblur==0.0) lp->YF_causticblur=0.001;
if (lp->YF_bufsize==0) lp->YF_bufsize=128;
/* spherelight radius default is zero, so nothing to do */
lamp_panel_yafray(ob, lp);
}
lamp_panel_texture(ob, ob->data);
lamp_panel_mapto(ob, ob->data);

View File

@@ -529,7 +529,8 @@ static void drawlamp(Object *ob)
setlinestyle(4);
if(la->type==LA_SPOT) {
/* yafray: for photonlight also draw lightcone as for spot */
if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) {
lvec[0]=lvec[1]= 0.0;
lvec[2] = 1.0;

View File

@@ -442,7 +442,8 @@ static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char
}
}
if(la->type==LA_SPOT) {
/* yafray: preview shade as spot, sufficient */
if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) {
if(la->mode & LA_SQUARE) {

View File

@@ -640,10 +640,10 @@ void yafrayFileRender_t::writeMaterialsAndModulators()
// bumpmapping
if ((mtex->mapto & MAP_NORM) || (mtex->maptoneg & MAP_NORM)) {
// for yafray, bump factor is negated (unless negative option of 'Nor', is not affected by 'Neg')
// scaled down quite a bit for yafray when image type, otherwise used directly
// scaled down quite a bit for yafray
float nf = -mtex->norfac;
if (mtex->maptoneg & MAP_NORM) nf *= -1.f;
if (tex->type==TEX_IMAGE) nf *= 2e-3f;
if (tex->type==TEX_IMAGE) nf/=60.f; else nf/=30.f;
ostr << "\t\t<normal value=\"" << nf << "\" />\n";
}
@@ -1050,7 +1050,7 @@ void yafrayFileRender_t::writeAreaLamp(LampRen* lamp, int num, float iview[4][4]
ostr << "<light type=\"arealight\" name=\"LAMP" << num+1 << "\" dummy=\""<< md << "\" power=\"" << power << "\" ";
if (!R.r.GIphotons) {
int psm=0, sm = lamp->ray_totsamp;
if (sm>=64) psm = sm/4;
if (sm>=25) psm = sm/5;
ostr << "samples=\"" << sm << "\" psamples=\"" << psm << "\" ";
}
ostr << ">\n";
@@ -1088,49 +1088,107 @@ void yafrayFileRender_t::writeLamps()
{
ostr.str("");
LampRen* lamp = R.la[i];
if (lamp->type==LA_AREA) { writeAreaLamp(lamp, i, iview); continue; }
// TODO: add decay setting in yafray
ostr << "<light type=\"";
if (lamp->type==LA_LOCAL)
ostr << "pointlight";
bool is_softL=false, is_sphereL=false;
if (lamp->type==LA_LOCAL) {
if (lamp->mode & LA_YF_SOFT) {
// shadowmapped omnidirectional light
ostr << "softlight";
is_softL = true;
}
else if ((lamp->mode & LA_SHAD_RAY) && (lamp->YF_ltradius>0.0)) {
// area sphere, only when ray shadows enabled and radius>0.0
ostr << "spherelight";
is_sphereL = true;
}
else ostr << "pointlight";
}
else if (lamp->type==LA_SPOT)
ostr << "spotlight";
else if ((lamp->type==LA_SUN) || (lamp->type==LA_HEMI)) // for now, hemi same as sun
else if ((lamp->type==LA_SUN) || (lamp->type==LA_HEMI)) // hemi exported as sun
ostr << "sunlight";
else if (lamp->type==LA_YF_PHOTON)
ostr << "photonlight";
else {
// possibly unknown type, ignore
cout << "Unknown Blender lamp type: " << lamp->type << endl;
continue;
}
ostr << "\" name=\"LAMP" << i+1; //no name available here, create one
//no name available here, create one
ostr << "\" name=\"LAMP" << i+1;
// color already premultiplied by energy, so only need distance here
float pwr;
if (lamp->mode & LA_SPHERE) {
// best approx. as used in LFexport script (LF d.f.m. 4pi?)
pwr = lamp->dist*(lamp->dist+1)*(0.25/M_PI);
//decay = 2;
}
else {
if ((lamp->type==LA_LOCAL) || (lamp->type==LA_SPOT)) {
float pwr = 1; // default for sun/hemi, distance irrelevant
if ((lamp->type!=LA_SUN) && (lamp->type!=LA_HEMI)) {
if (lamp->mode & LA_SPHERE) {
// best approx. as used in LFexport script (LF d.f.m. 4pi?)
pwr = lamp->dist*(lamp->dist+1)*(0.25/M_PI);
//decay = 2;
}
else {
pwr = lamp->dist;
//decay = 1;
}
else pwr = 1; // sun/hemi distance irrelevant
}
ostr << "\" power=\"" << pwr;
string lpmode="off";
// shadows only when Blender has shadow button enabled, only spots use LA_SHAD flag
if (R.r.mode & R_SHADOW)
if (((lamp->type==LA_SPOT) && (lamp->mode & LA_SHAD)) || (lamp->mode & LA_SHAD_RAY)) lpmode="on";
ostr << "\" cast_shadows=\"" << lpmode << "\"";
ostr << "\" power=\"" << pwr << "\"";
// cast_shadows flag not used with softlight, spherelight or photonlight
if ((!is_softL) && (!is_sphereL) && (lamp->type!=LA_YF_PHOTON)) {
string lpmode="off";
// shadows only when Blender has shadow button enabled, only spots use LA_SHAD flag
if (R.r.mode & R_SHADOW)
if (((lamp->type==LA_SPOT) && (lamp->mode & LA_SHAD)) || (lamp->mode & LA_SHAD_RAY)) lpmode="on";
ostr << " cast_shadows=\"" << lpmode << "\"";
}
// spot specific stuff
bool has_halo = ((lamp->type==LA_SPOT) && (lamp->mode & LA_HALO) && (lamp->haint>0.0));
if (lamp->type==LA_SPOT) {
// conversion already changed spotsize to cosine of half angle
float ld = 1-lamp->spotsi; //convert back to blender slider setting
if (ld!=0) ld = 1.f/ld;
ostr << " size=\"" << acos(lamp->spotsi)*180.0/M_PI << "\""
<< " blend=\"" << lamp->spotbl*ld << "\""
<< " beam_falloff=\"2\""; // no Blender equivalent (yet)
ostr << " size=\"" << acos(lamp->spotsi)*180.0/M_PI << "\""
<< " blend=\"" << lamp->spotbl*ld << "\""
<< " beam_falloff=\"2\""; // no Blender equivalent (yet)
// halo params
if (has_halo) {
ostr << "\n\thalo=\"on\" " << "res=\"" << lamp->YF_bufsize << "\"\n";
int hsmp = ((12-lamp->shadhalostep)*16)/12;
hsmp = (hsmp+1)*16; // makes range (16, 272) for halostep(12, 0), good enough?
ostr << "\tsamples=\"" << hsmp << "\" shadow_samples=\"" << (lamp->samp*lamp->samp) << "\"\n";
ostr << "\thalo_blur=\"0\" shadow_blur=\"" << (lamp->soft*0.01f) << "\"\n";
ostr << "\tfog_density=\"" << (lamp->haint*0.2f) << "\"";
}
}
else if (is_softL) {
// softlight
ostr << " res=\"" << lamp->YF_bufsize << "\""
<< " radius=\"" << lamp->soft << "\""
<< " bias=\"" << lamp->bias << "\"";
}
else if (is_sphereL) {
// spherelight
int psm=0, sm = lamp->samp*lamp->samp;
if (sm>=25) psm = sm/5;
ostr << " radius=\"" << lamp->YF_ltradius << "\""
<< " samples=\"" << sm << "\""
<< " psamples=\"" << psm << "\""
<< " qmc_method=\"1\"";
}
else if (lamp->type==LA_YF_PHOTON) {
string qmc="off";
if (lamp->YF_useqmc) qmc="on";
ostr << "\n\tphotons=\"" << lamp->YF_numphotons << "\""
<< " search=\"" << lamp->YF_numsearch << "\""
<< " depth=\"" << lamp->YF_phdepth << "\""
<< " use_QMC=\"" << qmc << "\""
<< " angle=\"" << acos(lamp->spotsi)*180.0/M_PI << "\"";
float cl = lamp->YF_causticblur/sqrt((float)lamp->YF_numsearch);
ostr << "\n\tfixedradius=\"" << lamp->YF_causticblur << "\" cluster=\"" << cl << "\"";
}
ostr << " >\n";
@@ -1146,11 +1204,13 @@ void yafrayFileRender_t::writeLamps()
ostr << "\t<from x=\"" << -lpvec[0] << "\" y=\"" << -lpvec[1] << "\" z=\"" << -lpvec[2] << "\" />\n";
else
ostr << "\t<from x=\"" << lpco[0] << "\" y=\"" << lpco[1] << "\" z=\"" << lpco[2] << "\" />\n";
// 'to' for spot, already calculated by Blender
if (lamp->type==LA_SPOT)
// 'to' for spot/photonlight, already calculated by Blender
if ((lamp->type==LA_SPOT) || (lamp->type==LA_YF_PHOTON)) {
ostr << "\t<to x=\"" << lpco[0] + lpvec[0]
<< "\" y=\"" << lpco[1] + lpvec[1]
<< "\" z=\"" << lpco[2] + lpvec[2] << "\" />\n";
if (has_halo) ostr << "\t<fog r=\"1\" g=\"1\" b=\"1\" />\n";
}
// color
// rgb in LampRen is premultiplied by energy, power is compensated for that above

View File

@@ -638,10 +638,10 @@ void yafrayPluginRender_t::writeMaterialsAndModulators()
{
// for yafray, bump factor is negated (unless negative option of 'Nor',
// is not affected by 'Neg')
// scaled down quite a bit for yafray when image type, otherwise used directly
// scaled down quite a bit for yafray
float nf = -mtex->norfac;
if (mtex->maptoneg & MAP_NORM) nf *= -1.f;
if (tex->type==TEX_IMAGE) nf *= 2e-3f;
if (tex->type==TEX_IMAGE) nf/=60.f; else nf/=30.f;
mparams["normal"]=yafray::parameter_t(nf);
}
@@ -1100,53 +1100,112 @@ void yafrayPluginRender_t::writeLamps()
yafray::paramMap_t params;
string type="";
LampRen* lamp = R.la[i];
if (lamp->type==LA_AREA) { writeAreaLamp(lamp, i, iview); continue; }
// TODO: add decay setting in yafray
if (lamp->type==LA_LOCAL)
params["type"]=yafray::parameter_t("pointlight");
bool is_softL=false, is_sphereL=false;
if (lamp->type==LA_LOCAL) {
if (lamp->mode & LA_YF_SOFT) {
// shadowmapped omnidirectional light
params["type"] = yafray::parameter_t("softlight");
is_softL = true;
}
else if ((lamp->mode & LA_SHAD_RAY) && (lamp->YF_ltradius>0.0)) {
// area sphere, only when ray shadows enabled and radius>0.0
params["type"] = yafray::parameter_t("spherelight");
is_sphereL = true;
}
else params["type"] = yafray::parameter_t("pointlight");
}
else if (lamp->type==LA_SPOT)
params["type"]=yafray::parameter_t("spotlight");
else if ((lamp->type==LA_SUN) || (lamp->type==LA_HEMI)) // for now, hemi same as sun
params["type"]=yafray::parameter_t("sunlight");
else
{
params["type"] = yafray::parameter_t("spotlight");
else if ((lamp->type==LA_SUN) || (lamp->type==LA_HEMI)) // hemi exported as sun
params["type"] = yafray::parameter_t("sunlight");
else if (lamp->type==LA_YF_PHOTON)
params["type"] = yafray::parameter_t("photonlight");
else {
// possibly unknown type, ignore
cout << "Unknown Blender lamp type: " << lamp->type << endl;
continue;
}
//no name available here, create one
char temp[16];
sprintf(temp,"LAMP%d",i+1);
params["name"]=yafray::parameter_t(temp);
params["name"] = yafray::parameter_t(temp);
// color already premultiplied by energy, so only need distance here
float pwr;
if (lamp->mode & LA_SPHERE)
{
// best approx. as used in LFexport script (LF d.f.m. 4pi?)
pwr = lamp->dist*(lamp->dist+1)*(0.25/M_PI);
//decay = 2;
}
else
{
if ((lamp->type==LA_LOCAL) || (lamp->type==LA_SPOT))
float pwr = 1; // default for sun/hemi, distance irrelevant
if ((lamp->type!=LA_SUN) && (lamp->type!=LA_HEMI)) {
if (lamp->mode & LA_SPHERE) {
// best approx. as used in LFexport script (LF d.f.m. 4pi?)
pwr = lamp->dist*(lamp->dist+1)*(0.25/M_PI);
//decay = 2;
}
else {
pwr = lamp->dist;
else pwr = 1; // sun/hemi distance irrelevent.
//decay = 1;
}
}
params["power"]=yafray::parameter_t(pwr);
string lpmode="off";
// shadows only when Blender has shadow button enabled, only spots use LA_SHAD flag
if (R.r.mode & R_SHADOW)
if (((lamp->type==LA_SPOT) && (lamp->mode & LA_SHAD)) || (lamp->mode & LA_SHAD_RAY)) lpmode="on";
params["cast_shadows"]=yafray::parameter_t(lpmode);
params["power"] = yafray::parameter_t(pwr);
// cast_shadows flag not used with softlight, spherelight or photonlight
if ((!is_softL) && (!is_sphereL) && (lamp->type!=LA_YF_PHOTON)) {
string lpmode="off";
// shadows only when Blender has shadow button enabled, only spots use LA_SHAD flag
if (R.r.mode & R_SHADOW)
if (((lamp->type==LA_SPOT) && (lamp->mode & LA_SHAD)) || (lamp->mode & LA_SHAD_RAY)) lpmode="on";
params["cast_shadows"] = yafray::parameter_t(lpmode);
}
// spot specific stuff
if (lamp->type==LA_SPOT)
{
bool has_halo = ((lamp->type==LA_SPOT) && (lamp->mode & LA_HALO) && (lamp->haint>0.0));
if (lamp->type==LA_SPOT) {
// conversion already changed spotsize to cosine of half angle
float ld = 1-lamp->spotsi; //convert back to blender slider setting
if (ld!=0) ld = 1.f/ld;
params["size"]=yafray::parameter_t(acos(lamp->spotsi)*180.0/M_PI);
params["blend"]=yafray::parameter_t(lamp->spotbl*ld);
params["beam_falloff"]=yafray::parameter_t(2.0);
params["size"] = yafray::parameter_t(acos(lamp->spotsi)*180.0/M_PI);
params["blend"] = yafray::parameter_t(lamp->spotbl*ld);
params["beam_falloff"] = yafray::parameter_t(2.0);
// halo params
if (has_halo) {
params["halo"] = yafray::parameter_t("on");
params["res"] = yafray::parameter_t(lamp->YF_bufsize);
int hsmp = ((12-lamp->shadhalostep)*16)/12;
hsmp = (hsmp+1)*16; // makes range (16, 272) for halostep(12, 0), good enough?
params["samples"] = yafray::parameter_t(hsmp);
params["shadow_samples"] = yafray::parameter_t(lamp->samp*lamp->samp);
params["halo_blur"] = yafray::parameter_t(0.0);
params["shadow_blur"] = yafray::parameter_t(lamp->soft*0.01f);
params["fog_density"] = yafray::parameter_t(lamp->haint*0.2f);
}
}
else if (is_softL) {
// softlight
params["res"] = yafray::parameter_t(lamp->YF_bufsize);
params["radius"] = yafray::parameter_t(lamp->soft);
params["bias"] = yafray::parameter_t(lamp->bias);
}
else if (is_sphereL) {
// spherelight
int psm=0, sm = lamp->samp*lamp->samp;
if (sm>=25) psm = sm/5;
params["radius"] = yafray::parameter_t(lamp->YF_ltradius);
params["samples"] = yafray::parameter_t(sm);
params["psamples"] = yafray::parameter_t(psm);
params["qmc_method"] = yafray::parameter_t(1);
}
else if (lamp->type==LA_YF_PHOTON) {
string qmc="off";
if (lamp->YF_useqmc) qmc="on";
params["photons"] = yafray::parameter_t(lamp->YF_numphotons);
params["search"] = yafray::parameter_t(lamp->YF_numsearch);
params["depth"] = yafray::parameter_t(lamp->YF_phdepth);
params["use_QMC"] = yafray::parameter_t(qmc);
params["angle"] = yafray::parameter_t(acos(lamp->spotsi)*180.0/M_PI);
float cl = lamp->YF_causticblur/sqrt((float)lamp->YF_numsearch);
params["fixedradius"] = yafray::parameter_t(lamp->YF_causticblur);
params["cluster"] = yafray::parameter_t(cl);
}
// transform lamp co & vec back to world
@@ -1161,14 +1220,17 @@ void yafrayPluginRender_t::writeLamps()
params["from"] = yafray::parameter_t(yafray::point3d_t(-lpvec[0], -lpvec[1], -lpvec[2]));
else
params["from"] = yafray::parameter_t(yafray::point3d_t(lpco[0], lpco[1], lpco[2]));
// 'to' for spot, already calculated by Blender
if (lamp->type==LA_SPOT)
params["to"]=yafray::parameter_t(yafray::point3d_t(lpco[0] + lpvec[0],
lpco[1] + lpvec[1],
lpco[2] + lpvec[2]));
// 'to' for spot/photonlight, already calculated by Blender
if ((lamp->type==LA_SPOT) || (lamp->type==LA_YF_PHOTON)) {
params["to"] = yafray::parameter_t(yafray::point3d_t(lpco[0] + lpvec[0],
lpco[1] + lpvec[1],
lpco[2] + lpvec[2]));
if (has_halo) params["fog"] = yafray::parameter_t(yafray::color_t(1.0, 1.0, 1.0));
}
// color
// rgb in LampRen is premultiplied by energy, power is compensated for that above
params["color"]=yafray::parameter_t(yafray::color_t(lamp->r,lamp->g,lamp->b));
params["color"] = yafray::parameter_t(yafray::color_t(lamp->r, lamp->g, lamp->b));
yafrayGate->addLight(params);
}
}