Sunsky / Atmoshphere:

- Added blending mode and factor option, so it's more clear and
  controllable what happens with it. Also nice for crazy effects
  of course!
- Preview render now shows preview for it too

On the todos:

- have this in World buttons (as well) for quicker sky setups
- review math of color clamping and scaling, this is definitely 
  not good... but a fix will make old files look very different.
This commit is contained in:
Ton Roosendaal 2008-09-21 16:04:33 +00:00
parent 1c29d02305
commit afe851b6d1
12 changed files with 13427 additions and 13025 deletions

@ -41,7 +41,7 @@ struct ListBase;
struct MemFile;
#define BLENDER_VERSION 247
#define BLENDER_SUBVERSION 4
#define BLENDER_SUBVERSION 5
#define BLENDER_MINVERSION 245
#define BLENDER_MINSUBVERSION 15

@ -748,6 +748,9 @@ void *add_lamp(char *name)
la->atm_extinction_factor = 1.0;
la->atm_distance_factor = 1.0;
la->sun_intensity = 1.0;
la->skyblendtype= MA_RAMP_ADD;
la->skyblendfac= 1.0f;
curvemapping_initialize(la->curfalloff);
return la;
}

@ -7818,6 +7818,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) {
Lamp *la= main->lamp.first;
for(; la; la= la->id.next) {
la->skyblendtype= MA_RAMP_ADD;
la->skyblendfac= 1.0f;
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */

@ -79,7 +79,7 @@ typedef struct Lamp {
/* sun/sky */
short sun_effect_type;
short atm_pad[3];
short skyblendtype;
float horizon_brightness;
float spread;
float sun_brightness;
@ -90,7 +90,7 @@ typedef struct Lamp {
float atm_inscattering_factor;
float atm_extinction_factor;
float atm_distance_factor;
float skyblendfac;
/* yafray: photonlight params */
int YF_numphotons, YF_numsearch;

@ -320,6 +320,7 @@ typedef struct Material {
#define MA_LAMP 6
#define MA_SKY 7
#define MA_HAIR 10
#define MA_ATMOS 11
/* pr_back */
#define MA_DARK 1

@ -33,7 +33,7 @@
typedef struct SunSky
{
short effect_type;
short effect_type, skyblendtype;
float turbidity;
float theta, phi;
@ -53,7 +53,8 @@ typedef struct SunSky
float sun_brightness;
float sun_size;
float backscattered_light;
float skyblendfac;
float atm_HGg;
float atm_SunIntensity;
@ -84,7 +85,8 @@ typedef struct SunSky
* back_scatter, controls back scatter light
* */
void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_brightness,
float spread,float sun_brightness, float sun_size, float back_scatter);
float spread,float sun_brightness, float sun_size, float back_scatter,
float skyblendfac, short skyblendtype);
/**
* GetSkyXYZRadiance:

@ -3638,7 +3638,8 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
Normalize(vec);
InitSunSky(lar->sunsky, la->atm_turbidity, vec, la->horizon_brightness,
la->spread, la->sun_brightness, la->sun_size, la->backscattered_light);
la->spread, la->sun_brightness, la->sun_size, la->backscattered_light,
la->skyblendfac, la->skyblendtype);
InitAtmosphere(lar->sunsky, la->sun_intensity, 1.0, 1.0, la->atm_inscattering_factor, la->atm_extinction_factor,
la->atm_distance_factor);

@ -45,6 +45,7 @@
#include "BKE_image.h"
#include "BKE_global.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
@ -604,12 +605,9 @@ void shadeSunView(struct SunSky *sunsky, float *colf, float *rco, float *view, f
*/
void shadeSkyPixel(float *collector, float fx, float fy)
{
float view[3], dxyview[2];
float sun_collector[3];
float suns_color[3];
short num_sun_lamp;
GroupObject *go;
LampRen *lar;
float view[3], dxyview[2];
/*
The rules for sky:
@ -657,33 +655,18 @@ void shadeSkyPixel(float *collector, float fx, float fy)
collector[3] = 0.0f;
}
suns_color[0] = suns_color[1] = suns_color[2] = 0;
num_sun_lamp = 0;
for(go=R.lights.first; go; go= go->next) {
lar= go->lampren;
if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)){
num_sun_lamp ++;
float sun_collector[3];
calc_view_vector(view, fx, fy);
Normalize(view);
shadeSunView(lar->sunsky, sun_collector, NULL, view, NULL);
suns_color[0] += sun_collector[0];
suns_color[1] += sun_collector[1];
suns_color[2] += sun_collector[2];
ramp_blend(lar->sunsky->skyblendtype, collector, collector+1, collector+2, lar->sunsky->skyblendfac, sun_collector);
}
}
if( num_sun_lamp > 0 ){
suns_color[0] /= num_sun_lamp;
suns_color[1] /= num_sun_lamp;
suns_color[2] /= num_sun_lamp;
collector[0] += suns_color[0];
collector[1] += suns_color[1];
collector[2] += suns_color[2];
ClipColor(collector);
}
}
/* aerial perspective */

@ -135,7 +135,8 @@ float PerezFunction(struct SunSky *sunsky, const float *lam, float theta, float
* back_scatter, controls back scatter light
* */
void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_brightness,
float spread,float sun_brightness, float sun_size, float back_scatter)
float spread,float sun_brightness, float sun_size, float back_scatter,
float skyblendfac, short skyblendtype)
{
float theta2;
@ -151,6 +152,8 @@ void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_b
sunsky->sun_brightness = sun_brightness;
sunsky->sun_size = sun_size;
sunsky->backscattered_light = back_scatter;
sunsky->skyblendfac= skyblendfac;
sunsky->skyblendtype= skyblendtype;
sunsky->toSun[0] = toSun[0];
sunsky->toSun[1] = toSun[1];

@ -2871,7 +2871,7 @@ static void lamp_panel_atmosphere(Object *ob, Lamp *la)
uiSetButLock(la->id.lib!=0, ERROR_LIBDATA_MESSAGE);
uiDefButBitS(block, TOG, LA_SUN_EFFECT_SKY, REDRAWVIEW3D, "Sky", 10,205,BUTW2,20,&(la->sun_effect_type), 0, 0, 0, 0, "Apply sun light effect on sky.");
uiDefButBitS(block, TOG, LA_SUN_EFFECT_SKY, B_LAMPPRV, "Sky", 10,205,BUTW2,20,&(la->sun_effect_type), 0, 0, 0, 0, "Apply sun light effect on sky.");
uiDefButBitS(block, TOG, LA_SUN_EFFECT_AP, REDRAWVIEW3D, "Atmosphere", 20+BUTW2,205,BUTW2,20,&(la->sun_effect_type), 0, 0, 0, 0, "Apply sun light effect on atmosphere.");
if(la->sun_effect_type & (LA_SUN_EFFECT_SKY|LA_SUN_EFFECT_AP)){
@ -2881,11 +2881,19 @@ static void lamp_panel_atmosphere(Object *ob, Lamp *la)
y = 180;
if(la->sun_effect_type & LA_SUN_EFFECT_SKY)
{
uiDefButF(block, NUM, B_LAMPREDRAW, "Hor.Bright:",10,y-25,BUTW2,19, &(la->horizon_brightness), 0.00f, 20.00f, 10, 0, "Sets horizon brightness.");
uiDefButF(block, NUM, B_LAMPREDRAW, "Hor.Spread:",10,y-50,BUTW2,19, &(la->spread), 0.00f, 10.00f, 10, 0, "Sets horizon spread.");
uiDefButF(block, NUM, B_LAMPREDRAW, "Sun Bright:",10,y-75,BUTW2,19, &(la->sun_brightness), 0.00f, 10.0f, 10, 0, "Sets sun brightness.");
uiDefButF(block, NUM, B_LAMPREDRAW, "Sun Size:",10,y-100,BUTW2,19, &(la->sun_size), 0.00f, 10.00f, 10, 0, "Sets sun size.");
uiDefButF(block, NUM, B_LAMPREDRAW, "Back Light:",10,y-125,BUTW2,19, &(la->backscattered_light), -1.00f, 1.00f, 10, 0, "Sets backscatter light.");
uiBlockBeginAlign(block);
uiDefButS(block, MENU, B_LAMPPRV, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Overlay %x9|Divide %x5|Difference %x6|Darken %x7|Lighten %x8|Dodge %x10|Burn %x11|Color %x15|Value %x14|Saturation %x13|Hue %x12",
10,y-25,BUTW2/2,19,
&la->skyblendtype, 0.0f, 0.0f, 0, 0, "Blend type for how it gets combined with sky");
uiDefButF(block, NUM, B_LAMPPRV, "",10+BUTW2/2,y-25,BUTW2/2,19, &(la->skyblendfac), 0.0f, 1.0f, 10, 0, "Sets blending factor with sky color");
uiBlockEndAlign(block);
y -= 25;
uiDefButF(block, NUM, B_LAMPPRV, "Hor.Bright:",10,y-25,BUTW2,19, &(la->horizon_brightness), 0.00f, 20.00f, 10, 0, "Sets horizon brightness.");
uiDefButF(block, NUM, B_LAMPPRV, "Hor.Spread:",10,y-50,BUTW2,19, &(la->spread), 0.00f, 10.00f, 10, 0, "Sets horizon spread.");
uiDefButF(block, NUM, B_LAMPPRV, "Sun Bright:",10,y-75,BUTW2,19, &(la->sun_brightness), 0.00f, 10.0f, 10, 0, "Sets sun brightness.");
uiDefButF(block, NUM, B_LAMPPRV, "Sun Size:",10,y-100,BUTW2,19, &(la->sun_size), 0.00f, 10.00f, 10, 0, "Sets sun size.");
uiDefButF(block, NUM, B_LAMPPRV, "Back Light:",10,y-125,BUTW2,19, &(la->backscattered_light), -1.00f, 1.00f, 10, 0, "Sets backscatter light.");
}
if(la->sun_effect_type & LA_SUN_EFFECT_AP)

File diff suppressed because it is too large Load Diff

@ -282,6 +282,15 @@ void BIF_preview_free_dbase(void)
free_main(pr_main);
}
static Object *find_object(ListBase *lb, const char *name)
{
Object *ob;
for(ob= lb->first; ob; ob= ob->id.next)
if(strcmp(ob->id.name+2, name)==0)
break;
return ob;
}
/* call this with an ID pointer to initialize preview scene */
/* call this with ID NULL to restore assigned ID pointers in preview scene */
static Scene *preview_prepare_scene(RenderInfo *ri, int id_type, ID *id, int pr_method)
@ -384,7 +393,16 @@ static Scene *preview_prepare_scene(RenderInfo *ri, int id_type, ID *id, int pr_
else if(id_type==ID_LA) {
Lamp *la= (Lamp *)id;
sce->lay= 1<<MA_LAMP;
if(la && la->type==LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) {
sce->lay= 1<<MA_ATMOS;
sce->world= G.scene->world;
sce->camera= (Object *)find_object(&pr_main->object, "CameraAtmo");
}
else {
sce->lay= 1<<MA_LAMP;
sce->world= NULL;
sce->camera= (Object *)find_object(&pr_main->object, "Camera");
}
sce->r.mode &= ~R_SHADOW;
for(base= sce->base.first; base; base= base->next) {