From 9bf630a1f32a264b5e0a6842ebb812e7eb52556e Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sat, 19 Jul 2003 20:31:29 +0000 Subject: [PATCH] WARNING: with makefiles I could not get a stable blender compiled. do a make clean in source/blender/ to be sure! - Included the new shaders from Cessen... well, only the shader calls themselves. To make sure the shaders work I nicely integrated it - MaterialButtons: layout changed a bit, but still resembles the old layout. The 'shader' options now are located together. - Shaders are separated in 'diffuse' and 'specular'. You can combine them freely. - diffuse Lambert: old shader diffuse Oren Nayar: new shader, gives sandy/silky/skinny material well diffuse Toon: for cartoon render - specular Phong: new spec, traditional 70ies spec specular CookTorr: a reduced version of cook torrance shading, does off specular peak well specular Blinn: new spec, same features as CookTorr, but with extra 'refraction' setting specular Toon: new spec for cartoon render - default blender starts with settings that render compatible! - works in shaded view and preview-render - works in unified render Further little changes: - removed paranoia compile warnings from render/loader/blenlib - and the warnings at files I worked at were removed. --- .../blender/blenkernel/BKE_bad_level_calls.h | 2 +- .../blenkernel/bad_level_call_stubs/stubs.c | 2 +- source/blender/blenkernel/intern/displist.c | 23 +- source/blender/blenkernel/intern/material.c | 23 +- source/blender/blenlib/intern/Makefile | 2 +- source/blender/blenloader/intern/Makefile | 2 +- source/blender/blenloader/intern/readfile.c | 9 + source/blender/include/interface.h | 2 +- source/blender/makesdna/DNA_material_types.h | 16 +- source/blender/render/extern/include/render.h | 7 +- .../render/intern/include/rendercore.h | 6 +- .../render/intern/include/rendercore_int.h | 1 - source/blender/render/intern/source/Makefile | 2 +- .../render/intern/source/pixelshading.c | 32 ++- .../blender/render/intern/source/rendercore.c | 222 ++++++++++++++++-- .../blender/renderconverter/intern/Makefile | 2 +- source/blender/src/buttons.c | 169 +++++++------ source/blender/src/previewrender.c | 49 ++-- 18 files changed, 430 insertions(+), 141 deletions(-) diff --git a/source/blender/blenkernel/BKE_bad_level_calls.h b/source/blender/blenkernel/BKE_bad_level_calls.h index 420a915adf6..045fcb7ba7c 100644 --- a/source/blender/blenkernel/BKE_bad_level_calls.h +++ b/source/blender/blenkernel/BKE_bad_level_calls.h @@ -70,7 +70,7 @@ extern struct ListBase editNurb; #include "DNA_world_types.h" /* for render_types */ #include "render_types.h" extern struct RE_Render R; -float RE_Spec(float, int); +float Phong_Spec(float *, float *, float *, int); void waitcursor(int); void allqueue(unsigned short event, short val); #define REDRAWVIEW3D 0x4010 diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c index 01e2acfb6c7..8c75e0b025a 100644 --- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c +++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c @@ -87,7 +87,7 @@ ListBase editNurb; #include "DNA_world_types.h" /* for render_types */ #include "render_types.h" struct RE_Render R; -float RE_Spec(float inp, int hard){return 0;} +float Phong_Spec(float *n, float *l, float *v, int hard){return 0;} void waitcursor(int val){} void allqueue(unsigned short event, short val){} #define REDRAWVIEW3D 0x4010 diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index ab91a33c259..f3beea7c389 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -47,6 +47,7 @@ #include "MEM_guardedalloc.h" #include "nla.h" /* For __NLA: Please do not remove yet */ +#include "render.h" #include "IMB_imbuf_types.h" @@ -301,7 +302,7 @@ void freefastshade() static void fastshade(float *co, float *nor, float *orco, Material *ma, char *col1, char *col2, char *vertcol) { FastLamp *fl; - float i, t, inp, soft, inpr, inpg, inpb, isr=0, isg=0, isb=0, lv[3], lampdist, ld; + float i, t, inp, soft, inpr, inpg, inpb, isr=0, isg=0, isb=0, lv[3], view[3], lampdist, ld; float inpr1, inpg1, inpb1, isr1=0, isg1=0, isb1=0; int a, back; @@ -447,6 +448,9 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co inp= nor[0]*lv[0]+ nor[1]*lv[1]+ nor[2]*lv[2]; + if(ma->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(nor, lv, view, ma->roughness); + else if(ma->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(nor, lv, view, ma->param[0], ma->param[1]); + back= 0; if(inp<0.0) { back= 1; @@ -465,11 +469,20 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co } if(ma->spec) { - lv[2]+= 1.0; - Normalise(lv); - t= nor[0]*lv[0]+nor[1]*lv[1]+nor[2]*lv[2]; + VECCOPY(view, fl->co); + Normalise(view); + + if(ma->spec_shader==MA_SPEC_PHONG) + t= Phong_Spec(nor, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_COOKTORR) + t= CookTorr_Spec(nor, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_BLINN) + t= Blinn_Spec(nor, lv, view, ma->refrac, (float)ma->har); + else + t= Toon_Spec(nor, lv, view, ma->param[2], ma->param[3]); + if(t>0) { - t= ma->spec*lampdist*RE_Spec(t, ma->har); + t*= ma->spec*lampdist; if(back==0) { isr+= t*(fl->r * ma->specr); isg+= t*(fl->g * ma->specg); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 3639b64e63c..a74670dbde9 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -82,18 +82,25 @@ void free_material(Material *ma) void init_material(Material *ma) { ma->lay= 1; - ma->r= ma->g= ma->b= ma->ref= 0.8f; - ma->specr= ma->specg= ma->specb= 1.0f; - ma->mirr= ma->mirg= ma->mirb= 1.0f; - ma->amb= 0.5f; - ma->alpha= 1.0f; - ma->spec= ma->hasize= 0.5f; + ma->r= ma->g= ma->b= ma->ref= 0.8; + ma->specr= ma->specg= ma->specb= 1.0; + ma->mirr= ma->mirg= ma->mirb= 1.0; + ma->amb= 0.5; + ma->alpha= 1.0; + ma->spec= ma->hasize= 0.5; ma->har= 50; ma->starc= ma->ringc= 4; ma->linec= 12; ma->flarec= 1; - ma->flaresize= ma->subsize= 1.0f; - ma->friction= 0.5f; + ma->flaresize= ma->subsize= 1.0; + ma->friction= 0.5; + ma->refrac= 4.0; + ma->roughness= 0.5; + ma->param[0]= 0.5; + ma->param[1]= 0.1; + ma->param[2]= 0.5; + ma->param[3]= 0.1; + ma->mode= MA_TRACEBLE+MA_SHADOW; } diff --git a/source/blender/blenlib/intern/Makefile b/source/blender/blenlib/intern/Makefile index 7ce3441d875..6644f13928b 100644 --- a/source/blender/blenlib/intern/Makefile +++ b/source/blender/blenlib/intern/Makefile @@ -40,7 +40,7 @@ ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windo CFLAGS += -funsigned-char endif -CPPFLAGS += $(LEVEL_2_C_WARNINGS) +# CPPFLAGS += $(LEVEL_2_C_WARNINGS) # path to SDNA types CPPFLAGS += -I../../makesdna diff --git a/source/blender/blenloader/intern/Makefile b/source/blender/blenloader/intern/Makefile index bbda61c53f5..130e936886e 100644 --- a/source/blender/blenloader/intern/Makefile +++ b/source/blender/blenloader/intern/Makefile @@ -36,7 +36,7 @@ DIR = $(OCGDIR)/blender/$(LIBNAME) include nan_compile.mk -CFLAGS += $(LEVEL_2_C_WARNINGS) +# CFLAGS += $(LEVEL_2_C_WARNINGS) ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows")) CFLAGS += -funsigned-char diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 5aecd18b231..ec051b0ec22 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3696,11 +3696,20 @@ static void do_versions(Main *main) } if(main->versionfile <= 227) { Scene *sce; + Material *ma; for (sce= main->scene.first; sce; sce= sce->id.next) { sce->audio.mixrate = 44100; sce->audio.flag |= (AUDIO_SYNC + AUDIO_SCRUB); } + for (ma= main->mat.first; ma; ma= ma->id.next) { + ma->refrac= 4.0; + ma->roughness= 0.5; + ma->param[0]= 0.5; + ma->param[1]= 0.1; + ma->param[2]= 0.1; + ma->param[3]= 0.05; + } } /* don't forget to set version number in blender.c! */ diff --git a/source/blender/include/interface.h b/source/blender/include/interface.h index f820af5ddd4..8a9f5330221 100644 --- a/source/blender/include/interface.h +++ b/source/blender/include/interface.h @@ -110,7 +110,7 @@ #define UI_BLOCK_BUSY 8 #define UI_BLOCK_NUMSELECT 16 #define UI_BLOCK_ENTER_OK 32 -#define UI_BLOCK_MENUMODE 128 + /* uiBlock->dt */ #define UI_EMBOSSX 0 /* Rounded embossed button */ diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h index 3789a296120..36b3e811953 100644 --- a/source/blender/makesdna/DNA_material_types.h +++ b/source/blender/makesdna/DNA_material_types.h @@ -69,7 +69,10 @@ typedef struct Material { char rgbsel, texact, pr_type, septex; short pr_back, pr_lamp; - int pad1; + /* shaders */ + short diff_shader, spec_shader; + float roughness, refrac; + float param[4]; /* size, smooth, size, smooth, for toonshader */ short texco, mapto; struct MTex *mtex[8]; @@ -120,6 +123,17 @@ typedef struct Material { #define MA_HALO_SHADE 0x4000 #define MA_HALO_FLARE 0x8000 +/* diff_shader */ +#define MA_DIFF_LAMBERT 0 +#define MA_DIFF_ORENNAYAR 1 +#define MA_DIFF_TOON 2 + +/* spec_shader */ +#define MA_SPEC_COOKTORR 0 +#define MA_SPEC_PHONG 1 +#define MA_SPEC_BLINN 2 +#define MA_SPEC_TOON 3 + /* dynamode */ #define MA_DRAW_DYNABUTS 1 #define MA_FH_NOR 2 diff --git a/source/blender/render/extern/include/render.h b/source/blender/render/extern/include/render.h index 972134f8be7..40bebb43c24 100644 --- a/source/blender/render/extern/include/render.h +++ b/source/blender/render/extern/include/render.h @@ -189,7 +189,12 @@ int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt); /* --------------------------------------------------------------------- */ /* rendercore (2) */ /* --------------------------------------------------------------------- */ - float RE_Spec(float inp, int hard); + 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 OrenNayar_Diff(float *n, float *l, float *v, float rough); + float Toon_Diff( float *n, float *l, float *v, float size, float smooth); /* maybe not external */ void RE_calc_R_ref(void); diff --git a/source/blender/render/intern/include/rendercore.h b/source/blender/render/intern/include/rendercore.h index 6808b8a30de..d1ab24550ab 100644 --- a/source/blender/render/intern/include/rendercore.h +++ b/source/blender/render/intern/include/rendercore.h @@ -39,13 +39,13 @@ struct HaloRen; float mistfactor(float *co); /* dist en hoogte, return alpha */ -/* void sky(char *col); */ void renderspothalo(unsigned short *col); void render_lighting_halo(struct HaloRen *har, float *colf); unsigned int calchalo_z(struct HaloRen *har, unsigned int zz); -float CookTorr(float *n, float *l, float *v, int hard); + +float spec(float inp, int hard); + void shade_lamp_loop(void); -/* void renderflare(struct HaloRen *har); */ void add_halo_flare(void); /** diff --git a/source/blender/render/intern/include/rendercore_int.h b/source/blender/render/intern/include/rendercore_int.h index 45b881fe27f..5ee63eb68ee 100644 --- a/source/blender/render/intern/include/rendercore_int.h +++ b/source/blender/render/intern/include/rendercore_int.h @@ -38,7 +38,6 @@ #include "zbuf_types.h" #include "render_types.h" -/* float CookTorr(float *n, float *l, float *v, int hard); */ void do_lamphalo_tex(LampRen *lar, float *p1, float *p2, float *intens); void spothalo(struct LampRen *lar, float *view, float *intens); void add_filt_mask(unsigned int mask, unsigned short *col, unsigned int *rb1, unsigned int *rb2, unsigned int *rb3); diff --git a/source/blender/render/intern/source/Makefile b/source/blender/render/intern/source/Makefile index ff8fc1fceae..fc14bec1267 100644 --- a/source/blender/render/intern/source/Makefile +++ b/source/blender/render/intern/source/Makefile @@ -41,7 +41,7 @@ ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windo CCFLAGS += -funsigned-char endif -CFLAGS += $(LEVEL_2_C_WARNINGS) +# CFLAGS += $(LEVEL_2_C_WARNINGS) # first /include is my own includes, second is the external interface. # The external modules follow after. There should be a nicer way to say this. diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index 3a61f95016d..1c2ac2509c7 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -1172,6 +1172,12 @@ void shadeLampLusFloat() if(lar->type==LA_HEMI) { i= 0.5*i+0.5; } + else { + /* diffuse shaders */ + if(ma->diff_shader==MA_DIFF_ORENNAYAR) i= OrenNayar_Diff(vn, lv, view, ma->roughness); + else if(ma->diff_shader==MA_DIFF_TOON) i= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); + else i= inp; // Lambert + } if(i>0.0) { i*= lampdist*ma->ref; } @@ -1213,15 +1219,27 @@ void shadeLampLusFloat() } /* watch it: shadfac and lampdist used below */ - t= ma->spec*RE_Spec(t, ma->har); + /* sun and hemi use no shaders */ + t= ma->spec*spec(t, ma->har); isr+= t*(lar->r * ma->specr); isg+= t*(lar->g * ma->specg); isb+= t*(lar->b * ma->specb); } else { - /* Does specular reflection? This would be the place */ - /* to put BRDFs. */ - t= shadfac*ma->spec*lampdist*CookTorr(vn, lv, view, ma->har); + /* specular shaders */ + float specfac; + + if(ma->spec_shader==MA_SPEC_PHONG) + specfac= Phong_Spec(vn, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_COOKTORR) + specfac= CookTorr_Spec(vn, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_BLINN) + specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)ma->har); + else + specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]); + + t= shadfac*ma->spec*lampdist*specfac; + isr+= t*(lar->r * ma->specr); isg+= t*(lar->g * ma->specg); isb+= t*(lar->b * ma->specb); @@ -1240,12 +1258,6 @@ void shadeLampLusFloat() * gammaCorrect implementation doesn't handle negative values * correctly ( (-1)^2 = 1!!) (ton) */ -/* if(ir<0.0) ir= 0.0; */ -/* if(ig<0.0) ig= 0.0; */ -/* if(ib<0.0) ib= 0.0; */ -/* if(isr<0.0) isr= 0.0; */ -/* if(isg<0.0) isg= 0.0; */ -/* if(isb<0.0) isb= 0.0; */ /* Well, it does now. -(1^2) = -1 :) (nzc) */ if(ma->mode & MA_ZTRA) { /* ztra shade */ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index bfe85159c77..b34f5bd1a29 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -30,10 +30,6 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -/* system includes */ -#include -#include -#include /* External modules: */ #include "MEM_guardedalloc.h" @@ -64,6 +60,12 @@ #include "jitter.h" +/* system includes */ +#include +#include +#include + + /* own include */ #include "rendercore.h" #include "rendercore_int.h" @@ -1277,7 +1279,10 @@ void halovert() } } -float RE_Spec(float inp, int hard) +/* ---------------- shaders ----------------------- */ + + +float spec(float inp, int hard) { float b1; @@ -1313,8 +1318,27 @@ float RE_Spec(float inp, int hard) return inp; } +float Phong_Spec( float *n, float *l, float *v, int hard ) +{ + float h[3]; + float rslt; -float CookTorr(float *n, float *l, float *v, int hard) + h[0] = l[0] + v[0]; + h[1] = l[1] + v[1]; + h[2] = l[2] + v[2]; + Normalise(h); + + rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; + + if( rslt > 0.0 ) rslt= spec(rslt, hard); + else rslt = 0.0; + + return rslt; +} + + +/* reduced cook torrance spec (for off-specular peak) */ +float CookTorr_Spec(float *n, float *l, float *v, int hard) { float i, nh, nv, h[3]; @@ -1327,12 +1351,162 @@ float CookTorr(float *n, float *l, float *v, int hard) if(nh<0.0) return 0.0; nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; if(nv<0.0) nv= 0.0; - i= RE_Spec(nh, hard); + i= spec(nh, hard); i= i/(0.1+nv); return i; } +/* Blinn spec */ +float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power ) +{ + float i, nh, nv, nl, vh, h[3]; + float a, b, c, g, p, f, ang; + + if(refrac < 1.0) return 0.0; + if(spec_power == 0.0) return 0.0; + + /* conversion from 'hardness' (1-255) to 'spec_power' (50 maps at 0.1) */ + spec_power= sqrt(1.0/spec_power); + + h[0]= v[0]+l[0]; + h[1]= v[1]+l[1]; + h[2]= v[2]+l[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) return 0.0; + + 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.01; + + 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.0; + return 0.0; + } + + vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and half-way vector. */ + if(vh<=0.0) vh= 0.01; + + a = 1.0; + b = (2.0*nh*nv)/vh; + c = (2.0*nh*nl)/vh; + + if( a < b && a < c ) g = a; + else if( b < a && b < c ) g = b; + else if( c < a && c < b ) g = c; + + p = sqrt( (double)((refrac * refrac)+(vh*vh)-1.0) ); + f = (((p-vh)*(p-vh))/((p+vh)*(p+vh)))*(1+((((vh*(p+vh))-1.0)*((vh*(p+vh))-1.0))/(((vh*(p-vh))+1.0)*((vh*(p-vh))+1.0)))); + ang = (float)acos((double)(nh)); + + i= f * g * exp((double)(-(ang*ang) / (2.0*spec_power*spec_power))); + + return i; +} + +/* cartoon render spec */ +float Toon_Spec( float *n, float *l, float *v, float size, float smooth ) +{ + float h[3]; + float ang; + float rslt; + + h[0] = l[0] + v[0]; + h[1] = l[1] + v[1]; + h[2] = l[2] + v[2]; + Normalise(h); + + rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; + + ang = acos( rslt ); + + if( ang < size ) rslt = 1.0; + else if( ang >= (size + smooth) || smooth == 0.0 ) rslt = 0.0; + else rslt = 1.0 - ((ang - size) / smooth); + + return rslt; +} + +/* cartoon render diffuse */ +float Toon_Diff( float *n, float *l, float *v, float size, float smooth ) +{ + float rslt, ang; + + rslt = n[0]*l[0] + n[1]*l[1] + n[2]*l[2]; + + ang = acos( (double)(rslt) ); + + if( ang < size ) rslt = 1.0; + else if( ang >= (size + smooth) || smooth == 0.0 ) rslt = 0.0; + else rslt = 1.0 - ((ang - size) / smooth); + + return rslt; +} + +/* Oren Nayar diffuse */ +float OrenNayar_Diff(float *n, float *l, float *v, float rough ) +{ + float i, nh, nv, nl, vh, h[3]; + float a, b, t, A, B; + float Lit_A, View_A, Lit_B[3], View_B[3]; + + h[0]= v[0]+l[0]; + h[1]= v[1]+l[1]; + h[2]= v[2]+l[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.0; + + 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.0; + + 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.0; + + vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and halfway vector. */ + if(vh<=0.0) vh= 0.0; + + Lit_A = acos( nl ); + View_A = acos( nv ); + + Lit_B[0] = l[0] - (nl * n[0]); + Lit_B[1] = l[1] - (nl * n[1]); + Lit_B[2] = l[2] - (nl * n[2]); + Normalise( Lit_B ); + + View_B[0] = v[0] - (nv * n[0]); + View_B[1] = v[1] - (nv * n[1]); + View_B[2] = v[2] - (nv * n[2]); + Normalise( View_B ); + + t = Lit_B[0]*View_B[0] + Lit_B[1]*View_B[1] + Lit_B[2]*View_B[2]; + if( t < 0 ) t = 0; + + if( Lit_A > View_A ) { + a = Lit_A; + b = View_A; + } + else { + a = View_A; + b = Lit_A; + } + + A = 1 - (0.5 * ((rough * rough) / ((rough * rough) + 0.33))); + B = 0.45 * ((rough * rough) / ((rough * rough) + 0.09)); + + i = nl * ( A + ( B * t * sin(a) * tan(b) ) ); + + return i; +} + +/* --------------------------------------------- */ + void RE_calc_R_ref() { float i; @@ -1620,16 +1794,24 @@ void shade_lamp_loop() } /* dot product and reflectivity*/ - inp=i= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; + inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; + if(lar->type==LA_HEMI) { - i= 0.5*i+0.5; + i= 0.5*inp + 0.5; } + else { + /* diffuse shaders */ + if(ma->diff_shader==MA_DIFF_ORENNAYAR) i= OrenNayar_Diff(vn, lv, view, ma->roughness); + else if(ma->diff_shader==MA_DIFF_TOON) i= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); + else i= inp; // Lambert + } + if(i>0.0) { i*= lampdist*ma->ref; } /* shadow and spec */ - if(i> -0.41) { /* heuristic value */ + if(inp> -0.41) { /* heuristic value */ shadfac= 1.0; if(lar->shb) { if(ma->mode & MA_SHADOW) { @@ -1659,15 +1841,27 @@ void shade_lamp_loop() if(lar->type==LA_HEMI) { t= 0.5*t+0.5; } - /* no more speclim */ - - t= ma->spec*RE_Spec(t, ma->har); + /* sun and hemi use no shaders */ + t= ma->spec*spec(t, ma->har); isr+= t*(lar->r * ma->specr); isg+= t*(lar->g * ma->specg); isb+= t*(lar->b * ma->specb); } else { - t= shadfac*ma->spec*lampdist*CookTorr(vn, lv, view, ma->har); + /* specular shaders */ + float specfac; + + if(ma->spec_shader==MA_SPEC_PHONG) + specfac= Phong_Spec(vn, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_COOKTORR) + specfac= CookTorr_Spec(vn, lv, view, ma->har); + else if(ma->spec_shader==MA_SPEC_BLINN) + specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)ma->har); + else + specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]); + + t= shadfac*ma->spec*lampdist*specfac; + isr+= t*(lar->r * ma->specr); isg+= t*(lar->g * ma->specg); isb+= t*(lar->b * ma->specb); diff --git a/source/blender/renderconverter/intern/Makefile b/source/blender/renderconverter/intern/Makefile index 529cb8e0ec7..baa51065c78 100644 --- a/source/blender/renderconverter/intern/Makefile +++ b/source/blender/renderconverter/intern/Makefile @@ -40,7 +40,7 @@ ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windo CFLAGS += -funsigned-char endif -CFLAGS += $(LEVEL_2_C_WARNINGS) +# CFLAGS += $(LEVEL_2_C_WARNINGS) CPPFLAGS += -I$(OPENGL_HEADERS) # path to our own external headerfiles diff --git a/source/blender/src/buttons.c b/source/blender/src/buttons.c index c6eef4b906f..56160b0b4fd 100644 --- a/source/blender/src/buttons.c +++ b/source/blender/src/buttons.c @@ -4121,7 +4121,7 @@ void matbuts(void) sprintf(str, "%d Mat", ob->totcol); if(ob->totcol) min= 1.0; else min= 0.0; - uiDefButC(block, NUM, B_ACTCOL, str, 415,195,140,20, &(ob->actcol), min, (float)ob->totcol, 0, 0, "Number of materials on object / Active material"); + uiDefButC(block, NUM, B_ACTCOL, str, 415,195,150,20, &(ob->actcol), min, (float)ob->totcol, 0, 0, "Number of materials on object / Active material"); uiSetButLock(id->lib!=0, "Can't edit library data"); @@ -4144,40 +4144,35 @@ void matbuts(void) uiSetButLock(ma->id.lib!=0, "Can't edit library data"); uiBlockSetCol(block, BUTGREY); - uiDefButS(block, ROW, REDRAWBUTSMAT, "RGB", 200,166,44,22, &(ma->colormodel), 1.0, (float)MA_RGB, 0, 0, "Create colour by red, green and blue"); - uiDefButS(block, ROW, REDRAWBUTSMAT, "HSV", 200,143,44,22, &(ma->colormodel), 1.0, (float)MA_HSV, 0, 0, "Mix colour with hue, saturation and value"); - uiDefButS(block, TOG|BIT|0, REDRAWBUTSMAT, "DYN", 200,120,44,22, &(ma->dynamode), 0.0, 0.0, 0, 0, "Adjust parameters for dynamics options"); - - if((ma->mode & MA_HALO)==0) - uiDefButF(block, NUM, 0, "Zoffset:", 200,91,174,19, &(ma->zoffs), 0.0, 10.0, 0, 0, "Give face an artificial offset"); + uiDefButS(block, ROW, REDRAWBUTSMAT, "RGB", 200,166,35,22, &(ma->colormodel), 1.0, (float)MA_RGB, 0, 0, "Create colour by red, green and blue"); + uiDefButS(block, ROW, REDRAWBUTSMAT, "HSV", 200,143,35,22, &(ma->colormodel), 1.0, (float)MA_HSV, 0, 0, "Mix colour with hue, saturation and value"); + uiDefButS(block, TOG|BIT|0, REDRAWBUTSMAT, "DYN", 200,120,35,22, &(ma->dynamode), 0.0, 0.0, 0, 0, "Adjust parameters for dynamics options"); if(ma->dynamode & MA_DRAW_DYNABUTS) { - uiDefButF(block, NUMSLI, 0, "Restitut ", 380,168,175,21, &ma->reflect, 0.0, 1.0, 0, 0, "Elasticity of collisions"); - uiDefButF(block, NUMSLI, 0, "Friction ", - 380,144,175,21, &ma->friction, 0.0, 100.0, 0, 0, - "Coulomb friction coefficient"); -/**/ - uiDefButF(block, NUMSLI, 0, "Fh Force ", 380,120,175,21, &ma->fh, 0.0, 1.0, 0, 0, "Upward spring force within the Fh area"); - uiDefButF(block, NUM, 0, "Fh Damp ", 260,144,120,21, &ma->xyfrict, 0.0, 1.0, 10, 0, "Damping of the Fh spring force"); - uiDefButF(block, NUM, 0, "Fh Dist ", 260,120,120,21, &ma->fhdist, 0.0, 20.0, 10, 0, "Height of the Fh area"); + uiDefButF(block, NUMSLI, 0, "Restitut ", 390,168,175,21, &ma->reflect, 0.0, 1.0, 0, 0, "Elasticity of collisions"); + uiDefButF(block, NUMSLI, 0, "Friction ", 390,144,175,21, &ma->friction, 0.0, 100.0, 0, 0, "Coulomb friction coefficient"); + + uiDefButF(block, NUMSLI, 0, "Fh Force ", 390,120,175,21, &ma->fh, 0.0, 1.0, 0, 0, "Upward spring force within the Fh area"); + uiDefButF(block, NUM, 0, "Fh Damp ", 260,144,120,21, &ma->xyfrict, 0.0, 1.0, 10, 0, "Damping of the Fh spring force"); + uiDefButF(block, NUM, 0, "Fh Dist ", 260,120,120,21, &ma->fhdist, 0.0, 20.0, 10, 0, "Height of the Fh area"); uiBlockSetCol(block, BUTGREEN); - uiDefButS(block, TOG|BIT|1, 0, "Fh Norm", 260,168,120,21, &ma->dynamode, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes"); + uiDefButS(block, TOG|BIT|1, 0, "Fh Norm", 260,168,120,21, &ma->dynamode, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes"); uiBlockSetCol(block, BUTGREY); } else { - uiDefButF(block, COL, B_MIRCOL, "", 246,143,37,45, &(ma->mirr), 0, 0, 0, 0, ""); - uiDefButF(block, COL, B_SPECCOL, "", 287,143,37,45, &(ma->specr), 0, 0, 0, 0, ""); - uiDefButF(block, COL, B_MATCOL, "", 326,143,47,45, &(ma->r), 0, 0, 0, 0, ""); + uiDefButF(block, COL, B_MIRCOL, "", 235,143,30,45, &(ma->mirr), 0, 0, 0, 0, ""); + uiDefButF(block, COL, B_SPECCOL, "", 265,143,39,45, &(ma->specr), 0, 0, 0, 0, ""); + uiDefButF(block, COL, B_MATCOL, "", 304,143,39,45, &(ma->r), 0, 0, 0, 0, ""); if(ma->mode & MA_HALO) { - uiDefButC(block, ROW, REDRAWBUTSMAT, "Ring", 246,120,37,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Mix the colour of the rings with the RGB sliders"); - uiDefButC(block, ROW, REDRAWBUTSMAT, "Line", 287,120,37,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Mix the colour of the lines with the RGB sliders"); - uiDefButC(block, ROW, REDRAWBUTSMAT, "Halo", 326,120,47,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Mix the colour of the halo with the RGB sliders"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Ring", 235,120,30,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Mix the colour of the rings with the RGB sliders"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Line", 265,120,39,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Mix the colour of the lines with the RGB sliders"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Halo", 304,120,39,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Mix the colour of the halo with the RGB sliders"); } else { - uiDefButC(block, ROW, REDRAWBUTSMAT, "Mir", 246,120,37,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Use mirror colour"); - uiDefButC(block, ROW, REDRAWBUTSMAT, "Spec", 287,120,37,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Set the colour of the specularity"); - uiDefButC(block, ROW, REDRAWBUTSMAT, "Color", 326,120,47,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Set the basic colour of the material"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Mir", 235,120,30,22, &(ma->rgbsel), 2.0, 2.0, 0, 0, "Use mirror colour"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Spe", 265,120,39,22, &(ma->rgbsel), 2.0, 1.0, 0, 0, "Set the colour of the specularity"); + uiDefButC(block, ROW, REDRAWBUTSMAT, "Col", 304,120,39,22, &(ma->rgbsel), 2.0, 0.0, 0, 0, "Set the basic colour of the material"); } if(ma->rgbsel==0) {colpoin= &(ma->r); rgbsel= B_MATCOL;} else if(ma->rgbsel==1) {colpoin= &(ma->specr); rgbsel= B_SPECCOL;} @@ -4186,80 +4181,106 @@ void matbuts(void) if(ma->rgbsel==0 && (ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE) && !(ma->mode & MA_HALO))); else if(ma->colormodel==MA_HSV) { uiBlockSetCol(block, BUTPURPLE); - uiDefButF(block, HSVSLI, B_MATPRV, "H ", 380,168,175,21, colpoin, 0.0, 0.9999, rgbsel, 0, ""); + uiDefButF(block, HSVSLI, B_MATPRV, "H ", 350,168,150,21, colpoin, 0.0, 0.9999, rgbsel, 0, ""); uiBlockSetCol(block, BUTPURPLE); - uiDefButF(block, HSVSLI, B_MATPRV, "S ", 380,144,175,21, colpoin, 0.0001, 1.0, rgbsel, 0, ""); + uiDefButF(block, HSVSLI, B_MATPRV, "S ", 350,144,150,21, colpoin, 0.0001, 1.0, rgbsel, 0, ""); uiBlockSetCol(block, BUTPURPLE); - uiDefButF(block, HSVSLI, B_MATPRV, "V ", 380,120,175,21, colpoin, 0.0001, 1.0, rgbsel, 0, ""); + uiDefButF(block, HSVSLI, B_MATPRV, "V ", 350,120,150,21, colpoin, 0.0001, 1.0, rgbsel, 0, ""); uiBlockSetCol(block, BUTGREY); } else { - uiDefButF(block, NUMSLI, B_MATPRV, "R ", 380,168,175,21, colpoin, 0.0, 1.0, rgbsel, 0, ""); - uiDefButF(block, NUMSLI, B_MATPRV, "G ", 380,144,175,21, colpoin+1, 0.0, 1.0, rgbsel, 0, ""); - uiDefButF(block, NUMSLI, B_MATPRV, "B ", 380,120,175,21, colpoin+2, 0.0, 1.0, rgbsel, 0, ""); + uiDefButF(block, NUMSLI, B_MATPRV, "R ", 350,168,150,21, colpoin, 0.0, 1.0, rgbsel, 0, ""); + uiDefButF(block, NUMSLI, B_MATPRV, "G ", 350,144,150,21, colpoin+1, 0.0, 1.0, rgbsel, 0, ""); + uiDefButF(block, NUMSLI, B_MATPRV, "B ", 350,120,150,21, colpoin+2, 0.0, 1.0, rgbsel, 0, ""); + } + if(!(ma->mode & MA_HALO)) { + uiBlockSetCol(block, BUTBLUE); + uiDefButI(block, TOG|BIT|4, B_REDR, "VCol Light", 505, 168, 60, 21, &(ma->mode), 0, 0, 0, 0, "Add vertex colours as extra light"); + uiDefButI(block, TOG|BIT|7, B_REDR, "VCol Paint", 505, 144, 60, 21, &(ma->mode), 0, 0, 0, 0, "Replace basic colours with vertex colours"); + uiDefButI(block, TOG|BIT|11, B_REDR, "TexFace", 505, 120, 60, 21, &(ma->mode), 0, 0, 0, 0, "UV-Editor assigned texture gives color and texture info for the faces"); } } if(ma->mode & MA_HALO) { - uiDefButF(block, NUM, B_MATPRV, "HaloSize: ", 200,70,175,18, &(ma->hasize), 0.0, 100.0, 10, 0, "Set the dimension of the halo"); + uiBlockSetCol(block, BUTGREY); + uiDefButF(block, NUM, B_MATPRV, "HaloSize: ", 200,90,175,18, &(ma->hasize), 0.0, 100.0, 10, 0, "Set the dimension of the halo"); uiDefButF(block, NUMSLI, B_MATPRV, "Alpha ", 200,50,175,18, &(ma->alpha), 0.0, 1.0, 0, 0, "Set the degree of coverage"); - uiDefButS(block, NUMSLI, B_MATPRV, "Hard ", 200,30,175,18, &(ma->har), 1.0, 127.0, 0, 0, "Set the hardness of the halo"); - uiDefButF(block, NUMSLI, B_MATPRV, "Add ", 200,10,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Strength of the add effect"); + uiDefButS(block, NUMSLI, B_MATPRV, "Hard ", 200,30,175,18, &(ma->har), 1.0, 127.0, 0, 0, "Set the hardness of the halo"); + uiDefButF(block, NUMSLI, B_MATPRV, "Add ", 200,10,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Strength of the add effect"); - uiDefButS(block, NUM, B_MATPRV, "Rings: ", 380,90,85,18, &(ma->ringc), 0.0, 24.0, 0, 0, "Set the number of rings rendered over the basic halo"); - uiDefButS(block, NUM, B_MATPRV, "Lines: ", 465,90,90,18, &(ma->linec), 0.0, 250.0, 0, 0, "Set the number of star shaped lines rendered over the halo"); + uiDefButS(block, NUM, B_MATPRV, "Rings: ", 380,90,85,18, &(ma->ringc), 0.0, 24.0, 0, 0, "Set the number of rings rendered over the basic halo"); + uiDefButS(block, NUM, B_MATPRV, "Lines: ", 465,90,90,18, &(ma->linec), 0.0, 250.0, 0, 0, "Set the number of star shaped lines rendered over the halo"); uiDefButS(block, NUM, B_MATPRV, "Star: ", 380,70,85,18, &(ma->starc), 3.0, 50.0, 0, 0, "Set the number of points on the star shaped halo"); uiDefButC(block, NUM, B_MATPRV, "Seed: ", 465,70,90,18, &(ma->seed1), 0.0, 255.0, 0, 0, "Use random values for ring dimension and line location"); - uiDefButF(block, NUM, B_MATPRV, "FlareSize: ", 380,50,85,18, &(ma->flaresize), 0.1, 25.0, 10, 0, "Set the factor the flare is larger than the halo"); + uiDefButF(block, NUM, B_MATPRV, "FlareSize: ", 380,50,85,18, &(ma->flaresize), 0.1, 25.0, 10, 0, "Set the factor the flare is larger than the halo"); uiDefButF(block, NUM, B_MATPRV, "Sub Size: ", 465,50,90,18, &(ma->subsize), 0.1, 25.0, 10, 0, "Set the dimension of the subflares, dots and circles"); - uiDefButF(block, NUM, B_MATPRV, "FlareBoost: ", 380,30,175,18, &(ma->flareboost), 0.1, 10.0, 10, 0, "Give the flare extra strength"); + uiDefButF(block, NUM, B_MATPRV, "FlareBoost: ", 380,30,175,18, &(ma->flareboost), 0.1, 10.0, 10, 0, "Give the flare extra strength"); uiDefButC(block, NUM, B_MATPRV, "Fl.seed: ", 380,10,85,18, &(ma->seed2), 0.0, 255.0, 0, 0, "Specify an offset in the seed table"); - uiDefButS(block, NUM, B_MATPRV, "Flares: ", 465,10,90,18, &(ma->flarec), 1.0, 32.0, 0, 0, "Set the nuber of subflares"); + uiDefButS(block, NUM, B_MATPRV, "Flares: ", 465,10,90,18, &(ma->flarec), 1.0, 32.0, 0, 0, "Set the nuber of subflares"); uiBlockSetCol(block, BUTBLUE); - uiDefButI(block, TOG|BIT|15, B_MATPRV, "Flare", 571, 181, 77, 36, &(ma->mode), 0, 0, 0, 0, "Render halo as a lensflare"); - uiDefButI(block, TOG|BIT|8, B_MATPRV, "Rings", 571, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render rings over basic halo"); - uiDefButI(block, TOG|BIT|9, B_MATPRV, "Lines", 571, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render star shaped lines over the basic halo"); - uiDefButI(block, TOG|BIT|11, B_MATPRV, "Star", 571, 105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render halo as a star"); - uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo", 571, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo"); + uiDefButI(block, TOG|BIT|15, B_MATPRV, "Flare", 576, 181, 77, 36, &(ma->mode), 0, 0, 0, 0, "Render halo as a lensflare"); + uiDefButI(block, TOG|BIT|8, B_MATPRV, "Rings", 576, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render rings over basic halo"); + uiDefButI(block, TOG|BIT|9, B_MATPRV, "Lines", 576, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render star shaped lines over the basic halo"); + uiDefButI(block, TOG|BIT|11, B_MATPRV, "Star", 576, 105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render halo as a star"); + uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo", 576, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo"); - uiDefButI(block, TOG|BIT|12, B_MATPRV, "HaloTex", 571, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Give halo a texture"); - uiDefButI(block, TOG|BIT|13, B_MATPRV, "HaloPuno", 571, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use the vertex normal to specify the dimension of the halo"); - uiDefButI(block, TOG|BIT|10, B_MATPRV, "X Alpha", 571, 28, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use extreme alpha"); - uiDefButI(block, TOG|BIT|14, B_MATPRV, "Shaded", 571, 10, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let halo receive light"); + uiDefButI(block, TOG|BIT|12, B_MATPRV, "HaloTex", 576, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Give halo a texture"); + uiDefButI(block, TOG|BIT|13, B_MATPRV, "HaloPuno", 576, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use the vertex normal to specify the dimension of the halo"); + uiDefButI(block, TOG|BIT|10, B_MATPRV, "X Alpha", 576, 28, 77, 18, &(ma->mode), 0, 0, 0, 0, "Use extreme alpha"); + uiDefButI(block, TOG|BIT|14, B_MATPRV, "Shaded", 576, 10, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let halo receive light"); } else { - uiDefButF(block, NUMSLI, B_MATPRV, "Spec ", 200,70,175,18, &(ma->spec), 0.0, 2.0, 0, 0, "Set the degree of specularity"); - uiDefButS(block, NUMSLI, B_MATPRV, "Hard ", 200,50,175,18, &(ma->har), 1.0, 255.0, 0, 0, "Set the hardness of the specularity"); - uiDefButF(block, NUMSLI, B_MATPRV, "SpTr ", 200,30,175,18, &(ma->spectra), 0.0, 1.0, 0, 0, "Make sheen areas opaque"); - uiDefButF(block, NUMSLI, B_MATPRV, "Add ", 200,10,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Glow factor"); + 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"; + + /* shader buttons */ + uiBlockSetCol(block, BUTGREY); + uiDefButS(block, MENU, B_MATPRV_DRAW, str1, 200,90,95,18, &(ma->diff_shader), 0.0, 0.0, 0, 0, "Set a diffuse shader"); + uiDefButS(block, MENU, B_MATPRV_DRAW, str2, 295,90,90,18, &(ma->spec_shader), 0.0, 0.0, 0, 0, "Set a diffuse shader"); + + if(ma->diff_shader==MA_DIFF_ORENNAYAR) + uiDefButF(block, NUM, B_MATPRV, "Rough:", 200, 70, 95,18, &(ma->roughness), 0.0, 3.14, 0, 0, "Oren Nayar Roughness"); + else if(ma->diff_shader==MA_DIFF_TOON) { + uiDefButF(block, NUM, B_MATPRV, "Size:", 200, 70, 95,18, &(ma->param[0]), 0.0, 1.0, 0, 0, "Size of diffuse toon area"); + uiDefButF(block, NUM, B_MATPRV, "Smooth:", 200, 50, 95,18, &(ma->param[1]), 0.0, 1.0, 0, 0, "Smoothness of diffuse toon area"); + } + + if ELEM3(ma->spec_shader, MA_SPEC_COOKTORR, MA_SPEC_PHONG, MA_SPEC_BLINN) { + uiDefButS(block, NUM, B_MATPRV, "Hard:", 295, 70, 90,18, &(ma->har), 1.0, 255, 0, 0, "Set the hardness of the specularity"); + } + if(ma->spec_shader==MA_SPEC_BLINN) + uiDefButF(block, NUM, B_MATPRV, "Refr:", 295, 50, 90,18, &(ma->refrac), 1.0, 10.0, 0, 0, "Refraction index"); + if(ma->spec_shader==MA_SPEC_TOON) { + uiDefButF(block, NUM, B_MATPRV, "Size:", 295, 70, 90,18, &(ma->param[2]), 0.0, 1.0, 0, 0, "Size of specular toon area"); + uiDefButF(block, NUM, B_MATPRV, "Smooth:", 295, 50, 90,18, &(ma->param[3]), 0.0, 1.0, 0, 0, "Smoothness of specular toon area"); + } + + uiDefButF(block, NUMSLI, B_MATPRV, "Ref ", 200,30,185,18, &(ma->ref), 0.0, 1.0, 0, 0, "Set the amount of reflection"); + uiDefButF(block, NUMSLI, B_MATPRV, "Spec ", 200,10,185,18, &(ma->spec), 0.0, 2.0, 0, 0, "Set the degree of specularity"); - uiDefButF(block, NUMSLI, B_MATPRV, "Ref ", 380,70,175,18, &(ma->ref), 0.0, 1.0, 0, 0, "Set the amount of reflection"); - uiDefButF(block, NUMSLI, B_MATPRV, "Alpha ", 380,50,175,18, &(ma->alpha), 0.0, 1.0, 0, 0, "Set the amount of coverage, to make materials transparent"); - uiDefButF(block, NUMSLI, B_MATPRV, "Emit ", 380,30,175,18, &(ma->emit), 0.0, 1.0, 0, 0, "Set the amount of emitting light"); - uiDefButF(block, NUMSLI, B_MATPRV, "Amb ", 380,10,175,18, &(ma->amb), 0.0, 1.0, 0, 0, "Set the amount of global ambient color"); - /* transparent solids : exponential dropoff */ -/* uiDefButF(block, NUMSLI, B_MATPRV, "K ", 380,-10,175,18, &(ma->kfac), 0.0, 10.0, 0, 0, ""); */ + /* default shading variables */ + uiDefButF(block, NUMSLI, B_MATPRV, "Alpha ", 390,90,175,18, &(ma->alpha), 0.0, 1.0, 0, 0, "Set the amount of coverage, to make materials transparent"); + uiDefButF(block, NUMSLI, B_MATPRV, "SpecTra ", 390,70,175,18, &(ma->spectra), 0.0, 1.0, 0, 0, "Make specular areas opaque"); + uiDefButF(block, NUMSLI, B_MATPRV, "Add ", 390,50,175,18, &(ma->add), 0.0, 1.0, 0, 0, "Glow factor for transparant"); + uiDefButF(block, NUMSLI, B_MATPRV, "Emit ", 390,30,175,18, &(ma->emit), 0.0, 1.0, 0, 0, "Set the amount of emitting light"); + uiDefButF(block, NUMSLI, B_MATPRV, "Amb ", 390,10,175,18, &(ma->amb), 0.0, 1.0, 0, 0, "Set the amount of global ambient color"); uiBlockSetCol(block, BUTBLUE); - uiDefButI(block, TOG|BIT|0, 0, "Traceable", 571,200,77,18, &(ma->mode), 0, 0, 0, 0, "Make material visible for shadow lamps"); - uiDefButI(block, TOG|BIT|1, 0, "Shadow", 571,181,77,18, &(ma->mode), 0, 0, 0, 0, "Enable material for shadows"); - uiDefButI(block, TOG|BIT|2, B_MATPRV, "Shadeless", 571, 162, 77, 18, &(ma->mode), 0, 0, 0, 0, "Make material insensitive to light or shadow"); - uiDefButI(block, TOG|BIT|3, 0, "Wire", 571, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render only the edges of faces"); - uiDefButI(block, TOG|BIT|4, B_REDR, "VCol Light", 571, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Add vertex colours as extra light"); - uiDefButI(block, TOG|BIT|7, B_REDR, "VCol Paint", 571,105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Replace basic colours with vertex colours"); - uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo",571, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo"); - uiDefButI(block, TOG|BIT|6, 0, "ZTransp", 571, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Z-Buffer transparent faces"); - uiDefButI(block, TOG|BIT|8, 0, "ZInvert", 571, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render with inverted Z Buffer"); - uiDefButI(block, TOG|BIT|9, 0, "Env", 571, 29, 77, 18, &(ma->mode), 0, 0, 0, 0, "Do not render material"); - uiDefButI(block, TOG|BIT|10, 0, "OnlyShadow", 571, 10, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let alpha be determined on the degree of shadow"); - /* transparent solids */ -/* uiDefButI(block, TOG|BIT|0, 0, "Transp", 571,-10, 77, 18, &(ma->mode2), 0, 0, 0, 0, ""); */ - - uiDefButI(block, TOG|BIT|14, 0, "No Mist", 477,95,77,18, &(ma->mode), 0, 0, 0, 0, "Set the material insensitive to mist"); - uiDefButI(block, TOG|BIT|11, B_REDR, "TexFace", 398,95,77,18, &(ma->mode), 0, 0, 0, 0, "UV-Editor assigned texture gives color and texture info for the faces"); + uiDefButI(block, TOG|BIT|0, 0, "Traceable", 576,200,77,18, &(ma->mode), 0, 0, 0, 0, "Make material visible for shadow lamps"); + uiDefButI(block, TOG|BIT|1, 0, "Shadow", 576,181,77,18, &(ma->mode), 0, 0, 0, 0, "Enable material for shadows"); + uiDefButI(block, TOG|BIT|2, B_MATPRV, "Shadeless", 576, 162, 77, 18, &(ma->mode), 0, 0, 0, 0, "Make material insensitive to light or shadow"); + uiDefButI(block, TOG|BIT|3, 0, "Wire", 576, 143, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render only the edges of faces"); + uiDefButI(block, TOG|BIT|6, 0, "ZTransp", 576, 124, 77, 18, &(ma->mode), 0, 0, 0, 0, "Z-Buffer transparent faces"); + uiDefButI(block, TOG|BIT|8, 0, "ZInvert", 576, 105, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render with inverted Z Buffer"); + uiDefButI(block, TOG|BIT|5, B_MATPRV_DRAW, "Halo", 576, 86, 77, 18, &(ma->mode), 0, 0, 0, 0, "Render as a halo"); + uiDefButI(block, TOG|BIT|9, 0, "Env", 576, 67, 77, 18, &(ma->mode), 0, 0, 0, 0, "Do not render material"); + uiDefButI(block, TOG|BIT|10, 0, "OnlyShadow", 576, 48, 77, 18, &(ma->mode), 0, 0, 0, 0, "Let alpha be determined on the degree of shadow"); + uiDefButI(block, TOG|BIT|14, 0, "No Mist", 576, 29, 77,18, &(ma->mode), 0, 0, 0, 0, "Set the material insensitive to mist"); + uiBlockSetCol(block, BUTGREY); + uiDefButF(block, NUM, 0, "Zoffs:", 576, 10, 77,18, &(ma->zoffs), 0.0, 10.0, 0, 0, "Give face an artificial offset"); } /* PREVIEW RENDER */ diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index c1953a29b1c..174022bb4c0 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -77,13 +77,11 @@ #include "BIF_screen.h" #include "BIF_space.h" /* allqueue */ #include "BIF_drawimage.h" /* rectwrite_part */ -//#include "BIF_previewrender.h" #include "BIF_mywindow.h" +#include "PIL_time.h" #include "RE_renderconverter.h" -//#include "mydevice.h" - #define PR_RECTX 101 #define PR_RECTY 101 #define PR_XMIN 10 @@ -260,7 +258,8 @@ static void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax) static void display_pr_scanline(unsigned int *rect, int recty) { - /* we display 3 new scanlines, one old */ + static double lasttime= 0; + /* we display 3 new scanlines, one old, the overlap is for wacky 3d cards that cant handle zoom proper */ if(recty % 2) return; if(recty<2) return; @@ -274,6 +273,12 @@ static void display_pr_scanline(unsigned int *rect, int recty) glDrawPixels(PR_RECTX, 3, GL_RGBA, GL_UNSIGNED_BYTE, rect); glPixelZoom(1.0, 1.0); + + /* flush opengl for cards with frontbuffer slowness */ + if(recty==PR_RECTY-1 || (PIL_check_seconds_timer() - lasttime > 0.05)) { + lasttime= PIL_check_seconds_timer(); + glFinish(); + } } static void draw_tex_crop(Tex *tex) @@ -745,22 +750,32 @@ static void shade_preview_pixel(float *vec, if(mat->spec) { - lv[0]+= view[0]; - lv[1]+= view[1]; - lv[2]+= view[2]; - Normalise(lv); - if(inp>0.0) { - v1= lv[0]*R.vn[0]+lv[1]*R.vn[1]+lv[2]*R.vn[2]; - if(v1>0.0) { - v1= RE_Spec(v1, mat->har); - inprspec= v1*mat->spec; - isr+= inprspec*mat->specr; - isg+= inprspec*mat->specg; - isb+= inprspec*mat->specb; - } + /* specular shaders */ + float specfac; + + if(mat->spec_shader==MA_SPEC_PHONG) + specfac= Phong_Spec(R.vn, lv, view, mat->har); + else if(mat->spec_shader==MA_SPEC_COOKTORR) + specfac= CookTorr_Spec(R.vn, lv, view, mat->har); + else if(mat->spec_shader==MA_SPEC_BLINN) + specfac= Blinn_Spec(R.vn, lv, view, mat->refrac, (float)mat->har); + else + specfac= Toon_Spec(R.vn, lv, view, mat->param[2], mat->param[3]); + + inprspec= specfac*mat->spec; + + isr+= inprspec*mat->specr; + isg+= inprspec*mat->specg; + isb+= inprspec*mat->specb; + } } + /* diffuse shaders */ + if(mat->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(R.vn, lv, view, mat->roughness); + else if(mat->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(R.vn, lv, view, mat->param[0], mat->param[1]); + // else Lambert + inp= (mat->ref*inp + mat->emit); if(a==0) la= pr1_col;