Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2004-06-30 22:54:09 +0400
committerTon Roosendaal <ton@blender.org>2004-06-30 22:54:09 +0400
commita8ef804146751f8b5ec0f83b411f4ab7d041ed84 (patch)
treee85a6e52b41f7774cf472171ee11783324eec991 /source/blender/blenkernel/intern/texture.c
parentc9b4585618ea72f61c4671d4734c9e48b6ce6745 (diff)
NEW: Ramp shades for diffuse and specular
http://www.blender3d.org/cms/Ramp_Shaders.348.0.html Material color and specular now can be defined by a Colorband. The actual color then is defined during shading based on: - shade value (like dotproduct) - energy value (dot product plus light) - normal - result of all shading (useful for adding stuff in the end) Special request from [A]ndy! :)
Diffstat (limited to 'source/blender/blenkernel/intern/texture.c')
-rw-r--r--source/blender/blenkernel/intern/texture.c93
1 files changed, 43 insertions, 50 deletions
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 44e16684f15..2507ca5c2b8 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -238,10 +238,9 @@ ColorBand *add_colorband()
/* ------------------------------------------------------------------------- */
-int do_colorband(ColorBand *coba)
+int do_colorband(ColorBand *coba, float in, float out[4])
{
/* These vars form the texture channel, in render/intern/texture.c */
- extern float Tin, Tr, Tg, Tb, Ta;
extern int Talpha;
CBData *cbd1, *cbd2, *cbd0, *cbd3;
float fac, mfac, t[4];
@@ -251,61 +250,55 @@ int do_colorband(ColorBand *coba)
Talpha= 1;
cbd1= coba->data;
-
- if(Tin <= cbd1->pos) { /* ultimate left */
- Tr= cbd1->r;
- Tg= cbd1->g;
- Tb= cbd1->b;
- Ta= cbd1->a;
+ if(coba->tot==1) {
+ out[0]= cbd1->r;
+ out[1]= cbd1->g;
+ out[2]= cbd1->b;
+ out[3]= cbd1->a;
}
else {
- /* we're looking for first pos > Tin */
-
- for(a=0; a<coba->tot; a++, cbd1++) if(cbd1->pos >= Tin) break;
+ if(in < cbd1->pos) in= cbd1->pos;
+
+ /* we're looking for first pos > in */
+ for(a=0; a<coba->tot; a++, cbd1++) if(cbd1->pos > in) break;
+
+ if(a==coba->tot) cbd1--;
+ if(in > cbd1->pos) in= cbd1->pos;
+
+ cbd2= cbd1-1;
+ fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos);
+
+ if(coba->ipotype==2) {
+ /* ipo from right to left: 3 2 1 0 */
- if(a==coba->tot) { /* ultimate right */
- cbd1--;
- Tr= cbd1->r;
- Tg= cbd1->g;
- Tb= cbd1->b;
- Ta= cbd1->a;
+ if(a>=coba->tot-1) cbd0= cbd1;
+ else cbd0= cbd1+1;
+ if(a<2) cbd3= cbd2;
+ else cbd3= cbd2-1;
+
+ set_four_ipo(fac, t, KEY_BSPLINE);
+
+ out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r;
+ out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
+ out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b;
+ out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a;
+ CLAMP(out[0], 0.0, 1.0);
+ CLAMP(out[1], 0.0, 1.0);
+ CLAMP(out[2], 0.0, 1.0);
+ CLAMP(out[3], 0.0, 1.0);
}
else {
- cbd2= cbd1-1;
- fac= (Tin-cbd1->pos)/(cbd2->pos-cbd1->pos);
-
- if(coba->ipotype==2) {
- /* ipo from right to left: 3 2 1 0 */
-
- if(a>=coba->tot-1) cbd0= cbd1;
- else cbd0= cbd1+1;
- if(a<2) cbd3= cbd2;
- else cbd3= cbd2-1;
-
- set_four_ipo(fac, t, KEY_BSPLINE);
-
- Tr= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r;
- Tg= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
- Tb= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b;
- Ta= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a;
- CLAMP(Tr, 0.0, 1.0);
- CLAMP(Tg, 0.0, 1.0);
- CLAMP(Tb, 0.0, 1.0);
- CLAMP(Ta, 0.0, 1.0);
+
+ if(coba->ipotype==1) { /* EASE */
+ mfac= fac*fac;
+ fac= 3.0f*mfac-2.0f*mfac*fac;
}
- else {
+ mfac= 1.0f-fac;
- if(coba->ipotype==1) { /* EASE */
- mfac= fac*fac;
- fac= 3.0f*mfac-2.0f*mfac*fac;
- }
- mfac= 1.0f-fac;
-
- Tr= mfac*cbd1->r + fac*cbd2->r;
- Tg= mfac*cbd1->g + fac*cbd2->g;
- Tb= mfac*cbd1->b + fac*cbd2->b;
- Ta= mfac*cbd1->a + fac*cbd2->a;
- }
+ out[0]= mfac*cbd1->r + fac*cbd2->r;
+ out[1]= mfac*cbd1->g + fac*cbd2->g;
+ out[2]= mfac*cbd1->b + fac*cbd2->b;
+ out[3]= mfac*cbd1->a + fac*cbd2->a;
}
}
return 1; /* OK */