- another fresnel improvement. :)

At last irc meeting, eeshlo pointed to an error in the code. It didn't
  use the IOR value correctly. This has been solved. So how it works now:
  - the IOR button value influences (very subtle) the fresnel effect.
    Only for realism diehards.
  - the Fresnel value (slider) now denotes the power in the function
    rf + (1-rf) * (1-c)^5
    where rf= rf = ((ior-1)/(ior+1))^2
    and c the dot-product ray/normal.
  - so, set the slider at '5' and you have real fresnel. Lower values
    for interesting artistic effects.

- put back the forgotten code for gaussian corrected sampling during
  antialising render. Normally, each sub-pixel sample in Blender counts
  equally, and together make up the pixel color.
  With 'Gauss' option set (F10 menu) each sub-pixel sample creates a small
  weighted mask with variable size, which (can) affect neighbouring pixels
  as well. The result is smoother edges, less sensitive for gamma, and
  well suited to reduce motion-aliasing (when things move extreme slow).
  This is result of *long* period of research in NeoGeo days, and based on
  every scientific sampling/reconstructing theory we could find. Plus a
  little bit of our selves. :)

- I should write once how blender constructs Jitter tables for sub-sampling.
  this is a very nice method, and superior to normal block filter or random
  jittering... time!
This commit is contained in:
Ton Roosendaal 2003-12-22 22:27:51 +00:00
parent 3df84b755f
commit 454166026a
9 changed files with 51 additions and 59 deletions

View File

@ -3931,13 +3931,14 @@ static void do_versions(Main *main)
}
if(main->versionfile <= 231) {
Material *ma= main->mat.first;
Scene *sce;
while(ma) {
if(ma->ang==0.0) {
ma->ang= 1.0;
ma->ray_depth= 2;
ma->ray_depth_tra= 2;
ma->fresnel_tra= 1.0;
ma->fresnel_mir= 1.0;
ma->fresnel_tra= 0.0;
ma->fresnel_mir= 0.0;
}
else if(ma->ang<1.0) { // temporal, because of IOR & fresnel change
ma-> ang= 1.0/ma->ang;
@ -3946,6 +3947,11 @@ static void do_versions(Main *main)
}
ma= ma->id.next;
}
sce= main->scene.first;
while(sce) {
if(sce->r.gauss==0.0) sce->r.gauss= 1.0;
sce= sce->id.next;
}
}
/* don't forget to set version number in blender.c! */
}

View File

