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>2003-07-20 00:31:29 +0400
committerTon Roosendaal <ton@blender.org>2003-07-20 00:31:29 +0400
commit9bf630a1f32a264b5e0a6842ebb812e7eb52556e (patch)
tree3da4b284da99cc4e42eb0501b099263a5245ad8e /source/blender/render
parent86073223850632a34babb87bbf5996bff06dbc97 (diff)
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.
Diffstat (limited to 'source/blender/render')
-rw-r--r--source/blender/render/extern/include/render.h7
-rw-r--r--source/blender/render/intern/include/rendercore.h6
-rw-r--r--source/blender/render/intern/include/rendercore_int.h1
-rw-r--r--source/blender/render/intern/source/Makefile2
-rw-r--r--source/blender/render/intern/source/pixelshading.c32
-rw-r--r--source/blender/render/intern/source/rendercore.c222
6 files changed, 240 insertions, 30 deletions
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 <math.h>
-#include <string.h>
-#include <stdlib.h>
/* External modules: */
#include "MEM_guardedalloc.h"
@@ -64,6 +60,12 @@
#include "jitter.h"
+/* system includes */
+#include <math.h>
+#include <string.h>
+#include <stdlib.h>
+
+
/* 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;
+
+ 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;
+}
+
-float CookTorr(float *n, float *l, float *v, int hard)
+/* 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);