Patch #13422, By Roland Hess, Shadow Color

Finally, after a long time new render candy for the non-game peoples! :)

Good doc is here: (url splits in two)
http://www.harkyman.com/2008/08/06/controllable-shadow-intensity-
and-color/

Note the colorpicker for shadow is in "Shadow and Spot" panel. A bit
hidden, could get more attention. For later. :)
This commit is contained in:
Ton Roosendaal 2008-09-19 16:01:22 +00:00
parent a0504ac922
commit 65ddef19b9
8 changed files with 42 additions and 14 deletions

@ -50,6 +50,7 @@ typedef struct Lamp {
short colormodel, totex;
float r, g, b, k;
float shdwr, shdwg, shdwb, shdwpad;
float energy, dist, spotsize, spotblend;
float haint;
@ -138,6 +139,7 @@ typedef struct Lamp {
/* Since it is used with LOCAL lamp, can't use LA_SHAD */
#define LA_YF_SOFT 16384
#define LA_LAYER_SHADOW 32768
#define LA_SHAD_TEX (1<<16)
/* layer_shadow */
#define LA_LAYER_SHADOW_BOTH 0
@ -190,6 +192,7 @@ typedef struct Lamp {
/* mapto */
#define LAMAP_COL 1
#define LAMAP_SHAD 2
#endif /* DNA_LAMP_TYPES_H */

@ -421,6 +421,7 @@ typedef struct LampRen {
short type;
int mode;
float r, g, b, k;
float shdwr, shdwg, shdwb;
float energy, haint;
int lay;
float spotsi,spotbl;

@ -55,7 +55,7 @@ struct ImBuf;
void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf);
void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, float *blend, int skyflag);
void do_material_tex(struct ShadeInput *shi);
void do_lamp_tex(LampRen *la, float *lavec, struct ShadeInput *shi, float *colf);
void do_lamp_tex(LampRen *la, float *lavec, struct ShadeInput *shi, float *colf, short effect);
void init_render_textures(Render *re);

@ -3566,6 +3566,9 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
lar->r= lar->energy*la->r;
lar->g= lar->energy*la->g;
lar->b= lar->energy*la->b;
lar->shdwr= la->shdwr;
lar->shdwg= la->shdwg;
lar->shdwb= la->shdwb;
lar->k= la->k;
// area
@ -3718,7 +3721,10 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
for(c=0; c<MAX_MTEX; c++) {
if(la->mtex[c] && la->mtex[c]->tex) {
lar->mode |= LA_TEXTURE;
if (la->mtex[c]->mapto & LAMAP_COL)
lar->mode |= LA_TEXTURE;
if (la->mtex[c]->mapto & LAMAP_SHAD)
lar->mode |= LA_SHAD_TEX;
if(G.rendering) {
if(re->osa) {

@ -141,7 +141,7 @@ static void render_lighting_halo(HaloRen *har, float *colf)
VECCOPY(shi.co, rco);
shi.osatex= 0;
do_lamp_tex(lar, lv, &shi, lacol);
do_lamp_tex(lar, lv, &shi, lacol, LA_TEXTURE);
}
if(lar->type==LA_SPOT) {

@ -1179,7 +1179,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
{
Material *ma= shi->mat;
VlakRen *vlr= shi->vlr;
float lv[3], lampdist, lacol[3], shadfac[4];
float lv[3], lampdist, lacol[3], shadfac[4], lashdw[3];
float i, is, i_noshad, inp, *vn, *view, vnor[3], phongcorr=1.0f;
float visifac;
@ -1219,7 +1219,12 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
lacol[1]= lar->g;
lacol[2]= lar->b;
if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol);
lashdw[0]= lar->shdwr;
lashdw[1]= lar->shdwg;
lashdw[2]= lar->shdwb;
if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE);
if(lar->mode & LA_SHAD_TEX) do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX);
/* tangent case; calculate fake face normal, aligned with lampvector */
/* note, vnor==vn is used as tangent trigger for buffer shadow */
@ -1342,13 +1347,13 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
if((lar->mode & LA_ONLYSHADOW) && i>0.0) {
shadfac[3]= i*lar->energy*(1.0f-shadfac[3]);
shr->shad[0] -= shadfac[3]*shi->r;
shr->shad[1] -= shadfac[3]*shi->g;
shr->shad[2] -= shadfac[3]*shi->b;
shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]);
shr->shad[1] -= shadfac[3]*shi->g*(1.0f-lashdw[1]);
shr->shad[2] -= shadfac[3]*shi->b*(1.0f-lashdw[2]);
shr->spec[0] -= shadfac[3]*shi->specr;
shr->spec[1] -= shadfac[3]*shi->specg;
shr->spec[2] -= shadfac[3]*shi->specb;
shr->spec[0] -= shadfac[3]*shi->specr*(1.0f-lashdw[0]);
shr->spec[1] -= shadfac[3]*shi->specg*(1.0f-lashdw[1]);
shr->spec[2] -= shadfac[3]*shi->specb*(1.0f-lashdw[2]);
return;
}
@ -1366,6 +1371,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
else
add_to_diffuse(shr->shad, shi, is, i*lacol[0], i*lacol[1], i*lacol[2]);
}
/* add light for colored shadow */
if (i_noshad>i && !(lashdw[0]==0 && lashdw[1]==0 && lashdw[2]==0)) {
add_to_diffuse(shr->shad, shi, is, lashdw[0]*(i_noshad-i)*lacol[0], lashdw[1]*(i_noshad-i)*lacol[1], lashdw[2]*(i_noshad-i)*lacol[2]);
}
if(i_noshad>0.0f) {
if(passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW)) {
if(ma->mode & MA_SHADOW_TRA)

@ -2301,7 +2301,7 @@ void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, f
/* ------------------------------------------------------------------------- */
/* colf supposed to be initialized with la->r,g,b */
void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf)
void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf, short effect)
{
Object *ob;
MTex *mtex;
@ -2440,7 +2440,7 @@ void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf)
}
/* mapping */
if(mtex->mapto & LAMAP_COL) {
if(((mtex->mapto & LAMAP_COL) && (effect & LA_TEXTURE))||((mtex->mapto & LAMAP_SHAD) && (effect & LA_SHAD_TEX))) {
float col[3];
if(rgb==0) {

@ -2535,7 +2535,10 @@ static void lamp_panel_mapto(Object *ob, Lamp *la)
uiDefButF(block, NUMSLI, B_LAMPPRV, "DVar ", 10,10,135,19, &(mtex->def_var), 0.0, 1.0, 0, 0, "Value to use for Ref, Spec, Amb, Emit, Alpha, RayMir, TransLu and Hard");
/* MAP TO */
uiDefButBitS(block, TOG, MAP_COL, B_LAMPPRV, "Col", 10,180,135,19, &(mtex->mapto), 0, 0, 0, 0, "Lets the texture affect the basic color of the lamp");
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LAMAP_COL, B_LAMPPRV, "Col", 10,180,135,19, &(mtex->mapto), 0, 0, 0, 0, "Lets the texture affect the basic color of the lamp");
uiDefButBitS(block, TOG, LAMAP_SHAD, B_LAMPPRV, "Shadow", 146,180,135,19, &(mtex->mapto), 0, 0, 0, 0, "Lets the texture affect the shadow color of the lamp");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButS(block, MENU, B_LAMPPRV, mapto_blendtype_pup(),155,125,155,19, &(mtex->blendtype), 0, 0, 0, 0, "Texture blending mode");
@ -2669,6 +2672,12 @@ static void lamp_panel_spot(Object *ob, Lamp *la)
uiDefButBitI(block, TOG, LA_LAYER_SHADOW, B_LAMPPRV,"Layer", 10,90,80,19,&la->mode, 0, 0, 0, 0, "Causes only objects on the same layer to cast shadows");
uiBlockEndAlign(block);
if(ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && ((la->mode & LA_SHAD_RAY)||(la->mode & LA_SHAD_BUF))) {
uiBlockBeginAlign(block);
uiDefButF(block, COL, 0, "Shadow ", 10,90,80,19,&la->shdwr, 0, 0, 0, B_COLLAMP, "Sets the shadow color; default is black (RGB 0,0,0)");
uiBlockEndAlign(block);
}
if(la->type==LA_SPOT) {
uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, LA_SQUARE, B_LAMPREDRAW,"Square", 10,60,80,19,&la->mode, 0, 0, 0, 0, "Sets square spotbundles");