@ -200,12 +200,12 @@ typedef struct RenderData {
/** For unified renderer: reduce intensity on boundaries with
* identical materials with this number.*/
short same_mat_redux, pad_3[2];
short same_mat_redux;
/**
* The gamma for the normal rendering. Used when doing
* oversampling, to correctly blend subpixels to pixels. */
float gamma;
float gamma, gauss;
/** post-production settings. Don't really belong here */
float postmul, postgamma, postadd, postigamma;
@ -282,6 +282,7 @@ typedef struct Scene {
#define R_MBLUR 0x4000
#define R_UNIFIED 0x8000
#define R_RAYTRACE 0x10000
#define R_GAUSS 0x20000
/* scemode */
#define R_DOSEQ 0x0001

View File

@ -58,7 +58,7 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
void shade_color(struct ShadeInput *shi, ShadeResult *shr);
void shade_lamp_loop(struct ShadeInput *shi, ShadeResult *shr, int mask);
float fresnel_fac(float *view, float *vn, float fresnel);
float fresnel_fac(float *view, float *vn, float fresnel, float fac);
void calc_R_ref(struct ShadeInput *shi);
float spec(float inp, int hard);

View File

@ -168,9 +168,12 @@ void RE_free_render_data()
float calc_weight(float *weight, int i, int j)
{
float x, y, dist, totw= 0.0;
float x, y, dist, totw= 0.0, fac;
int a;
fac= R.r.gauss*R.r.gauss;
fac*= fac;
for(a=0; a<R.osa; a++) {
x= jit[a][0]-0.5+ i;
y= jit[a][1]-0.5+ j;
@ -179,15 +182,15 @@ float calc_weight(float *weight, int i, int j)
weight[a]= 0.0;
/* gaussian weighting has been cancelled */
//if(R.r.mode & R_GAUSS) {
// if(dist<1.5) {
// x = dist*1.5;
// weight[a]= (1.0/exp(x*x) - 1.0/exp(1.5*1.5*1.5*1.5));
// }
//}
//else {
if(R.r.mode & R_GAUSS) {
if(dist<R.r.gauss) {
x = dist*R.r.gauss;
weight[a]= (1.0/exp(x*x) - 1.0/exp(fac));
}
}
else {
if(i==0 && j==0) weight[a]= 1.0;
//}
}
totw+= weight[a];

View File

@ -1366,7 +1366,7 @@ static void traceray(short depth, float *start, float *vec, float *col, VlakRen
if(shi.matren->mode & MA_RAYMIRROR) {
f= shi.matren->ray_mirror;
if(f!=0.0) f*= fresnel_fac(shi.view, shi.vn, shi.matren->fresnel_mir);
if(f!=0.0) f*= fresnel_fac(shi.view, shi.vn, shi.matren->ang, shi.matren->fresnel_mir);
}
else f= 0.0;
@ -1619,7 +1619,7 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr, int mask)
if(do_mir) {
i= shi->matren->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->matren->fresnel_mir);
i= shi->matren->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->matren->ang, shi->matren->fresnel_mir);
if(i!=0.0) {
fr= shi->matren->mirr;
fg= shi->matren->mirg;

View File

@ -1500,46 +1500,29 @@ void calc_R_ref(ShadeInput *shi)
}
float fresnel_fac(float *view, float *vn, float ior)
float fresnel_fac(float *view, float *vn, float ior, float fac)
{
float rf, t1, t2;
if(ior==1.0) return 1.0;
t1= (view[0]*vn[0] + view[1]*vn[1] + view[2]*vn[2]);
if(t1>0.0) t1= 1.0+t1;
else t1 = 1.0-t1;
if(fac==0.0) return 1.0;
t2 = t1*t1;
t2= (ior + (1.0-ior)*t2*t2*t1);
if(t2<0.0) return 0.0;
else if(t2>1.0) return 1.0;
return t2;
}
#if 0
/* correctness fresnel, schlick approx */
float fresnel_fac1(float *view, float *vn, float ior)
{
float rf, t1, t2;
if(ior==1.0) return 1.0;
rf = ((ior-1)/(ior+1));
rf = ((ior-1.0)/(ior+1.0));
rf*= rf;
t1= (view[0]*vn[0] + view[1]*vn[1] + view[2]*vn[2]);
if(t1>0.0) t1= 1.0-t1;
else t1 = 1.0+t1;
t2 = t1*t1;
t2= (rf + (1.0-rf)*t2*t2*t1);
if(fac==5.0) {
t2 = t1*t1;
t2= rf + (1.0-rf)*t1*t2*t2;
}
else t2= rf + (1.0-rf)*pow(t1, fac);
if(t2<0.0) return 0.0;
else if(t2>1.0) return 1.0;
return t2;
}
#endif
void shade_color(ShadeInput *shi, ShadeResult *shr)
{
@ -1564,7 +1547,7 @@ void shade_color(ShadeInput *shi, ShadeResult *shr)
if(ma->mode & (MA_ZTRA|MA_RAYTRANSP)) {
if(ma->fresnel_tra!=1.0)
ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra);
ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->ang, ma->fresnel_tra);
}
shr->diff[0]= ma->r;
@ -1896,7 +1879,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr, int mask)
if(ma->mode & (MA_ZTRA|MA_RAYTRANSP)) {
if(ma->fresnel_tra!=1.0)
ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra);
ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->ang, ma->fresnel_tra);
if(ma->spectra!=0.0) {

View File

@ -1054,16 +1054,17 @@ static void render_panel_render()
uiDefButS(block, ROW,B_DIFF,"75%", 565,90,36,20,&G.scene->r.size,1.0,75.0, 0, 0, "Set render size to 3/4 of defined size");
uiDefButS(block, ROW,B_DIFF,"50%", 604,90,40,20,&G.scene->r.size,1.0,50.0, 0, 0, "Set render size to 1/2 of defined size");
uiDefButS(block, ROW,B_DIFF,"25%", 647,90,39,20,&G.scene->r.size,1.0,25.0, 0, 0, "Set render size to 1/4 of defined size");
uiBlockEndAlign(block);
uiDefButI(block, TOG|BIT|6,0,"Fields", 564,42,90,31,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
uiBlockBeginAlign(block);
uiDefButI(block, TOG|BIT|13,0,"Odd", 655,57,30,16,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
uiDefButI(block, TOG|BIT|7,0,"x", 655,42,30,15,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
uiBlockEndAlign(block);
uiDefButI(block, TOG|BIT|6,0,"Fields", 564,50,60,23,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
uiDefButI(block, TOG|BIT|13,0,"Odd", 624,50,40,23,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
uiDefButI(block, TOG|BIT|7,0,"x", 655,50,20,23,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
uiDefButI(block, TOG|BIT|17,0,"Gauss", 564,30,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Gauss sampling filter for antialiasing");
uiDefButF(block, NUM,B_DIFF,"", 624,30,60,20,&G.scene->r.gauss,0.5, 2.0, 0, 0, "Sets the Gauss filter size)");
uiDefButI(block, TOG|BIT|9,REDRAWVIEWCAM, "Border", 565,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image");
uiDefButI(block, TOG|BIT|2,0, "Gamma", 626,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
uiDefButI(block, TOG|BIT|9,REDRAWVIEWCAM, "Border", 564,10,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image");
uiDefButI(block, TOG|BIT|2,0, "Gamma", 624,10,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
}

View File

@ -2025,9 +2025,7 @@ void do_matbuts(unsigned short event)
case B_MATRAYTRANSP:
ma= G.buts->lockpoin;
if(ma) {
// set ztra when you disable ray-tra, is nicer
if(ma->mode & MA_RAYTRANSP) ma->mode &= ~MA_ZTRA;
else ma->mode |= MA_ZTRA;
ma->mode &= ~MA_ZTRA;
allqueue(REDRAWBUTSSHADING, 0);
BIF_preview_changed(G.buts);
}
@ -2256,7 +2254,7 @@ static void material_panel_tramir(Material *ma)
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, B_MATPRV, "RayMir ", 10,180,200,19, &(ma->ray_mirror), 0.0, 1.0, 100, 2, "Sets the amount mirror reflection for raytrace");
uiDefButI(block, TOG|BIT|18, B_MATPRV,"Ray Mirror",210,180,100,19, &(ma->mode), 0, 0, 0, 0, "Enables raytracing for mirror reflection rendering");
uiDefButF(block, NUMSLI, B_MATPRV, "Fresnel ", 10,160,200,19, &(ma->fresnel_mir), 1.0, 1.5, 10, 2, "Amount of Fresnel for mirror reflection");
uiDefButF(block, NUMSLI, B_MATPRV, "Fresnel ", 10,160,200,19, &(ma->fresnel_mir), 0.0, 5.0, 100, 2, "Power of Fresnel for mirror reflection");
uiDefButS(block, NUM, B_MATPRV, "Depth:", 210,160,100,19, &(ma->ray_depth), 0.0, 10.0, 100, 0, "Amount of inter-reflections calculated maximal ");
uiBlockBeginAlign(block);
@ -2266,7 +2264,7 @@ static void material_panel_tramir(Material *ma)
uiDefButF(block, NUMSLI, B_MATPRV, "IOR ", 10,110,200,19, &(ma->ang), 1.0, 3.0, 100, 2, "Sets the angular index of refraction for raytrace");
uiDefButI(block, TOG|BIT|17, B_MATRAYTRANSP,"Ray Transp",210,110,100,19, &(ma->mode), 0, 0, 0, 0, "Enables raytracing for transparency rendering");
uiDefButF(block, NUMSLI, B_MATPRV, "Fresnel ", 10,90,200,19, &(ma->fresnel_tra), 1.0, 1.5, 10, 2, "Amount of Fresnel for transparency");
uiDefButF(block, NUMSLI, B_MATPRV, "Fresnel ", 10,90,200,19, &(ma->fresnel_tra), 0.0, 5.0, 100, 2, "Power of Fresnel for transparency");
uiDefButS(block, NUM, B_MATPRV, "Depth:", 210,90,100,19, &(ma->ray_depth_tra), 0.0, 10.0, 100, 0, "Amount of refractions calculated maximal ");
uiBlockBeginAlign(block);

View File

@ -701,7 +701,7 @@ static void refraction_prv(int *x, int *y, float *n, float index)
static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *rect, int smooth)
{
extern float fresnel_fac(float *view, float *vn, float fresnel);
extern float fresnel_fac(float *view, float *vn, float ior, float fac);
Material *mat;
float v1,inp, inprspec=0, isr=0.0, isb=0.0, isg=0.0;
float ir=0.0, ib=0.0, ig=0.0;
@ -860,7 +860,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
/* scale */
div= (0.85*shi->ref[1]);
shi->refcol[0]= mat->ray_mirror*fresnel_fac(view, shi->vn, mat->fresnel_mir);
shi->refcol[0]= mat->ray_mirror*fresnel_fac(view, shi->vn, mat->ang, mat->fresnel_mir);
if(div<0.0) {
/* minus 0.5 prevents too many small tiles in distance */
@ -907,7 +907,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
if(mat->mode & (MA_ZTRA|MA_RAYTRANSP))
if(mat->fresnel_tra!=0.0)
alpha*= fresnel_fac(view, shi->vn, mat->fresnel_tra);
alpha*= fresnel_fac(view, shi->vn, mat->ang, mat->fresnel_tra);
/* ztra shade */
if(mat->spectra!=0.0) {