Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2007-09-16 17:50:34 +0400
committerMatt Ebb <matt@mke3.net>2007-09-16 17:50:34 +0400
commit90daa8f81126a86f2cd419a6288b5f0b097d478b (patch)
tree4c84662f08c72e42845f8e6667aa5c190126c5c0 /source/blender
parentc8fe5a0ed95fa15e955d3224fd6a2c8a8b648d73 (diff)
* Extra lamp falloff options, including custom curve!
This adds some new lamp attenuation options to the Lamp panel, replacing the old 'Quad' button. Yes, the panel layout is still nasty here, but I've ignored it for now to address properly in the panels cleanup work. * Constant http://mke3.net/blender/devel/rendering/falloff-constant.jpg Lamp doesn't decay with distance * Inverse Linear http://mke3.net/blender/devel/rendering/falloff-invlinear.jpg Default, and same as in older Blender without 'Quad' on. Decays linearly, with 'Dist' value as the lamp's half-energy-distance * Inverse Square http://mke3.net/blender/devel/rendering/falloff-invsquare.jpg A sharper, more realistic decay, good for most electric lights (i.e. not sunlight). This is similar to the old Quad option with slight changes. * Lin/Quad weighted Exactly the same as in older Blenders with the old 'Quad' button enabled. When this setting is chosen, two sliders are shown, 'Linear' and 'Quad' (previously Quad1 and Quad2), which controls the 'linearness' or 'quadraticness' of the falloff curve. Lamps in old files with the 'Quad' button on will be initialised to this setting. But much better for precise control over the lamp falloff now is: * Custom Curve This shows an extra 'Falloff Curve' panel, where you can use the standard Blender curve UI control to precisely control how the light falls off. The Y axis is intensity, and the X axis is distance, stretched over the length of the 'Dist' value. Some example curves and renders: http://mke3.net/blender/devel/rendering/falloff-curve1-curve.png http://mke3.net/blender/devel/rendering/falloff-curve1.jpg http://mke3.net/blender/devel/rendering/falloff-curve2-curve.png http://mke3.net/blender/devel/rendering/falloff-curve2.jpg http://mke3.net/blender/devel/rendering/falloff-curve3-curve.png http://mke3.net/blender/devel/rendering/falloff-curve3.jpg (whee)
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/colortools.c8
-rw-r--r--source/blender/blenkernel/intern/object.c10
-rw-r--r--source/blender/blenloader/intern/readfile.c18
-rw-r--r--source/blender/blenloader/intern/writefile.c3
-rw-r--r--source/blender/include/BIF_butspace.h8
-rw-r--r--source/blender/include/butspace.h1
-rw-r--r--source/blender/makesdna/DNA_lamp_types.h17
-rw-r--r--source/blender/render/intern/include/render_types.h4
-rw-r--r--source/blender/render/intern/source/convertblender.c5
-rw-r--r--source/blender/render/intern/source/shadeoutput.c31
-rw-r--r--source/blender/src/buttons_shading.c44
11 files changed, 129 insertions, 20 deletions
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index fda31d9e7c0..83b014cdd63 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -62,12 +62,18 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa
{
CurveMapping *cumap;
int a;
+ float clipminx, clipminy, clipmaxx, clipmaxy;
cumap= MEM_callocN(sizeof(CurveMapping), "new curvemap");
cumap->flag= CUMA_DO_CLIP;
if(tot==4) cumap->cur= 3; /* rhms, hack for 'col' curve? */
- BLI_init_rctf(&cumap->curr, minx, maxx, miny, maxy);
+ clipminx = MIN2(minx, maxx);
+ clipminy = MIN2(miny, maxy);
+ clipmaxx = MAX2(minx, maxx);
+ clipmaxy = MAX2(miny, maxy);
+
+ BLI_init_rctf(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy);
cumap->clipr= cumap->curr;
cumap->white[0]= cumap->white[1]= cumap->white[2]= 1.0f;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 9f68706716a..751887b9f42 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -70,6 +70,7 @@
#include "BKE_armature.h"
#include "BKE_action.h"
+#include "BKE_colortools.h"
#include "BKE_deform.h"
#include "BKE_DerivedMesh.h"
#include "BKE_nla.h"
@@ -601,6 +602,9 @@ void *add_lamp(char *name)
la->ray_samp_method = LA_SAMP_HALTON;
la->adapt_thresh = 0.001;
la->preview=NULL;
+ la->falloff_type = LA_FALLOFF_INVLINEAR;
+ la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
+ curvemapping_initialize(la->curfalloff);
return la;
}
@@ -619,6 +623,8 @@ Lamp *copy_lamp(Lamp *la)
}
}
+ lan->curfalloff = curvemapping_copy(la->curfalloff);
+
id_us_plus((ID *)lan->ipo);
if (la->preview) lan->preview = BKE_previewimg_copy(la->preview);
@@ -693,13 +699,15 @@ void free_lamp(Lamp *la)
/* scriptlinks */
BPY_free_scriptlink(&la->scriptlink);
-
+
for(a=0; a<MAX_MTEX; a++) {
mtex= la->mtex[a];
if(mtex && mtex->tex) mtex->tex->id.us--;
if(mtex) MEM_freeN(mtex);
}
la->ipo= 0;
+
+ curvemapping_free(la->curfalloff);
BKE_previewimg_free(&la->preview);
BKE_icon_delete(&la->id);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 38240ceeafa..624bfedf6cd 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -112,6 +112,7 @@
#include "BKE_action.h"
#include "BKE_armature.h"
+#include "BKE_colortools.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
@@ -1917,6 +1918,11 @@ static void direct_link_lamp(FileData *fd, Lamp *la)
for(a=0; a<MAX_MTEX; a++) {
la->mtex[a]= newdataadr(fd, la->mtex[a]);
}
+
+ la->curfalloff= newdataadr(fd, la->curfalloff);
+ if(la->curfalloff)
+ direct_link_curvemapping(fd, la->curfalloff);
+
la->preview = direct_link_preview_image(fd, la->preview);
}
@@ -6670,6 +6676,18 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
}
+ if(main->versionfile <= 245) {
+ Lamp *la;
+ if (main->versionfile != 245 || main->subversionfile < 1) {
+ for(la=main->lamp.first; la; la= la->id.next) {
+ if (la->mode & LA_QUAD) la->falloff_type = LA_FALLOFF_SLIDERS;
+ else la->falloff_type = LA_FALLOFF_INVLINEAR;
+
+ la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
+ curvemapping_initialize(la->curfalloff);
+ }
+ }
+ }
if (main->versionfile <= 245) {
bScreen *sc;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 90873efb5b9..4f09f51bc87 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1380,6 +1380,9 @@ static void write_lamps(WriteData *wd, ListBase *idbase)
if(la->mtex[a]) writestruct(wd, DATA, "MTex", 1, la->mtex[a]);
}
+ if(la->curfalloff)
+ write_curvemapping(wd, la->curfalloff);
+
write_scriptlink(wd, &la->scriptlink);
write_previews(wd, la->preview);
diff --git a/source/blender/include/BIF_butspace.h b/source/blender/include/BIF_butspace.h
index 519f3f18a0c..eb2cafad792 100644
--- a/source/blender/include/BIF_butspace.h
+++ b/source/blender/include/BIF_butspace.h
@@ -120,16 +120,16 @@ extern void validate_editbonebutton_cb(void *bonev, void *namev);
#define PANEL_YMAX 210
#define PANEL_XMAX 310
-#define X1CLM 10
+#define X1CLM1 10
-#define X2CLM1 X1CLM
+#define X2CLM1 X1CLM1
#define X2CLM2 165
-#define X3CLM1 X1CLM
+#define X3CLM1 X1CLM1
#define X3CLM2 113
#define X3CLM3 217
-#define X4CLM1 X1CLM
+#define X4CLM1 X1CLM1
#define X4CLM2 77
#define X4CLM3 165
#define X4CLM4 232
diff --git a/source/blender/include/butspace.h b/source/blender/include/butspace.h
index 44e4e5132eb..4f09ad716d7 100644
--- a/source/blender/include/butspace.h
+++ b/source/blender/include/butspace.h
@@ -180,6 +180,7 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
#define B_SHADRAY 1106
#define B_LMTEXPASTE 1107
#define B_LMTEXCOPY 1108
+#define B_LFALLOFFCHANGED 1109
/* *********************** */
#define B_MATBUTS 1300
diff --git a/source/blender/makesdna/DNA_lamp_types.h b/source/blender/makesdna/DNA_lamp_types.h
index e1d4e4c1cc1..f8cc2378cb1 100644
--- a/source/blender/makesdna/DNA_lamp_types.h
+++ b/source/blender/makesdna/DNA_lamp_types.h
@@ -43,6 +43,7 @@
struct MTex;
struct Ipo;
+struct CurveMapping;
typedef struct Lamp {
ID id;
@@ -54,7 +55,13 @@ typedef struct Lamp {
float energy, dist, spotsize, spotblend;
float haint;
+
+
float att1, att2; /* Quad1 and Quad2 attenuation */
+ int pad2;
+ struct CurveMapping *curfalloff;
+ short falloff_type;
+ short pad3;
float clipsta, clipend, shadspotsize;
float bias, soft;
@@ -104,7 +111,7 @@ typedef struct Lamp {
#define LA_SHAD_BUF 1
#define LA_HALO 2
#define LA_LAYER 4
-#define LA_QUAD 8
+#define LA_QUAD 8 /* no longer used */
#define LA_NEG 16
#define LA_ONLYSHADOW 32
#define LA_SPHERE 64
@@ -119,6 +126,14 @@ typedef struct Lamp {
/* Since it is used with LOCAL lamp, can't use LA_SHAD */
#define LA_YF_SOFT 16384
+/* falloff_type */
+#define LA_FALLOFF_CONSTANT 0
+#define LA_FALLOFF_INVLINEAR 1
+#define LA_FALLOFF_INVSQUARE 2
+#define LA_FALLOFF_CURVE 3
+#define LA_FALLOFF_SLIDERS 4
+
+
/* buftype, no flag */
#define LA_SHADBUF_REGULAR 0
#define LA_SHADBUF_IRREGULAR 1
diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h
index b6d1024a081..abcdf417b62 100644
--- a/source/blender/render/intern/include/render_types.h
+++ b/source/blender/render/intern/include/render_types.h
@@ -32,6 +32,7 @@
/* exposed internal in render module only! */
/* ------------------------------------------------------------------------- */
+#include "DNA_color_types.h"
#include "DNA_scene_types.h"
#include "DNA_world_types.h"
#include "DNA_object_types.h"
@@ -324,7 +325,10 @@ typedef struct LampRen {
float vec[3];
float xsp, ysp, distkw, inpr;
float halokw, halo;
+
+ short falloff_type;
float ld1,ld2;
+ struct CurveMapping *curfalloff;
/* copied from Lamp, to decouple more rendering stuff */
/** Size of the shadowbuffer */
diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c
index cb31c58ab2f..29b48413ca7 100644
--- a/source/blender/render/intern/source/convertblender.c
+++ b/source/blender/render/intern/source/convertblender.c
@@ -66,6 +66,7 @@
#include "BKE_action.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
+#include "BKE_colortools.h"
#include "BKE_constraint.h"
#include "BKE_displist.h"
#include "BKE_deform.h"
@@ -2221,7 +2222,6 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
lar->mode= la->mode;
lar->energy= la->energy;
- lar->energy= la->energy;
if(la->mode & LA_NEG) lar->energy= -lar->energy;
lar->vec[0]= -mat[2][0];
@@ -2312,8 +2312,10 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
lar->lay= ob->lay & 0xFFFFFF; // higher 8 bits are localview layers
+ lar->falloff_type = la->falloff_type;
lar->ld1= la->att1;
lar->ld2= la->att2;
+ lar->curfalloff = curvemapping_copy(la->curfalloff);
if(lar->type==LA_SPOT) {
@@ -2965,6 +2967,7 @@ void RE_Database_Free(Render *re)
if(lar->jitter) MEM_freeN(lar->jitter);
if(lar->shadsamp) MEM_freeN(lar->shadsamp);
if(lar->qsa) free_lamp_qmcsampler(lar);
+ curvemapping_free(lar->curfalloff);
}
BLI_freelistN(&re->lampren);
diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c
index c8f6bd129c3..f50028e4c83 100644
--- a/source/blender/render/intern/source/shadeoutput.c
+++ b/source/blender/render/intern/source/shadeoutput.c
@@ -32,6 +32,7 @@
#include "MTC_matrixops.h"
#include "BLI_arithb.h"
+#include "BKE_colortools.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
@@ -1056,14 +1057,26 @@ float lamp_get_visibility(LampRen *lar, float *co, float *lv, float *dist)
visifac= 0.0f;
}
else {
- if(lar->mode & LA_QUAD) {
- if(lar->ld1>0.0f)
- visifac= lar->dist/(lar->dist+lar->ld1*dist[0]);
- if(lar->ld2>0.0f)
- visifac*= lar->distkw/(lar->distkw+lar->ld2*dist[0]*dist[0]);
- }
- else {
- visifac= (lar->dist/(lar->dist+dist[0]));
+ switch(lar->falloff_type)
+ {
+ case LA_FALLOFF_CONSTANT:
+ visifac = 1.0f;
+ break;
+ case LA_FALLOFF_INVLINEAR:
+ visifac = lar->dist/(lar->dist + dist[0]);
+ break;
+ case LA_FALLOFF_INVSQUARE:
+ visifac = lar->dist / (lar->dist + dist[0]*dist[0]);
+ break;
+ case LA_FALLOFF_SLIDERS:
+ if(lar->ld1>0.0f)
+ visifac= lar->dist/(lar->dist+lar->ld1*dist[0]);
+ if(lar->ld2>0.0f)
+ visifac*= lar->distkw/(lar->distkw+lar->ld2*dist[0]*dist[0]);
+ break;
+ case LA_FALLOFF_CURVE:
+ visifac = curvemapping_evaluateF(lar->curfalloff, 0, dist[0]/lar->dist);
+ break;
}
if(lar->mode & LA_SPHERE) {
@@ -1130,6 +1143,8 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
vn= shi->vn;
view= shi->view;
+ if (lar->energy == 0.0) return;
+
/* lampdist, spot angle, area side, ... */
visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist);
if(visifac==0.0f)
diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c
index 385fd36b698..b11e3bc006d 100644
--- a/source/blender/src/buttons_shading.c
+++ b/source/blender/src/buttons_shading.c
@@ -61,6 +61,7 @@
#include "DNA_view3d_types.h"
#include "DNA_world_types.h"
+#include "BKE_colortools.h"
#include "BKE_displist.h"
#include "BKE_effect.h"
#include "BKE_global.h"
@@ -2317,6 +2318,13 @@ void do_lampbuts(unsigned short event)
scrarea_queue_winredraw(curarea);
}
break;
+ case B_LFALLOFFCHANGED:
+ la= G.buts->lockpoin;
+ curvemapping_changed(la->curfalloff, 1);
+ BIF_undo_push("Edit Lamp falloff curve");
+ BIF_preview_changed(ID_LA);
+ scrarea_queue_winredraw(curarea);
+ break;
}
}
@@ -2664,6 +2672,28 @@ static void lamp_panel_yafray(Object *ob, Lamp *la)
}
+static void lamp_panel_falloff(Object *ob, Lamp *la)
+{
+ uiBlock *block;
+ rctf butr;
+ short yco=PANEL_YMAX;
+ float grid= 0.0;
+
+ /* name "Preview" is abused to detect previewrender offset panel */
+ block= uiNewBlock(&curarea->uiblocks, "lamp_panel_falloff", UI_EMBOSS, UI_HELV, curarea->win);
+ uiNewPanelTabbed("Lamp", "Lamp");
+ if(uiNewPanel(curarea, block, "Falloff Curve", "Lamp", PANELX, PANELY, PANELW, PANELH)==0) return;
+
+ if(G.vd) grid= G.vd->grid;
+ if(grid<1.0) grid= 1.0;
+
+ uiSetButLock(la->id.lib!=0, ERROR_LIBDATA_MESSAGE);
+
+ BLI_init_rctf(&butr, 10.0, 310.0, 10.0, (float)yco);
+ curvemap_buttons(block, la->curfalloff, 's', B_LFALLOFFCHANGED, B_LAMPREDRAW, &butr);
+
+}
+
static void lamp_panel_lamp(Object *ob, Lamp *la)
{
uiBlock *block;
@@ -2701,7 +2731,8 @@ static void lamp_panel_lamp(Object *ob, Lamp *la)
}
else if( ELEM(la->type, LA_LOCAL, LA_SPOT)) {
uiBlockSetCol(block, TH_BUT_SETTING1);
- uiDefButBitS(block, TOG, LA_QUAD, B_LAMPPRV,"Quad", 10,150,100,19,&la->mode, 0, 0, 0, 0, "Uses inverse quadratic proportion for light attenuation");
+ uiDefButS(block, MENU, B_LAMPREDRAW, "Falloff %t|Constant %x0|Inverse Linear %x1|Inverse Square %x2|Custom Curve %x3|Lin/Quad Weighted %x4|",
+ 10,150,100,19, &la->falloff_type, 0,0,0,0, "Lamp falloff - intensity decay with distance");
uiDefButBitS(block, TOG, LA_SPHERE, REDRAWVIEW3D,"Sphere", 10,130,100,19,&la->mode, 0, 0, 0, 0, "Sets light intensity to zero for objects beyond the distance value");
}
@@ -2725,9 +2756,9 @@ static void lamp_panel_lamp(Object *ob, Lamp *la)
uiDefButF(block, COL, B_LAMPPRV, "", 120,52,180,24, &la->r, 0, 0, 0, B_COLLAMP, "");
uiBlockBeginAlign(block);
- if (ELEM(la->type, LA_LOCAL, LA_SPOT)) {
- uiDefButF(block, NUMSLI,B_LAMPPRV,"Quad1 ", 120,30,180,19,&la->att1, 0.0, 1.0, 0, 0, "Set the linear distance attenuatation for a quad lamp");
- uiDefButF(block, NUMSLI,B_LAMPPRV,"Quad2 ", 120,10,180,19,&la->att2, 0.0, 1.0, 0, 0, "Set the quadratic distance attenuatation for a quad lamp");
+ if (ELEM(la->type, LA_LOCAL, LA_SPOT) && (la->falloff_type == LA_FALLOFF_SLIDERS)) {
+ uiDefButF(block, NUMSLI,B_LAMPPRV,"Linear ", 120,30,180,19,&la->att1, 0.0, 1.0, 0, 0, "Set the linear distance attenuatation for a quad lamp");
+ uiDefButF(block, NUMSLI,B_LAMPPRV,"Quad ", 120,10,180,19,&la->att2, 0.0, 1.0, 0, 0, "Set the quadratic distance attenuatation for a quad lamp");
}
else if(la->type==LA_AREA) {
if(la->k==0.0) la->k= 1.0;
@@ -3992,11 +4023,16 @@ void material_panels()
void lamp_panels()
{
Object *ob= OBACT;
+ Lamp *la = ob->data;
if(ob==NULL || ob->type!= OB_LAMP) return;
lamp_panel_preview(ob, ob->data);
lamp_panel_lamp(ob, ob->data);
+
+ if (ELEM(la->type, LA_SPOT, LA_LOCAL) && (la->falloff_type == LA_FALLOFF_CURVE))
+ lamp_panel_falloff(ob, ob->data);
+
/* switch to yafray lamp panel if yafray enabled */
if (G.scene->r.renderer==R_INTERN)
lamp_panel_spot(ob, ob->data);