forked from bartvdbraak/blender
Improved method to calculate normals for procedural textures such as
Marble, wood, clouds. Instead of the retarded (but faster :) old method it now derives the normal based on displacement of a 'nabla' vector; sampling the texture additionally with three little offsets in x, y and z. Code provided by Eeshlo, and gratefully accepted!
This commit is contained in:
parent
9d78e1164b
commit
b5071f367d
@ -191,38 +191,6 @@ void end_render_textures()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ************************** */
|
|
||||||
|
|
||||||
static int clouds(Tex *tex, float *texvec)
|
|
||||||
{
|
|
||||||
float (*turbfunc)(float, float, float, float, int);
|
|
||||||
|
|
||||||
if(tex->noisetype==TEX_NOISESOFT) turbfunc= BLI_turbulence;
|
|
||||||
else turbfunc= BLI_turbulence1;
|
|
||||||
|
|
||||||
Tin= turbfunc(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth);
|
|
||||||
|
|
||||||
if(tex->stype==1) {
|
|
||||||
|
|
||||||
Tr= Tin;
|
|
||||||
Tg= turbfunc(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth);
|
|
||||||
|
|
||||||
Tb= turbfunc(tex->noisesize,texvec[1],texvec[2],texvec[0], tex->noisedepth);
|
|
||||||
|
|
||||||
BRICONRGB;
|
|
||||||
Ta= 1.0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
BRICON;
|
|
||||||
|
|
||||||
if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int blend(Tex *tex, float *texvec)
|
static int blend(Tex *tex, float *texvec)
|
||||||
@ -271,65 +239,130 @@ static int blend(Tex *tex, float *texvec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* ************************************************************************* */
|
||||||
|
/* clouds, wood & marble updated to do proper bumpmapping */
|
||||||
|
/* 0.025 seems reasonable value for offset */
|
||||||
|
#define B_OFFS 0.025
|
||||||
|
|
||||||
static int wood(Tex *tex, float *texvec)
|
static int clouds(Tex *tex, float *texvec)
|
||||||
|
{
|
||||||
|
float (*turbfunc)(float, float, float, float, int);
|
||||||
|
int rv=0; /* return value, int:0, col:1, nor:2, everything:3 */
|
||||||
|
|
||||||
|
if (tex->noisetype==TEX_NOISESOFT) turbfunc = BLI_turbulence;
|
||||||
|
else turbfunc = BLI_turbulence1;
|
||||||
|
|
||||||
|
Tin = turbfunc(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth);
|
||||||
|
|
||||||
|
if (tex->nor!=NULL) {
|
||||||
|
/* calculate bumpnormal */
|
||||||
|
tex->nor[0] = Tin - turbfunc(tex->noisesize, texvec[0] + B_OFFS, texvec[1], texvec[2], tex->noisedepth);
|
||||||
|
tex->nor[1] = Tin - turbfunc(tex->noisesize, texvec[0], texvec[1] + B_OFFS, texvec[2], tex->noisedepth);
|
||||||
|
tex->nor[2] = Tin - turbfunc(tex->noisesize, texvec[0], texvec[1], texvec[2] + B_OFFS, tex->noisedepth);
|
||||||
|
rv += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tex->stype==1) {
|
||||||
|
/* in this case, int. value should really be computed from color,
|
||||||
|
and bumpnormal from that, would be too slow, looks ok as is */
|
||||||
|
Tr = Tin;
|
||||||
|
Tg = turbfunc(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth);
|
||||||
|
Tb = turbfunc(tex->noisesize, texvec[1], texvec[2], texvec[0], tex->noisedepth);
|
||||||
|
BRICONRGB;
|
||||||
|
Ta = 1.0;
|
||||||
|
return (rv+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
BRICON;
|
||||||
|
|
||||||
|
if (tex->flag & TEX_COLORBAND) return (rv + do_colorband(tex->coba));
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* computes basic wood intensity value at x,y,z */
|
||||||
|
static float wood_int(Tex *tex, float x, float y, float z)
|
||||||
{
|
{
|
||||||
float (*noisefunc)(float, float, float, float);
|
float (*noisefunc)(float, float, float, float);
|
||||||
|
float wi=0;
|
||||||
|
|
||||||
if (tex->noisetype==TEX_NOISESOFT) noisefunc = BLI_hnoise;
|
if (tex->noisetype==TEX_NOISESOFT) noisefunc = BLI_hnoise;
|
||||||
else noisefunc = BLI_hnoisep;
|
else noisefunc = BLI_hnoisep;
|
||||||
|
|
||||||
|
if (tex->stype==0)
|
||||||
if(tex->stype==0) {
|
wi = 0.5 + 0.5*sin((x + y + z)*10.0);
|
||||||
Tin= 0.5+0.5*sin( (texvec[0]+texvec[1]+texvec[2])*10.0 );
|
else if (tex->stype==1)
|
||||||
}
|
wi = 0.5 + 0.5*sin(sqrt(x*x + y*y + z*z)*20.0);
|
||||||
else if(tex->stype==1) {
|
|
||||||
Tin= 0.5+0.5*sin( sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2])*20.0 );
|
|
||||||
}
|
|
||||||
else if (tex->stype==2) {
|
else if (tex->stype==2) {
|
||||||
Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]);
|
wi = noisefunc(tex->noisesize, x, y, z);
|
||||||
Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(texvec[0]+texvec[1]+texvec[2])*10.0);
|
wi = 0.5 + 0.5*sin(tex->turbul*wi + (x + y + z)*10.0);
|
||||||
}
|
}
|
||||||
else if (tex->stype==3) {
|
else if (tex->stype==3) {
|
||||||
Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]);
|
wi = noisefunc(tex->noisesize, x, y, z);
|
||||||
Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2]))*20.0);
|
wi = 0.5 + 0.5*sin(tex->turbul*wi + (sqrt(x*x + y*y + z*z))*20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return wi;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int wood(Tex *tex, float *texvec)
|
||||||
|
{
|
||||||
|
int rv=0; /* return value, int:0, col:1, nor:2, everything:3 */
|
||||||
|
|
||||||
|
Tin = wood_int(tex, texvec[0], texvec[1], texvec[2]);
|
||||||
|
if (tex->nor!=NULL) {
|
||||||
|
/* calculate bumpnormal */
|
||||||
|
tex->nor[0] = Tin - wood_int(tex, texvec[0] + B_OFFS, texvec[1], texvec[2]);
|
||||||
|
tex->nor[1] = Tin - wood_int(tex, texvec[0], texvec[1] + B_OFFS, texvec[2]);
|
||||||
|
tex->nor[2] = Tin - wood_int(tex, texvec[0], texvec[1], texvec[2] + B_OFFS);
|
||||||
|
rv += 2;
|
||||||
|
}
|
||||||
|
|
||||||
BRICON;
|
BRICON;
|
||||||
if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba);
|
if (tex->flag & TEX_COLORBAND) return (rv + do_colorband(tex->coba));
|
||||||
|
|
||||||
return 0;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* computes basic marble intensity at x,y,z */
|
||||||
|
static float marble_int(Tex *tex, float x, float y, float z)
|
||||||
static int marble(Tex *tex, float *texvec)
|
|
||||||
{
|
{
|
||||||
float n;
|
float n, mi;
|
||||||
float (*turbfunc)(float, float, float, float, int);
|
float (*turbfunc)(float, float, float, float, int);
|
||||||
|
|
||||||
if (tex->noisetype==TEX_NOISESOFT) turbfunc = BLI_turbulence;
|
if (tex->noisetype==TEX_NOISESOFT) turbfunc = BLI_turbulence;
|
||||||
else turbfunc = BLI_turbulence1;
|
else turbfunc = BLI_turbulence1;
|
||||||
|
|
||||||
n= 5.0*(texvec[0]+texvec[1]+texvec[2]);
|
n = 5.0 * (x + y + z);
|
||||||
|
|
||||||
Tin = 0.5+0.5*sin(n+tex->turbul*turbfunc(tex->noisesize, texvec[0],texvec[1],texvec[2], tex->noisedepth));
|
mi = 0.5 + 0.5 * sin(n + tex->turbul*turbfunc(tex->noisesize, x, y, z, tex->noisedepth));
|
||||||
|
if (tex->stype>=1) {
|
||||||
|
mi = sqrt(mi);
|
||||||
|
if (tex->stype==2) mi = sqrt(mi);
|
||||||
|
}
|
||||||
|
|
||||||
switch (tex->stype) {
|
return mi;
|
||||||
case 1:
|
}
|
||||||
Tin= sqrt(Tin);
|
|
||||||
break;
|
static int marble(Tex *tex, float *texvec)
|
||||||
case 2:
|
{
|
||||||
Tin= sqrt(Tin);
|
int rv=0; /* return value, int:0, col:1, nor:2, everything:3 */
|
||||||
Tin= sqrt(Tin);
|
|
||||||
break;
|
Tin = marble_int(tex, texvec[0], texvec[1], texvec[2]);
|
||||||
|
|
||||||
|
if (tex->nor!=NULL) {
|
||||||
|
/* calculate bumpnormal */
|
||||||
|
tex->nor[0] = Tin - marble_int(tex, texvec[0] + B_OFFS, texvec[1], texvec[2]);
|
||||||
|
tex->nor[1] = Tin - marble_int(tex, texvec[0], texvec[1] + B_OFFS, texvec[2]);
|
||||||
|
tex->nor[2] = Tin - marble_int(tex, texvec[0], texvec[1], texvec[2] + B_OFFS);
|
||||||
|
rv += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
BRICON;
|
BRICON;
|
||||||
if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba);
|
if (tex->flag & TEX_COLORBAND) return (rv + do_colorband(tex->coba));
|
||||||
|
|
||||||
return 0;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user