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:
-rw-r--r--source/blender/blenkernel/bad_level_call_stubs/stubs.c2
-rw-r--r--source/blender/blenkernel/intern/displist.c3
-rw-r--r--source/blender/blenkernel/intern/material.c2
-rw-r--r--source/blender/blenloader/intern/readfile.c9
-rw-r--r--source/blender/makesdna/DNA_material_types.h4
-rw-r--r--source/blender/render/extern/include/render.h4
-rw-r--r--source/blender/render/intern/source/rendercore.c54
-rw-r--r--source/blender/src/buttons_shading.c9
-rw-r--r--source/blender/src/previewrender.c3
-rwxr-xr-xsource/blender/src/transform_conversions.c8
10 files changed, 90 insertions, 8 deletions
diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
index cca654e9268..894ac8fc6fb 100644
--- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c
+++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
@@ -97,8 +97,10 @@ float Phong_Spec(float *n, float *l, float *v, int hard){return 0;}
float Blinn_Spec(float *n, float *l, float *v, float a, float b){return 0;}
float CookTorr_Spec(float *n, float *l, float *v, int hard){return 0;}
float Toon_Spec(float *n, float *l, float *v, float a, float b){return 0;}
+float WardIso_Spec(float *n, float *l, float *v, float a){return 0;}
float Toon_Diff(float *n, float *l, float *v, float a, float b){return 0;}
float OrenNayar_Diff(float *n, float *l, float *v, float a, float b){return 0;}
+float Minnaert_Diff(float nl, float *n, float *v, float a){return 0;}
void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b){}
void ramp_diffuse_result(float *diff, ShadeInput *shi){}
void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec){}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 1164e46136e..54fffdac28f 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -567,6 +567,7 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
if(ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(nor, lv, shi.view, ma->roughness);
else if(ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(nor, lv, shi.view, ma->param[0], ma->param[1]);
+ else if(ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(is, nor, shi.view, ma->darkness);
}
back= 0;
@@ -596,6 +597,8 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
specfac= CookTorr_Spec(nor, lv, shi.view, shi.har);
else if(ma->spec_shader==MA_SPEC_BLINN)
specfac= Blinn_Spec(nor, lv, shi.view, ma->refrac, (float)shi.har);
+ else if(ma->spec_shader==MA_SPEC_WARDISO)
+ specfac= WardIso_Spec(nor, lv, shi.view, ma->rms);
else
specfac= Toon_Spec(nor, lv, shi.view, ma->param[2], ma->param[3]);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index a96345da9eb..df4dfd3ac7b 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -100,6 +100,8 @@ void init_material(Material *ma)
ma->param[1]= 0.1;
ma->param[2]= 0.5;
ma->param[3]= 0.1;
+ ma->rms=0.1;
+ ma->darkness=1.0;
ma->ang= 1.0;
ma->ray_depth= 2;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0d04fff7343..f2db3d25621 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4223,6 +4223,8 @@ static void do_versions(Main *main)
ma->param[1]= 0.1;
ma->param[2]= 0.1;
ma->param[3]= 0.05;
+ ma->rms=0.1;
+ ma->darkness=1.0;
}
// patch for old wrong max view2d settings, allows zooming out more
for (sc= main->screen.first; sc; sc= sc->id.next) {
@@ -4636,6 +4638,7 @@ static void do_versions(Main *main)
Object *ob;
Scene *sce= main->scene.first;
Camera *cam= main->camera.first;
+ Material *ma;
bScreen *sc;
while(sce) {
@@ -4662,6 +4665,12 @@ static void do_versions(Main *main)
}
}
}
+ // init new shader vars
+ for (ma= main->mat.first; ma; ma= ma->id.next) {
+ ma->rms=0.1;
+ ma->darkness=1.0;
+ }
+
/* temporal copy */
for(ob= main->object.first; ob; ob= ob->id.next) {
if(ob->softflag && ob->soft==NULL) {
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index d241c1e1c36..c60fa32db09 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -83,6 +83,8 @@ typedef struct Material {
short diff_shader, spec_shader;
float roughness, refrac;
float param[4]; /* size, smooth, size, smooth, for toonshader */
+ float rms;
+ float darkness;
short texco, mapto;
/* ramp colors */
@@ -152,12 +154,14 @@ typedef struct Material {
#define MA_DIFF_LAMBERT 0
#define MA_DIFF_ORENNAYAR 1
#define MA_DIFF_TOON 2
+#define MA_DIFF_MINNAERT 3
/* spec_shader */
#define MA_SPEC_COOKTORR 0
#define MA_SPEC_PHONG 1
#define MA_SPEC_BLINN 2
#define MA_SPEC_TOON 3
+#define MA_SPEC_WARDISO 4
/* dynamode */
#define MA_DRAW_DYNABUTS 1
diff --git a/source/blender/render/extern/include/render.h b/source/blender/render/extern/include/render.h
index 77e2125d314..b0c7939b3ab 100644
--- a/source/blender/render/extern/include/render.h
+++ b/source/blender/render/extern/include/render.h
@@ -171,14 +171,16 @@ struct EnvMap *RE_add_envmap(void);
struct EnvMap *RE_copy_envmap(struct EnvMap *env);
/* --------------------------------------------------------------------- */
-/* rendercore (10) */
+/* rendercore (12) */
/* --------------------------------------------------------------------- */
float Phong_Spec(float *n, float *l, float *v, int hard);
float CookTorr_Spec(float *n, float *l, float *v, int hard);
float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power);
float Toon_Spec( float *n, float *l, float *v, float size, float smooth);
+float WardIso_Spec(float *n, float *l, float *v, float rms);
float OrenNayar_Diff(float *n, float *l, float *v, float rough);
float Toon_Diff( float *n, float *l, float *v, float size, float smooth);
+float Minnaert_Diff( float nl, float *n, float *v, float darkness);
void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b);
void ramp_diffuse_result(float *diff, ShadeInput *shi);
void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec);
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index 98aa265d3c6..6b54b88f548 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -822,6 +822,35 @@ float Toon_Spec( float *n, float *l, float *v, float size, float smooth )
return rslt;
}
+/* Ward isotropic gaussian spec */
+float WardIso_Spec( float *n, float *l, float *v, float rms)
+{
+ float i, nh, nv, nl, h[3], angle, alpha;
+
+
+ /* half-way vector */
+ h[0] = l[0] + v[0];
+ h[1] = l[1] + v[1];
+ h[2] = l[2] + v[2];
+ Normalise(h);
+
+ nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */
+ if(nh<=0.0) nh = 0.001;
+
+ nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
+ if(nv<=0.0) nv = 0.001;
+
+ nl = n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
+ if(nl<=0.0) nl = 0.001;
+
+ angle = tan(saacos(nh));
+ alpha = MAX2(rms,0.001);
+
+ i=(1.0/(4*PI*alpha*alpha)) * (exp( -(angle*angle)/(alpha*alpha))/(sqrt(nv*nl)));
+
+ return i;
+}
+
/* cartoon render diffuse */
float Toon_Diff( float *n, float *l, float *v, float size, float smooth )
{
@@ -908,6 +937,28 @@ float OrenNayar_Diff(float *n, float *l, float *v, float rough )
return OrenNayar_Diff_i(nl, n, l, v, rough);
}
+/* Minnaert diffuse */
+float Minnaert_Diff(float nl, float *n, float *v, float darkness)
+{
+
+float i, nv;
+
+ /* nl = dot product between surface normal and light vector */
+ if (nl <= 0.0)
+ return 0;
+
+ /* nv = dot product between surface normal and view vector */
+ nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2];
+ if (nv < 0.0)
+ nv = 0;
+
+ if (darkness <= 1)
+ i = nl * pow(MAX2(nv*nl, 0.1), (darkness - 1) ); /*The Real model*/
+ else
+ i = nl * pow( (1.001 - nv), (darkness - 1) ); /*Nvidia model*/
+
+ return i;
+}
/* --------------------------------------------- */
/* also called from texture.c */
@@ -1520,6 +1571,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
/* diffuse shaders (oren nayer gets inp from area light) */
if(ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff_i(inp, vn, lv, view, ma->roughness);
else if(ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]);
+ else if(ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(inp, vn, view, ma->darkness);
else is= inp; // Lambert
}
@@ -1594,6 +1646,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
specfac= CookTorr_Spec(vn, lv, view, shi->har);
else if(ma->spec_shader==MA_SPEC_BLINN)
specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har);
+ else if(ma->spec_shader==MA_SPEC_WARDISO)
+ specfac= WardIso_Spec( vn, lv, view, ma->rms);
else
specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]);
diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c
index 6121ae0df0e..31448a754cd 100644
--- a/source/blender/src/buttons_shading.c
+++ b/source/blender/src/buttons_shading.c
@@ -2874,8 +2874,8 @@ static void material_panel_shading(Material *ma)
uiBlockEndAlign(block);
}
else {
- char *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2";
- char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3";
+ char *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2|Minnaert %x3";
+ char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3|WardIso %x4";
/* diff shader buttons */
uiDefButS(block, MENU, B_MATPRV_DRAW, str1, 9, 180,78,19, &(ma->diff_shader), 0.0, 0.0, 0, 0, "Creates a diffuse shader");
@@ -2888,6 +2888,8 @@ static void material_panel_shading(Material *ma)
uiDefButF(block, NUMSLI, B_MATPRV, "Size:", 90, 160,150,19, &(ma->param[0]), 0.0, 3.14, 0, 0, "Sets size of diffuse toon area");
uiDefButF(block, NUMSLI, B_MATPRV, "Smooth:",90,140,150,19, &(ma->param[1]), 0.0, 1.0, 0, 0, "Sets smoothness of diffuse toon area");
}
+ else if(ma->diff_shader==MA_DIFF_MINNAERT)
+ uiDefButF(block, NUMSLI, B_MATPRV, "Dark:",90,160, 150,19, &(ma->darkness), 0.0, 2.0, 0, 0, "Sets Minnaert darkness");
uiBlockEndAlign(block);
/* spec shader buttons */
@@ -2904,7 +2906,8 @@ static void material_panel_shading(Material *ma)
uiDefButF(block, NUMSLI, B_MATPRV, "Size:", 90, 100,150,19, &(ma->param[2]), 0.0, 1.53, 0, 0, "Sets the size of specular toon area");
uiDefButF(block, NUMSLI, B_MATPRV, "Smooth:",90, 80,150,19, &(ma->param[3]), 0.0, 1.0, 0, 0, "Sets the smoothness of specular toon area");
}
-
+ if(ma->spec_shader==MA_SPEC_WARDISO)
+ uiDefButF(block, NUMSLI, B_MATPRV, "rms:", 90, 100,150,19, &(ma->rms), 0.0, 0.4, 0, 0, "Sets the standard deviation of surface slope");
/* default shading variables */
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, 0, "Translucency ", 9,30,301,19, &(ma->translucency), 0.0, 1.0, 100, 2, "Amount of diffuse shading of the back side");
diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c
index 87d79a46cc0..e77ae44299a 100644
--- a/source/blender/src/previewrender.c
+++ b/source/blender/src/previewrender.c
@@ -888,6 +888,8 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
specfac= CookTorr_Spec(shi->vn, lv, shi->view, shi->har);
else if(mat->spec_shader==MA_SPEC_BLINN)
specfac= Blinn_Spec(shi->vn, lv, shi->view, mat->refrac, (float)shi->har);
+ else if(mat->spec_shader==MA_SPEC_WARDISO)
+ specfac= WardIso_Spec(shi->vn, lv, shi->view, mat->rms);
else
specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3]);
@@ -910,6 +912,7 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
/* diffuse shaders */
if(mat->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(shi->vn, lv, shi->view, mat->roughness);
else if(mat->diff_shader==MA_DIFF_TOON) is= Toon_Diff(shi->vn, lv, shi->view, mat->param[0], mat->param[1]);
+ else if(mat->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(is, shi->vn, shi->view, mat->darkness);
// else Lambert
inp= (shi->refl*is + shi->emit);
diff --git a/source/blender/src/transform_conversions.c b/source/blender/src/transform_conversions.c
index 2d2214b20b9..eea30fd0974 100755
--- a/source/blender/src/transform_conversions.c
+++ b/source/blender/src/transform_conversions.c
@@ -1046,8 +1046,8 @@ static void createTransEditVerts(TransInfo *t)
t->total = count;
/* allocating scratch arrays */
- vectors = (float *)malloc(t->total * 3 * sizeof(float));
- nears = (EditVert**)malloc(t->total * sizeof(EditVert*));
+ vectors = (float *)MEM_mallocN(t->total * 3 * sizeof(float), "scratch vectors");
+ nears = (EditVert**)MEM_mallocN(t->total * sizeof(EditVert*), "scratch nears");
}
else t->total = countsel;
tob= t->data= MEM_mallocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
@@ -1084,8 +1084,8 @@ static void createTransEditVerts(TransInfo *t)
}
}
if (propmode) {
- free(vectors);
- free(nears);
+ MEM_freeN(vectors);
+ MEM_freeN(nears);
}
}