- Added "anisotropic" rendering for static particle hair strands.
This means the diffuse and specular shaders don't use the normal for hair (which is actually undefined, a hair is micro cylinder) but it uses the tangent vector (vector in direction of hair). For Diffuse, it computes a fake normal now, representing the optimal hair normal pointing towards the light. All current builtin shaders work with this, including ramps. For Specular, it uses another formula to remap dot products for all lines that now use the tangent vector instead of the normal: dot = vector * tangent dot = sqrt(1.0 - dot*dot) Gives better results than using the 'fake' normal for diffuse. Officially (according the papers) this could be used for diffuse too, but then hair becomes very flat. Now you can control the flatness easily with ramps or using Oren-Nayer for example. Example image (disappears in some weeks) http://www.blender.org/bf/rt9.jpg - Added new texture channel "Strand" to apply textures on hairs over the length of hair (1 dimensional). Orco now gives 1 fixed coordinate for the entire hair, based on where it starts. Note; UV doesn't work yet. Nor vertexcolor. http://www.blender.org/bf/rt10.jpg
This commit is contained in:
@@ -76,14 +76,16 @@ extern struct ListBase editNurb;
|
||||
#include "DNA_world_types.h" /* for render_types */
|
||||
#include "render_types.h"
|
||||
extern struct RE_Render R;
|
||||
float Blinn_Spec(float *n, float *l, float *v, float a, float b);
|
||||
float Phong_Spec(float *, float *, float *, int);
|
||||
float CookTorr_Spec(float *n, float *l, float *v, int hard);
|
||||
float Toon_Spec(float *n, float *l, float *v, float a, float b);
|
||||
float WardIso_Spec(float *n, float *l, float *v, float a);
|
||||
float Blinn_Spec(float *n, float *l, float *v, float a, float b, int);
|
||||
float Phong_Spec(float *, float *, float *, int, int);
|
||||
float CookTorr_Spec(float *n, float *l, float *v, int hard, int);
|
||||
float Toon_Spec(float *n, float *l, float *v, float a, float b, int);
|
||||
float WardIso_Spec(float *n, float *l, float *v, float a, int);
|
||||
|
||||
float Toon_Diff(float *n, float *l, float *v, float a, float b);
|
||||
float OrenNayar_Diff(float *n, float *l, float *v, float rough);
|
||||
float Minnaert_Diff(float nl, float *n, float *v, float a);
|
||||
|
||||
void add_to_diffuse(float *, ShadeInput *, float, float, float, float);
|
||||
void ramp_diffuse_result(float *diff, ShadeInput *shi);
|
||||
void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec);
|
||||
|
||||
@@ -107,14 +107,16 @@ ListBase editNurb;
|
||||
#include "render_types.h"
|
||||
struct RE_Render R;
|
||||
|
||||
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 Phong_Spec(float *n, float *l, float *v, int hard, int tangent){return 0;}
|
||||
float Blinn_Spec(float *n, float *l, float *v, float a, float b, int tangent){return 0;}
|
||||
float CookTorr_Spec(float *n, float *l, float *v, int hard, int tangent){return 0;}
|
||||
float Toon_Spec(float *n, float *l, float *v, float a, float b, int tangent){return 0;}
|
||||
float WardIso_Spec(float *n, float *l, float *v, float a, int tangent){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 rough){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){}
|
||||
|
||||
@@ -561,15 +561,15 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
|
||||
float specfac;
|
||||
|
||||
if(ma->spec_shader==MA_SPEC_PHONG)
|
||||
specfac= Phong_Spec(nor, lv, shi.view, shi.har);
|
||||
specfac= Phong_Spec(nor, lv, shi.view, shi.har, 0);
|
||||
else if(ma->spec_shader==MA_SPEC_COOKTORR)
|
||||
specfac= CookTorr_Spec(nor, lv, shi.view, shi.har);
|
||||
specfac= CookTorr_Spec(nor, lv, shi.view, shi.har, 0);
|
||||
else if(ma->spec_shader==MA_SPEC_BLINN)
|
||||
specfac= Blinn_Spec(nor, lv, shi.view, ma->refrac, (float)shi.har);
|
||||
specfac= Blinn_Spec(nor, lv, shi.view, ma->refrac, (float)shi.har, 0);
|
||||
else if(ma->spec_shader==MA_SPEC_WARDISO)
|
||||
specfac= WardIso_Spec(nor, lv, shi.view, ma->rms);
|
||||
specfac= WardIso_Spec(nor, lv, shi.view, ma->rms, 0);
|
||||
else
|
||||
specfac= Toon_Spec(nor, lv, shi.view, ma->param[2], ma->param[3]);
|
||||
specfac= Toon_Spec(nor, lv, shi.view, ma->param[2], ma->param[3], 0);
|
||||
|
||||
if(specfac>0) {
|
||||
t= specfac*shi.spec*lampdist;
|
||||
|
||||
@@ -553,7 +553,9 @@ void init_render_material(Material *ma)
|
||||
if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
|
||||
}
|
||||
|
||||
if(ma->texco & (511)) needuv= 1;
|
||||
if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND)) needuv= 1;
|
||||
else if(ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT)) needuv= 1;
|
||||
else if(ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1;
|
||||
|
||||
if(mtex->object) mtex->object->flag |= OB_DO_IMAT;
|
||||
|
||||
|
||||
@@ -200,8 +200,10 @@ typedef struct Material {
|
||||
#define TEXCO_OSA 512
|
||||
#define TEXCO_WINDOW 1024
|
||||
#define NEED_UV 2048
|
||||
/* optim = use simpler AA */
|
||||
/* optim = use simpler AA */
|
||||
#define TEXCO_OPTIM 4096
|
||||
/* stored in vertex->accum, 1 D */
|
||||
#define TEXCO_STRAND 8192
|
||||
|
||||
/* mapto */
|
||||
#define MAP_COL 1
|
||||
|
||||
@@ -412,7 +412,10 @@ typedef struct Scene {
|
||||
#define R_NOPUNOFLIP 8
|
||||
#define R_FULL_OSA 16
|
||||
#define R_FACE_SPLIT 32
|
||||
#define R_DIVIDE_24 64 /* Tells render to divide face other way. */
|
||||
/* Tells render to divide face other way. */
|
||||
#define R_DIVIDE_24 64
|
||||
/* vertex normals are tangent vector, for hair shader */
|
||||
#define R_TANGENT 128
|
||||
|
||||
/* vertren->texofs (texcoordinate offset relative to vertren->orco */
|
||||
#define R_UVOFS3 1
|
||||
|
||||
12
source/blender/render/extern/include/render.h
vendored
12
source/blender/render/extern/include/render.h
vendored
@@ -173,14 +173,16 @@ struct EnvMap *RE_copy_envmap(struct EnvMap *env);
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* 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 Phong_Spec(float *n, float *l, float *v, int hard, int tangent);
|
||||
float CookTorr_Spec(float *n, float *l, float *v, int hard, int tangent);
|
||||
float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power, int tangent);
|
||||
float Toon_Spec( float *n, float *l, float *v, float size, float smooth, int tangent);
|
||||
float WardIso_Spec(float *n, float *l, float *v, float rms, int tangent);
|
||||
|
||||
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);
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef struct ShadeInput
|
||||
|
||||
/* texture coordinates */
|
||||
float lo[3], gl[3], uv[3], ref[3], orn[3], winco[3], sticky[3], vcol[3], rad[3];
|
||||
float vn[3], facenor[3], view[3], refcol[4], displace[3];
|
||||
float vn[3], facenor[3], view[3], refcol[4], displace[3], strand;
|
||||
/* dx/dy OSA coordinates */
|
||||
float dxco[3], dyco[3];
|
||||
float dxlo[3], dylo[3], dxgl[3], dygl[3], dxuv[3], dyuv[3];
|
||||
@@ -92,6 +92,7 @@ typedef struct ShadeInput
|
||||
float dxwin[3], dywin[3];
|
||||
float dxsticky[3], dysticky[3];
|
||||
float dxrefract[3], dyrefract[3];
|
||||
float dxstrand, dystrand;
|
||||
|
||||
float xs, ys; /* pixel to be rendered */
|
||||
short osatex, puno;
|
||||
@@ -193,7 +194,7 @@ typedef struct VertRen
|
||||
float *sticky;
|
||||
void *svert; /* smooth vert, only used during initrender */
|
||||
short clip, texofs; /* texofs= flag */
|
||||
float accum; /* accum for radio weighting */
|
||||
float accum; /* accum for radio weighting, and for strand texco static particles */
|
||||
short flag;
|
||||
} VertRen;
|
||||
|
||||
|
||||
@@ -289,11 +289,12 @@ void set_normalflags(void)
|
||||
|
||||
/* recalculate puno. Displace & flipped matrices can screw up */
|
||||
vlr->puno= 0;
|
||||
if( Inpf(vlr->n, vlr->v1->n) < 0.0 ) vlr->puno |= ME_FLIPV1;
|
||||
if( Inpf(vlr->n, vlr->v2->n) < 0.0 ) vlr->puno |= ME_FLIPV2;
|
||||
if( Inpf(vlr->n, vlr->v3->n) < 0.0 ) vlr->puno |= ME_FLIPV3;
|
||||
if(vlr->v4 && Inpf(vlr->n, vlr->v4->n) < 0.0 ) vlr->puno |= ME_FLIPV4;
|
||||
|
||||
if(!(vlr->flag & R_TANGENT)) {
|
||||
if( Inpf(vlr->n, vlr->v1->n) < 0.0 ) vlr->puno |= ME_FLIPV1;
|
||||
if( Inpf(vlr->n, vlr->v2->n) < 0.0 ) vlr->puno |= ME_FLIPV2;
|
||||
if( Inpf(vlr->n, vlr->v3->n) < 0.0 ) vlr->puno |= ME_FLIPV3;
|
||||
if(vlr->v4 && Inpf(vlr->n, vlr->v4->n) < 0.0 ) vlr->puno |= ME_FLIPV4;
|
||||
}
|
||||
xn= fabs(vlr->n[0]);
|
||||
yn= fabs(vlr->n[1]);
|
||||
zn= fabs(vlr->n[2]);
|
||||
|
||||
@@ -658,15 +658,10 @@ static float area_lamp_energy(float *co, float *vn, LampRen *lar)
|
||||
rad[3]= saacos_d(rad[3]);
|
||||
|
||||
/* Stoke formula */
|
||||
VECMUL(cross[0], rad[0]);
|
||||
VECMUL(cross[1], rad[1]);
|
||||
VECMUL(cross[2], rad[2]);
|
||||
VECMUL(cross[3], rad[3]);
|
||||
|
||||
fac= vn[0]*cross[0][0]+ vn[1]*cross[0][1]+ vn[2]*cross[0][2];
|
||||
fac+= vn[0]*cross[1][0]+ vn[1]*cross[1][1]+ vn[2]*cross[1][2];
|
||||
fac+= vn[0]*cross[2][0]+ vn[1]*cross[2][1]+ vn[2]*cross[2][2];
|
||||
fac+= vn[0]*cross[3][0]+ vn[1]*cross[3][1]+ vn[2]*cross[3][2];
|
||||
fac= rad[0]*(vn[0]*cross[0][0]+ vn[1]*cross[0][1]+ vn[2]*cross[0][2]);
|
||||
fac+= rad[1]*(vn[0]*cross[1][0]+ vn[1]*cross[1][1]+ vn[2]*cross[1][2]);
|
||||
fac+= rad[2]*(vn[0]*cross[2][0]+ vn[1]*cross[2][1]+ vn[2]*cross[2][2]);
|
||||
fac+= rad[3]*(vn[0]*cross[3][0]+ vn[1]*cross[3][1]+ vn[2]*cross[3][2]);
|
||||
|
||||
if(fac<=0.0) return 0.0;
|
||||
return pow(fac*lar->areasize, lar->k); // corrected for buttons size and lar->dist^2
|
||||
@@ -713,27 +708,28 @@ float spec(float inp, int hard)
|
||||
return inp;
|
||||
}
|
||||
|
||||
float Phong_Spec( float *n, float *l, float *v, int hard )
|
||||
float Phong_Spec( float *n, float *l, float *v, int hard, int tangent )
|
||||
{
|
||||
float h[3];
|
||||
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];
|
||||
|
||||
if(tangent) rslt= sqrt(1.0 - rslt*rslt);
|
||||
|
||||
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 CookTorr_Spec(float *n, float *l, float *v, int hard, int tangent)
|
||||
{
|
||||
float i, nh, nv, h[3];
|
||||
|
||||
@@ -743,9 +739,12 @@ float CookTorr_Spec(float *n, float *l, float *v, int hard)
|
||||
Normalise(h);
|
||||
|
||||
nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2];
|
||||
if(nh<0.0) return 0.0;
|
||||
if(tangent) nh= sqrt(1.0 - nh*nh);
|
||||
else 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;
|
||||
if(tangent) nv= sqrt(1.0 - nv*nv);
|
||||
else if(nv<0.0) nv= 0.0;
|
||||
|
||||
i= spec(nh, hard);
|
||||
|
||||
@@ -754,7 +753,7 @@ float CookTorr_Spec(float *n, float *l, float *v, int hard)
|
||||
}
|
||||
|
||||
/* Blinn spec */
|
||||
float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power )
|
||||
float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power, int tangent)
|
||||
{
|
||||
float i, nh, nv, nl, vh, h[3];
|
||||
float a, b, c, g=0.0, p, f, ang;
|
||||
@@ -773,17 +772,16 @@ float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power )
|
||||
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;
|
||||
if(tangent) nh= sqrt(1.0f - nh*nh);
|
||||
else 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;
|
||||
if(tangent) nv= sqrt(1.0f - nv*nv);
|
||||
if(nv<=0.0) nv= 0.01; /* hrms... */
|
||||
|
||||
nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
|
||||
|
||||
if(tangent) nl= sqrt(1.0f - nl*nl);
|
||||
if(nl<=0.0) {
|
||||
nl= 0.0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -809,7 +807,7 @@ float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power )
|
||||
}
|
||||
|
||||
/* cartoon render spec */
|
||||
float Toon_Spec( float *n, float *l, float *v, float size, float smooth )
|
||||
float Toon_Spec( float *n, float *l, float *v, float size, float smooth, int tangent)
|
||||
{
|
||||
float h[3];
|
||||
float ang;
|
||||
@@ -821,6 +819,7 @@ float Toon_Spec( float *n, float *l, float *v, float size, float smooth )
|
||||
Normalise(h);
|
||||
|
||||
rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2];
|
||||
if(tangent) rslt = sqrt(1.0f - rslt*rslt);
|
||||
|
||||
ang = saacos( rslt );
|
||||
|
||||
@@ -832,7 +831,7 @@ float Toon_Spec( float *n, float *l, float *v, float size, float smooth )
|
||||
}
|
||||
|
||||
/* Ward isotropic gaussian spec */
|
||||
float WardIso_Spec( float *n, float *l, float *v, float rms)
|
||||
float WardIso_Spec( float *n, float *l, float *v, float rms, int tangent)
|
||||
{
|
||||
float i, nh, nv, nl, h[3], angle, alpha;
|
||||
|
||||
@@ -844,12 +843,15 @@ float WardIso_Spec( float *n, float *l, float *v, float rms)
|
||||
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;
|
||||
if(tangent) nh = sqrt(1.0f - nh*nh);
|
||||
if(nh<=0.0) nh = 0.001f;
|
||||
|
||||
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;
|
||||
if(tangent) nv = sqrt(1.0f - nv*nv);
|
||||
if(nv<=0.0) nv = 0.001f;
|
||||
|
||||
nl = n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
|
||||
if(tangent) nl = sqrt(1.0f - nl*nl);
|
||||
if(nl<=0.0) nl = 0.001;
|
||||
|
||||
angle = tan(saacos(nh));
|
||||
@@ -950,11 +952,11 @@ float OrenNayar_Diff(float *n, float *l, float *v, float rough )
|
||||
float Minnaert_Diff(float nl, float *n, float *v, float darkness)
|
||||
{
|
||||
|
||||
float i, nv;
|
||||
float i, nv;
|
||||
|
||||
/* nl = dot product between surface normal and light vector */
|
||||
if (nl <= 0.0)
|
||||
return 0;
|
||||
/* 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];
|
||||
@@ -1292,7 +1294,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
|
||||
LampRen *lar;
|
||||
Material *ma= shi->mat;
|
||||
VlakRen *vlr= shi->vlr;
|
||||
float i, inp, inpr, is, t, lv[3], lacol[3], lampdist, ld = 0;
|
||||
float i, inp, inpr, is, t, lv[3], vnor[3], lacol[3], lampdist, ld = 0;
|
||||
float lvrot[3], *vn, *view, shadfac[4], soft, phongcorr; // shadfac = rgba
|
||||
int a;
|
||||
|
||||
@@ -1549,8 +1551,17 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
|
||||
/* dot product and reflectivity */
|
||||
/* inp = dotproduct, is = shader result, i = lamp energy (with shadow) */
|
||||
|
||||
/* tangent case; calculate fake face normal, aligned with lampvector */
|
||||
if(vlr->flag & R_TANGENT) {
|
||||
float cross[3];
|
||||
Crossf(cross, lv, vn);
|
||||
Crossf(vnor, cross, shi->vn);
|
||||
vnor[0]= -vnor[0];vnor[1]= -vnor[1];vnor[2]= -vnor[2];
|
||||
vn= vnor;
|
||||
}
|
||||
|
||||
inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2];
|
||||
|
||||
|
||||
/* phong threshold to prevent backfacing faces having artefacts on ray shadow (terminator problem) */
|
||||
if((ma->mode & MA_RAYBIAS) && (lar->mode & LA_SHAD_RAY) && (vlr->flag & R_SMOOTH)) {
|
||||
float thresh= vlr->ob->smoothresh;
|
||||
@@ -1572,8 +1583,9 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
|
||||
|
||||
if(lar->type==LA_AREA) {
|
||||
/* single sided */
|
||||
if(lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0)
|
||||
inp= area_lamp_energy(shi->co, shi->vn, lar);
|
||||
if(lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0) {
|
||||
inp= area_lamp_energy(shi->co, vn, lar);
|
||||
}
|
||||
else inp= 0.0;
|
||||
}
|
||||
|
||||
@@ -1589,7 +1601,9 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
|
||||
if(i>0.0) {
|
||||
i*= lampdist*shi->refl;
|
||||
}
|
||||
|
||||
|
||||
vn= shi->vn; // bring back original vector, we use special specular shaders for tangent
|
||||
|
||||
/* shadow and spec, (lampdist==0 outside spot) */
|
||||
if(lampdist> 0.0) {
|
||||
|
||||
@@ -1650,15 +1664,15 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
|
||||
float specfac;
|
||||
|
||||
if(ma->spec_shader==MA_SPEC_PHONG)
|
||||
specfac= Phong_Spec(vn, lv, view, shi->har);
|
||||
specfac= Phong_Spec(vn, lv, view, shi->har, vlr->flag & R_TANGENT);
|
||||
else if(ma->spec_shader==MA_SPEC_COOKTORR)
|
||||
specfac= CookTorr_Spec(vn, lv, view, shi->har);
|
||||
specfac= CookTorr_Spec(vn, lv, view, shi->har, vlr->flag & R_TANGENT);
|
||||
else if(ma->spec_shader==MA_SPEC_BLINN)
|
||||
specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har);
|
||||
specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har, vlr->flag & R_TANGENT);
|
||||
else if(ma->spec_shader==MA_SPEC_WARDISO)
|
||||
specfac= WardIso_Spec( vn, lv, view, ma->rms);
|
||||
specfac= WardIso_Spec( vn, lv, view, ma->rms, vlr->flag & R_TANGENT);
|
||||
else
|
||||
specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]);
|
||||
specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3], vlr->flag & R_TANGENT);
|
||||
|
||||
/* area lamp correction */
|
||||
if(lar->type==LA_AREA) specfac*= inp;
|
||||
@@ -1916,6 +1930,15 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
|
||||
MTC_Mat3MulVecfl(R.imat, shi->dyco);
|
||||
}
|
||||
}
|
||||
if(texco & TEXCO_STRAND) {
|
||||
shi->strand= (l*v3->accum - u*v1->accum - v*v2->accum);
|
||||
if(shi->osatex) {
|
||||
dl= shi->dxuv[0]+shi->dxuv[1];
|
||||
shi->dxstrand= dl*v3->accum-shi->dxuv[0]*v1->accum-shi->dxuv[1]*v2->accum;
|
||||
dl= shi->dyuv[0]+shi->dyuv[1];
|
||||
shi->dystrand= dl*v3->accum-shi->dyuv[0]*v1->accum-shi->dyuv[1]*v2->accum;
|
||||
}
|
||||
}
|
||||
if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) {
|
||||
int j1=i1, j2=i2, j3=i3;
|
||||
|
||||
@@ -2013,7 +2036,6 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
|
||||
shi->orn[1]= -shi->vn[1];
|
||||
shi->orn[2]= -shi->vn[2];
|
||||
}
|
||||
|
||||
if(mode & MA_RADIO) {
|
||||
shi->rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]);
|
||||
shi->rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]);
|
||||
@@ -2022,7 +2044,6 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
|
||||
else {
|
||||
shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0;
|
||||
}
|
||||
|
||||
if(texco & TEXCO_REFL) {
|
||||
/* mirror reflection colour textures (and envmap) */
|
||||
calc_R_ref(shi);
|
||||
|
||||
@@ -1471,6 +1471,15 @@ void do_material_tex(ShadeInput *shi)
|
||||
else if(mtex->texco==TEXCO_WINDOW) {
|
||||
co= shi->winco; dx= shi->dxwin; dy= shi->dywin;
|
||||
}
|
||||
else if(mtex->texco==TEXCO_STRAND) {
|
||||
co= tempvec; dx= dxt; dy= dyt;
|
||||
co[0]= shi->strand;
|
||||
co[1]= co[2]= 0.0f;
|
||||
dx[0]= shi->dxstrand;
|
||||
dx[1]= dx[2]= 0.0f;
|
||||
dy[0]= shi->dystrand;
|
||||
dy[1]= dy[2]= 0.0f;
|
||||
}
|
||||
else continue; // can happen when texco defines disappear and it renders old files
|
||||
|
||||
/* de pointer defines if bumping happens */
|
||||
|
||||
@@ -120,33 +120,8 @@ extern void error (char *fmt, ...); /* defined in BIF_toolbox.h, but we dont ne
|
||||
/* Local functions */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static Material *give_render_material(Object *ob, int nr);
|
||||
|
||||
|
||||
|
||||
/* blenderWorldManipulation.c */
|
||||
static int contrpuntnormr(float *n, float *puno);
|
||||
static void as_addvert(VertRen *v1, VlakRen *vlr);
|
||||
static void as_freevert(VertRen *ver);
|
||||
static void autosmooth(int startvert, int startvlak, int degr);
|
||||
static void render_particle_system(Object *ob, PartEff *paf);
|
||||
static void render_static_particle_system(Object *ob, PartEff *paf);
|
||||
static int verghalo(const void *a1, const void *a2);
|
||||
static void sort_halos(void);
|
||||
static void init_render_mball(Object *ob);
|
||||
static void init_render_mesh(Object *ob);
|
||||
static void init_render_surf(Object *ob);
|
||||
static void init_render_curve(Object *ob);
|
||||
static void init_render_object(Object *ob);
|
||||
static HaloRen *initstar(float *vec, float hasize);
|
||||
|
||||
/* Displacement Texture */
|
||||
static void displace_render_face(VlakRen *vlr, float *scale);
|
||||
static void do_displacement(Object *ob, int startface, int numface, int startvert, int numvert);
|
||||
static short test_for_displace(Object *ob);
|
||||
static void displace_render_vert(ShadeInput *shi, VertRen *vr, float *scale);
|
||||
|
||||
/* more prototypes for autosmoothing below */
|
||||
|
||||
static void do_displacement(Object *ob, int startface, int numface, int startvert, int numvert );
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* tool functions/defines for ad hoc simplification and possible future
|
||||
@@ -173,6 +148,25 @@ u | | F1 | F2 |
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* this is a bad beast, since it is misused by the 3d view drawing as well. */
|
||||
|
||||
/* more star stuff, here used to be a cliptest, removed for envmap render or panorama... */
|
||||
static HaloRen *initstar(float *vec, float hasize)
|
||||
{
|
||||
HaloRen *har;
|
||||
float hoco[4];
|
||||
|
||||
RE_projectverto(vec, hoco);
|
||||
|
||||
har= RE_findOrAddHalo(R.tothalo++);
|
||||
|
||||
/* projectvert is done in function zbufvlaggen again, because of parts */
|
||||
VECCOPY(har->co, vec);
|
||||
har->hasize= hasize;
|
||||
|
||||
har->zd= 0.0;
|
||||
|
||||
return har;
|
||||
}
|
||||
|
||||
extern unsigned char hash[512];
|
||||
|
||||
/* there must be a 'fixed' amount of stars generated between
|
||||
@@ -316,27 +310,6 @@ void RE_make_stars(void (*initfunc)(void),
|
||||
if (termfunc) termfunc();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* more star stuff, here used to be a cliptest, removed for envmap render or panorama... */
|
||||
static HaloRen *initstar(float *vec, float hasize)
|
||||
{
|
||||
HaloRen *har;
|
||||
float hoco[4];
|
||||
|
||||
RE_projectverto(vec, hoco);
|
||||
|
||||
har= RE_findOrAddHalo(R.tothalo++);
|
||||
|
||||
/* projectvert is done in function zbufvlaggen again, because of parts */
|
||||
VECCOPY(har->co, vec);
|
||||
har->hasize= hasize;
|
||||
|
||||
har->zd= 0.0;
|
||||
|
||||
return har;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static void split_v_renderfaces(int startvlak, int startvert, int usize, int vsize, int uIndex, int cyclu, int cyclv)
|
||||
@@ -740,6 +713,48 @@ static void autosmooth(int startvert, int startvlak, int degr)
|
||||
/* End of autosmoothing: */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Orco hash */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static GHash *g_orco_hash = NULL;
|
||||
|
||||
static float *get_object_orco(Object *ob)
|
||||
{
|
||||
float *orco;
|
||||
|
||||
if (!g_orco_hash)
|
||||
g_orco_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
||||
|
||||
orco = BLI_ghash_lookup(g_orco_hash, ob);
|
||||
|
||||
if (!orco) {
|
||||
if (ob->type==OB_MESH) {
|
||||
orco = mesh_create_orco_render(ob);
|
||||
} else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
|
||||
orco = make_orco_curve(ob);
|
||||
} else if (ob->type==OB_SURF) {
|
||||
orco = make_orco_surf(ob);
|
||||
}
|
||||
|
||||
if (orco)
|
||||
BLI_ghash_insert(g_orco_hash, ob, orco);
|
||||
}
|
||||
|
||||
return orco;
|
||||
}
|
||||
static void free_mesh_orco_hash(void)
|
||||
{
|
||||
if (g_orco_hash) {
|
||||
BLI_ghash_free(g_orco_hash, NULL, (GHashValFreeFP)MEM_freeN);
|
||||
g_orco_hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ******************** END ORCO HASH ***************** */
|
||||
|
||||
|
||||
static void make_render_halos(Object *ob, Mesh *me, int totvert, MVert *mvert, Material *ma, float *orco)
|
||||
{
|
||||
HaloRen *har;
|
||||
@@ -905,16 +920,8 @@ static Object *vlr_set_ob(Object *ob)
|
||||
return ob;
|
||||
}
|
||||
|
||||
static float strand_orcos[256][3];
|
||||
static void particle_orcos(void)
|
||||
{
|
||||
int a;
|
||||
|
||||
for(a=0; a<256; a++) {
|
||||
strand_orcos[a][0]= ((float)a)/255.0f;
|
||||
strand_orcos[a][1]=strand_orcos[a][2]= 0.0f;
|
||||
}
|
||||
}
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
{
|
||||
@@ -926,7 +933,7 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
float xn, yn, zn, imat[3][3], mat[4][4], hasize;
|
||||
float mtime, ptime, ctime, vec[3], vec1[3], view[3], nor[3];
|
||||
float *orco= NULL;
|
||||
int a, mat_nr=1, seed, totvlako, totverto;
|
||||
int a, mat_nr=1, seed;
|
||||
|
||||
pa= paf->keys;
|
||||
if(pa==NULL || (paf->flag & PAF_ANIMATED)) {
|
||||
@@ -943,13 +950,13 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
MTC_Mat4Invert(ob->imat, mat); /* need to be that way, for imat texture */
|
||||
|
||||
MTC_Mat3CpyMat4(imat, ob->imat);
|
||||
|
||||
totvlako= R.totvlak;
|
||||
totverto= R.totvert;
|
||||
|
||||
/* orcos */
|
||||
if(!(ma->mode & (MA_HALO|MA_WIRE))) {
|
||||
particle_orcos();
|
||||
orco= MEM_mallocN(3*sizeof(float)*paf->totpart, "static particle orcos");
|
||||
if (!g_orco_hash)
|
||||
g_orco_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
||||
BLI_ghash_insert(g_orco_hash, ob, orco);
|
||||
}
|
||||
|
||||
if(ob->ipoflag & OB_OFFS_PARTICLE) ptime= ob->sf;
|
||||
@@ -958,8 +965,9 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
seed= ma->seed1;
|
||||
|
||||
for(a=0; a<paf->totpart; a++, pa+=paf->totkey) {
|
||||
|
||||
|
||||
where_is_particle(paf, pa, pa->time, vec1);
|
||||
if(orco) VECCOPY(orco, vec1);
|
||||
MTC_Mat4MulVecfl(mat, vec1);
|
||||
|
||||
mtime= pa->time+pa->lifetime+paf->staticstep-1;
|
||||
@@ -1055,6 +1063,7 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
float cross[3], w, dx, dy;
|
||||
|
||||
VecSubf(nor, vec, vec1);
|
||||
Normalise(nor); // nor needed as tangent
|
||||
Crossf(cross, vec, nor);
|
||||
|
||||
/* turn cross in pixelsize */
|
||||
@@ -1072,16 +1081,20 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
|
||||
VECCOPY(v1->co, vec);
|
||||
VecAddf(v1->co, v1->co, cross);
|
||||
v1->orco= strand_orcos[ (int)( 255.0*(ctime-pa->time)/(mtime-pa->time) )];
|
||||
|
||||
VECCOPY(v1->n, nor);
|
||||
v2->orco= orco;
|
||||
v1->accum= (ctime-pa->time)/(mtime-pa->time); // accum abuse for strand texco
|
||||
|
||||
VECCOPY(v2->co, vec);
|
||||
VecSubf(v2->co, v2->co, cross);
|
||||
v2->orco= v1->orco;
|
||||
VECCOPY(v2->n, nor);
|
||||
v2->orco= orco;
|
||||
v2->accum= v1->accum;
|
||||
}
|
||||
else {
|
||||
|
||||
vlr= RE_findOrAddVlak(R.totvlak++);
|
||||
vlr->flag= ME_SMOOTH;
|
||||
vlr->flag= ME_SMOOTH|R_NOPUNOFLIP|R_TANGENT;
|
||||
vlr->ob= vlr_set_ob(ob);
|
||||
vlr->v1= v1;
|
||||
vlr->v2= v2;
|
||||
@@ -1093,11 +1106,15 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
|
||||
VECCOPY(vlr->v4->co, vec);
|
||||
VecAddf(vlr->v4->co, vlr->v4->co, cross);
|
||||
vlr->v4->orco= strand_orcos[ (int)( 255.0*(ctime-pa->time)/(mtime-pa->time) )];
|
||||
VECCOPY(vlr->v4->n, nor);
|
||||
vlr->v4->orco= orco;
|
||||
vlr->v4->accum= (ctime-pa->time)/(mtime-pa->time); // accum abuse for strand texco
|
||||
|
||||
VECCOPY(vlr->v3->co, vec);
|
||||
VecSubf(vlr->v3->co, vlr->v3->co, cross);
|
||||
vlr->v3->orco= vlr->v4->orco;
|
||||
VECCOPY(vlr->v3->n, nor);
|
||||
vlr->v3->orco= orco;
|
||||
vlr->v3->accum= vlr->v4->accum;
|
||||
|
||||
CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
|
||||
|
||||
@@ -1110,11 +1127,10 @@ static void render_static_particle_system(Object *ob, PartEff *paf)
|
||||
|
||||
VECCOPY(vec1, vec);
|
||||
}
|
||||
|
||||
seed++;
|
||||
if(orco) orco+=3;
|
||||
}
|
||||
|
||||
calc_vertexnormals(totverto, totvlako);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1299,39 +1315,6 @@ static void init_render_mball(Object *ob)
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* convert */
|
||||
|
||||
static GHash *g_orco_hash = NULL;
|
||||
|
||||
static float *get_object_orco(Object *ob)
|
||||
{
|
||||
float *orco;
|
||||
|
||||
if (!g_orco_hash)
|
||||
g_orco_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
||||
|
||||
orco = BLI_ghash_lookup(g_orco_hash, ob);
|
||||
|
||||
if (!orco) {
|
||||
if (ob->type==OB_MESH) {
|
||||
orco = mesh_create_orco_render(ob);
|
||||
} else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
|
||||
orco = make_orco_curve(ob);
|
||||
} else if (ob->type==OB_SURF) {
|
||||
orco = make_orco_surf(ob);
|
||||
}
|
||||
|
||||
if (orco)
|
||||
BLI_ghash_insert(g_orco_hash, ob, orco);
|
||||
}
|
||||
|
||||
return orco;
|
||||
}
|
||||
static void free_mesh_orco_hash(void)
|
||||
{
|
||||
if (g_orco_hash) {
|
||||
BLI_ghash_free(g_orco_hash, NULL, (GHashValFreeFP)MEM_freeN);
|
||||
g_orco_hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void init_render_mesh(Object *ob)
|
||||
{
|
||||
@@ -2832,107 +2815,6 @@ static short test_for_displace(Object *ob)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void do_displacement(Object *ob, int startface, int numface, int startvert, int numvert )
|
||||
{
|
||||
VertRen *vr;
|
||||
VlakRen *vlr;
|
||||
// float min[3]={1e30, 1e30, 1e30}, max[3]={-1e30, -1e30, -1e30};
|
||||
float scale[3]={1.0f, 1.0f, 1.0f}, temp[3];//, xn
|
||||
int i; //, texflag=0;
|
||||
Object *obt;
|
||||
|
||||
/* Object Size with parenting */
|
||||
obt=ob;
|
||||
while(obt){
|
||||
VecAddf(temp, obt->size, obt->dsize);
|
||||
scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2];
|
||||
obt=obt->parent;
|
||||
}
|
||||
|
||||
/* Clear all flags */
|
||||
for(i=startvert; i<startvert+numvert; i++){
|
||||
vr= RE_findOrAddVert(i);
|
||||
vr->flag= 0;
|
||||
}
|
||||
|
||||
for(i=startface; i<startface+numface; i++){
|
||||
vlr=RE_findOrAddVlak(i);
|
||||
displace_render_face(vlr, scale);
|
||||
}
|
||||
|
||||
/* Recalc vertex normals */
|
||||
calc_vertexnormals(startvert, startface);
|
||||
}
|
||||
|
||||
static void displace_render_face(VlakRen *vlr, float *scale)
|
||||
{
|
||||
ShadeInput shi;
|
||||
// VertRen vr;
|
||||
// float samp1,samp2, samp3, samp4, xn;
|
||||
short hasuv=0;
|
||||
/* set up shadeinput struct for multitex() */
|
||||
|
||||
shi.osatex= 0; /* signal not to use dx[] and dy[] texture AA vectors */
|
||||
shi.vlr= vlr; /* current render face */
|
||||
shi.mat= vlr->mat; /* current input material */
|
||||
|
||||
|
||||
/* UV coords must come from face */
|
||||
hasuv = vlr->tface && (shi.mat->texco & TEXCO_UV);
|
||||
if (hasuv) shi.uv[2]=0.0f;
|
||||
/* I don't think this is used, but seting it just in case */
|
||||
|
||||
/* Displace the verts, flag is set when done */
|
||||
if (! (vlr->v1->flag)){
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[0][0]-1.0f; /* shi.uv and tface->uv are */
|
||||
shi.uv[1]= 2*vlr->tface->uv[0][1]-1.0f; /* scalled differently */
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v1, scale);
|
||||
}
|
||||
|
||||
if (! (vlr->v2->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[1][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[1][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v2, scale);
|
||||
}
|
||||
|
||||
if (! (vlr->v3->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[2][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[2][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v3, scale);
|
||||
}
|
||||
|
||||
if (vlr->v4) {
|
||||
if (! (vlr->v4->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[3][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[3][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v4, scale);
|
||||
}
|
||||
/* We want to split the quad along the opposite verts that are */
|
||||
/* closest in displace value. This will help smooth edges. */
|
||||
if ( fabs(vlr->v1->accum - vlr->v3->accum) > fabs(vlr->v2->accum - vlr->v4->accum))
|
||||
vlr->flag |= R_DIVIDE_24;
|
||||
else vlr->flag &= ~R_DIVIDE_24; // E: typo?, was missing '='
|
||||
}
|
||||
|
||||
/* Recalculate the face normal - if flipped before, flip now */
|
||||
if(vlr->v4) {
|
||||
CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
|
||||
}
|
||||
else {
|
||||
CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void displace_render_vert(ShadeInput *shi, VertRen *vr, float *scale)
|
||||
{
|
||||
short texco= shi->mat->texco;
|
||||
@@ -2973,9 +2855,9 @@ static void displace_render_vert(ShadeInput *shi, VertRen *vr, float *scale)
|
||||
vr->co[2] += shi->displace[2] * scale[2] ;
|
||||
|
||||
//printf("after co=%f, %f, %f\n", vr->co[0], vr->co[1], vr->co[2]);
|
||||
|
||||
|
||||
/* we just don't do this vertex again, bad luck for other face using same vertex with
|
||||
different material... */
|
||||
different material... */
|
||||
vr->flag |= 1;
|
||||
|
||||
/* Pass sample back so displace_face can decide which way to split the quad */
|
||||
@@ -2987,3 +2869,105 @@ static void displace_render_vert(ShadeInput *shi, VertRen *vr, float *scale)
|
||||
/* Should be sqrt(sample), but I'm only looking for "bigger". Save the cycles. */
|
||||
return;
|
||||
}
|
||||
|
||||
static void displace_render_face(VlakRen *vlr, float *scale)
|
||||
{
|
||||
ShadeInput shi;
|
||||
// VertRen vr;
|
||||
// float samp1,samp2, samp3, samp4, xn;
|
||||
short hasuv=0;
|
||||
/* set up shadeinput struct for multitex() */
|
||||
|
||||
shi.osatex= 0; /* signal not to use dx[] and dy[] texture AA vectors */
|
||||
shi.vlr= vlr; /* current render face */
|
||||
shi.mat= vlr->mat; /* current input material */
|
||||
|
||||
|
||||
/* UV coords must come from face */
|
||||
hasuv = vlr->tface && (shi.mat->texco & TEXCO_UV);
|
||||
if (hasuv) shi.uv[2]=0.0f;
|
||||
/* I don't think this is used, but seting it just in case */
|
||||
|
||||
/* Displace the verts, flag is set when done */
|
||||
if (! (vlr->v1->flag)){
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[0][0]-1.0f; /* shi.uv and tface->uv are */
|
||||
shi.uv[1]= 2*vlr->tface->uv[0][1]-1.0f; /* scalled differently */
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v1, scale);
|
||||
}
|
||||
|
||||
if (! (vlr->v2->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[1][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[1][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v2, scale);
|
||||
}
|
||||
|
||||
if (! (vlr->v3->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[2][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[2][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v3, scale);
|
||||
}
|
||||
|
||||
if (vlr->v4) {
|
||||
if (! (vlr->v4->flag)) {
|
||||
if (hasuv) {
|
||||
shi.uv[0] = 2*vlr->tface->uv[3][0]-1.0f;
|
||||
shi.uv[1]= 2*vlr->tface->uv[3][1]-1.0f;
|
||||
}
|
||||
displace_render_vert(&shi, vlr->v4, scale);
|
||||
}
|
||||
/* We want to split the quad along the opposite verts that are */
|
||||
/* closest in displace value. This will help smooth edges. */
|
||||
if ( fabs(vlr->v1->accum - vlr->v3->accum) > fabs(vlr->v2->accum - vlr->v4->accum))
|
||||
vlr->flag |= R_DIVIDE_24;
|
||||
else vlr->flag &= ~R_DIVIDE_24; // E: typo?, was missing '='
|
||||
}
|
||||
|
||||
/* Recalculate the face normal - if flipped before, flip now */
|
||||
if(vlr->v4) {
|
||||
CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
|
||||
}
|
||||
else {
|
||||
CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void do_displacement(Object *ob, int startface, int numface, int startvert, int numvert )
|
||||
{
|
||||
VertRen *vr;
|
||||
VlakRen *vlr;
|
||||
// float min[3]={1e30, 1e30, 1e30}, max[3]={-1e30, -1e30, -1e30};
|
||||
float scale[3]={1.0f, 1.0f, 1.0f}, temp[3];//, xn
|
||||
int i; //, texflag=0;
|
||||
Object *obt;
|
||||
|
||||
/* Object Size with parenting */
|
||||
obt=ob;
|
||||
while(obt){
|
||||
VecAddf(temp, obt->size, obt->dsize);
|
||||
scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2];
|
||||
obt=obt->parent;
|
||||
}
|
||||
|
||||
/* Clear all flags */
|
||||
for(i=startvert; i<startvert+numvert; i++){
|
||||
vr= RE_findOrAddVert(i);
|
||||
vr->flag= 0;
|
||||
}
|
||||
|
||||
for(i=startface; i<startface+numface; i++){
|
||||
vlr=RE_findOrAddVlak(i);
|
||||
displace_render_face(vlr, scale);
|
||||
}
|
||||
|
||||
/* Recalc vertex normals */
|
||||
calc_vertexnormals(startvert, startface);
|
||||
}
|
||||
|
||||
|
||||
@@ -1798,8 +1798,6 @@ static void object_panel_particles(Object *ob)
|
||||
}
|
||||
|
||||
if(eff) {
|
||||
uiDefButS(block, MENU, B_CHANGEEFFECT, "Particles %x1", 895,187,107,27, &eff->buttype, 0, 0, 0, 0, "Set effect type");
|
||||
|
||||
if(eff->type==EFF_PARTICLE) {
|
||||
PartEff *paf;
|
||||
|
||||
@@ -1808,9 +1806,9 @@ static void object_panel_particles(Object *ob)
|
||||
uiDefBut(block, BUT, B_RECALCAL, "RecalcAll", 741,187,67,27, 0, 0, 0, 0, 0, "Update the particle system");
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButBitS(block, TOG, PAF_STATIC, B_CALCEFFECT, "Static", 825,187,67,27, &paf->flag, 0, 0, 0, 0, "Make static particles (deform only works with SubSurf)");
|
||||
if(paf->flag & PAF_STATIC)
|
||||
uiDefButBitS(block, TOG, PAF_ANIMATED, B_DIFF, "Animated",825,167,67,20, &paf->flag, 0, 0, 0, 0, "Static particles are recalculated each rendered frame");
|
||||
|
||||
if(paf->flag & PAF_STATIC) {
|
||||
uiDefButBitS(block, TOG, PAF_ANIMATED, B_DIFF, "Animated",895,187,107,27, &paf->flag, 0, 0, 0, 0, "Static particles are recalculated each rendered frame");
|
||||
}
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButI(block, NUM, B_CALCEFFECT, "Tot:", 550,146,91,20, &paf->totpart, 1.0, 100000.0, 0, 0, "Set the total number of particles");
|
||||
if(paf->flag & PAF_STATIC) {
|
||||
|
||||
@@ -44,28 +44,30 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_packedFile_types.h"
|
||||
#include "DNA_radio_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_texture_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_packedFile_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "DNA_radio_types.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_texture.h"
|
||||
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_plugin_types.h"
|
||||
#include "BKE_image.h"
|
||||
@@ -2704,7 +2706,7 @@ static void material_panel_map_to(Material *ma)
|
||||
}
|
||||
|
||||
|
||||
static void material_panel_map_input(Material *ma)
|
||||
static void material_panel_map_input(Object *ob, Material *ma)
|
||||
{
|
||||
uiBlock *block;
|
||||
MTex *mtex;
|
||||
@@ -2728,7 +2730,10 @@ static void material_panel_map_input(Material *ma)
|
||||
|
||||
uiDefButS(block, ROW, B_MATPRV, "Glob", 630,146,45,18, &(mtex->texco), 4.0, (float)TEXCO_GLOB, 0, 0, "Uses global coordinates for the texture coordinates");
|
||||
uiDefButS(block, ROW, B_MATPRV, "Orco", 675,146,50,18, &(mtex->texco), 4.0, (float)TEXCO_ORCO, 0, 0, "Uses the original coordinates of the mesh");
|
||||
uiDefButS(block, ROW, B_MATPRV, "Stick", 725,146,50,18, &(mtex->texco), 4.0, (float)TEXCO_STICKY, 0, 0, "Uses mesh's sticky coordinates for the texture coordinates");
|
||||
if( give_parteff(ob) )
|
||||
uiDefButS(block, ROW, B_MATPRV, "Strand", 725,146,50,18, &(mtex->texco), 4.0, (float)TEXCO_STRAND, 0, 0, "Uses normalized strand texture coordinate (1D)");
|
||||
else
|
||||
uiDefButS(block, ROW, B_MATPRV, "Stick", 725,146,50,18, &(mtex->texco), 4.0, (float)TEXCO_STICKY, 0, 0, "Uses mesh's sticky coordinates for the texture coordinates");
|
||||
uiDefButS(block, ROW, B_MATPRV, "Win", 775,146,45,18, &(mtex->texco), 4.0, (float)TEXCO_WINDOW, 0, 0, "Uses screen coordinates as texture coordinates");
|
||||
uiDefButS(block, ROW, B_MATPRV, "Nor", 820,146,44,18, &(mtex->texco), 4.0, (float)TEXCO_NORM, 0, 0, "Uses normal vector as texture coordinates");
|
||||
uiDefButS(block, ROW, B_MATPRV, "Refl", 864,146,44,18, &(mtex->texco), 4.0, (float)TEXCO_REFL, 0, 0, "Uses reflection vector as texture coordinates");
|
||||
@@ -3278,7 +3283,7 @@ void material_panels()
|
||||
|
||||
mtex= ma->mtex[ ma->texact ];
|
||||
if(mtex && mtex->tex) {
|
||||
material_panel_map_input(ma);
|
||||
material_panel_map_input(ob, ma);
|
||||
material_panel_map_to(ma);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,6 +795,9 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
|
||||
if(mat->texco & TEXCO_UV) {
|
||||
VECCOPY(shi->uv, shi->lo);
|
||||
}
|
||||
if(mat->texco & TEXCO_STRAND) {
|
||||
shi->strand= shi->lo[0];
|
||||
}
|
||||
if(mat->texco & TEXCO_OBJECT) {
|
||||
VECCOPY(shi->co, shi->lo);
|
||||
}
|
||||
@@ -883,15 +886,15 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *
|
||||
float specfac;
|
||||
|
||||
if(mat->spec_shader==MA_SPEC_PHONG)
|
||||
specfac= Phong_Spec(shi->vn, lv, shi->view, shi->har);
|
||||
specfac= Phong_Spec(shi->vn, lv, shi->view, shi->har, 0);
|
||||
else if(mat->spec_shader==MA_SPEC_COOKTORR)
|
||||
specfac= CookTorr_Spec(shi->vn, lv, shi->view, shi->har);
|
||||
specfac= CookTorr_Spec(shi->vn, lv, shi->view, shi->har, 0);
|
||||
else if(mat->spec_shader==MA_SPEC_BLINN)
|
||||
specfac= Blinn_Spec(shi->vn, lv, shi->view, mat->refrac, (float)shi->har);
|
||||
specfac= Blinn_Spec(shi->vn, lv, shi->view, mat->refrac, (float)shi->har, 0);
|
||||
else if(mat->spec_shader==MA_SPEC_WARDISO)
|
||||
specfac= WardIso_Spec(shi->vn, lv, shi->view, mat->rms);
|
||||
specfac= WardIso_Spec(shi->vn, lv, shi->view, mat->rms, 0);
|
||||
else
|
||||
specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3]);
|
||||
specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3], 0);
|
||||
|
||||
inprspec= specfac*shi->spec;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user