[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13275] trunk/blender/source/blender: Render control feature: shader-level shadowbuffer bias

Ton Roosendaal ton at blender.org
Thu Jan 17 20:01:58 CET 2008


Revision: 13275
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13275
Author:   ton
Date:     2008-01-17 20:01:58 +0100 (Thu, 17 Jan 2008)

Log Message:
-----------
Render control feature: shader-level shadowbuffer bias

Lampbuffers require painful bias tweaking (to prevent aliasing or to
get shadow detail). Sometimes you want this different per object, like
for gras you want less shadow detail, but for the ground you want high
detail. This feature allows to tweak it.

The new "LBias" slider is in shader panel, bottom. Ugly! But, thats for
later...

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_material_types.h
    trunk/blender/source/blender/render/intern/include/shadbuf.h
    trunk/blender/source/blender/render/intern/source/pixelshading.c
    trunk/blender/source/blender/render/intern/source/shadbuf.c
    trunk/blender/source/blender/render/intern/source/shadeoutput.c
    trunk/blender/source/blender/src/buttons_shading.c

Modified: trunk/blender/source/blender/makesdna/DNA_material_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_material_types.h	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/makesdna/DNA_material_types.h	2008-01-17 19:01:58 UTC (rev 13275)
@@ -88,8 +88,10 @@
 	float strand_min, strand_widthfade;
 	char strand_uvname[32];
 	
-	float sbias;			/* shadow bias */
+	float sbias;			/* shadow bias to prevent terminator prob */
+	float lbias;			/* factor to multiply lampbias with (0.0 = no mult) */
 	float shad_alpha;		/* in use for irregular shadowbuffer */
+	float padf;				/* free padding, take me! */
 	
 	/* for buttons and render*/
 	char rgbsel, texact, pr_type, use_nodes;

Modified: trunk/blender/source/blender/render/intern/include/shadbuf.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/shadbuf.h	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/render/intern/include/shadbuf.h	2008-01-17 19:01:58 UTC (rev 13275)
@@ -57,7 +57,7 @@
  * @param inp The inproduct between viewvector and ?
  *
  */
-float testshadowbuf(struct ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp);	
+float testshadowbuf(struct ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, float mat_bias);	
 
 /**
  * Determines the shadow factor for lamp <lar>, between <p1>

Modified: trunk/blender/source/blender/render/intern/source/pixelshading.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pixelshading.c	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/render/intern/source/pixelshading.c	2008-01-17 19:01:58 UTC (rev 13275)
@@ -182,7 +182,7 @@
 					inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2];
 					if(inp>0.0) {
 						/* testshadowbuf==0.0 : 100% shadow */
-						shadfac = testshadowbuf(lar->shb, rco, dco, dco, inp);
+						shadfac = testshadowbuf(lar->shb, rco, dco, dco, inp, 0.0f);
 						if( shadfac>0.0 ) {
 							shadfac*= inp*soft*lar->energy;
 							ir -= shadfac;
@@ -219,7 +219,7 @@
 		if(i> -0.41) {			/* heuristic valua! */
 			shadfac= 1.0;
 			if(lar->shb) {
-				shadfac = testshadowbuf(lar->shb, rco, dco, dco, inp);
+				shadfac = testshadowbuf(lar->shb, rco, dco, dco, inp, 0.0f);
 				if(shadfac==0.0) continue;
 				i*= shadfac;
 			}

Modified: trunk/blender/source/blender/render/intern/source/shadbuf.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/shadbuf.c	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/render/intern/source/shadbuf.c	2008-01-17 19:01:58 UTC (rev 13275)
@@ -648,11 +648,11 @@
 
 /* the externally called shadow testing (reading) function */
 /* return 1.0: no shadow at all */
-float testshadowbuf(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp)
+float testshadowbuf(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, float mat_bias)
 {
 	ShadSampleBuf *shsample;
 	float fac, co[4], dx[3], dy[3], shadfac=0.0f;
-	float xs1,ys1, siz, *jit, *weight, xres, yres;
+	float xs1,ys1, siz, *jit, *weight, xres, yres, biasf;
 	int xs, ys, zs, bias, *rz;
 	short a, num;
 	
@@ -689,10 +689,12 @@
 	num= shb->samp*shb->samp;
 	fac= shb->soft;
 	
+	if(mat_bias!=0.0f) biasf= shb->bias*mat_bias;
+	else biasf= shb->bias;
 	/* with inp==1.0, bias is half the size. correction value was 1.1, giving errors 
 	   on cube edges, with one side being almost frontal lighted (ton)  */
-	bias= (1.5f-inp*inp)*shb->bias;
-
+	bias= (1.5f-inp*inp)*biasf;
+	
 	if(num==1) {
 		for(shsample= shb->buffers.first; shsample; shsample= shsample->next)
 			shadfac += readshadowbuf(shb, shsample, bias, (int)xs1, (int)ys1, zs);

Modified: trunk/blender/source/blender/render/intern/source/shadeoutput.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/shadeoutput.c	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/render/intern/source/shadeoutput.c	2008-01-17 19:01:58 UTC (rev 13275)
@@ -1054,7 +1054,7 @@
 			if(lar->buftype==LA_SHADBUF_IRREGULAR)
 				shadfac[3]= ISB_getshadow(shi, lar->shb);
 			else
-				shadfac[3] = testshadowbuf(lar->shb, shi->co, shi->dxco, shi->dyco, inp);
+				shadfac[3] = testshadowbuf(lar->shb, shi->co, shi->dxco, shi->dyco, inp, shi->mat->lbias);
 		}
 		else if(lar->mode & LA_SHAD_RAY) {
 			ray_shadow(shi, lar, shadfac);

Modified: trunk/blender/source/blender/src/buttons_shading.c
===================================================================
--- trunk/blender/source/blender/src/buttons_shading.c	2008-01-17 17:45:20 UTC (rev 13274)
+++ trunk/blender/source/blender/src/buttons_shading.c	2008-01-17 19:01:58 UTC (rev 13275)
@@ -3714,7 +3714,7 @@
 	uiBlock *block;
 	
 	block= uiNewBlock(&curarea->uiblocks, "material_panel_shading", UI_EMBOSS, UI_HELV, curarea->win);
-	if(uiNewPanel(curarea, block, "Shaders", "Material", 640, 0, 318, 204)==0) return;
+	if(uiNewPanel(curarea, block, "Shaders", "Material", 640, 0, 318, 224)==0) return;
 	
 	uiSetButLock(ma->id.lib!=NULL, ERROR_LIBDATA_MESSAGE);
 	
@@ -3792,6 +3792,7 @@
 		uiDefButF(block, NUMSLI, B_MATPRV, "SBias ",	159,30,151,19, &(ma->sbias), 0.0, 0.25, 10, 2, "Shadow bias, to prevent terminator problems on shadow boundary");
 		uiDefButF(block, NUMSLI, B_MATPRV, "Amb ",		9,10,150,19, &(ma->amb), 0.0, 1.0, 0, 0, "Sets the amount of global ambient color the material receives");
 		uiDefButF(block, NUMSLI, B_MATPRV, "Emit ",		159,10,151,19, &(ma->emit), 0.0, 2.0, 0, 0, "Sets the amount of light the material emits");
+		uiDefButF(block, NUMSLI, B_MATPRV, "LBias ",	9,-10,300,19, &(ma->lbias), 0.0, 10.0, 100, 2, "Factor to multiply shadowbuffer bias with (0 is ignore)");
 		uiBlockEndAlign(block);
 
 		uiBlockSetCol(block, TH_BUT_SETTING1);
@@ -3807,6 +3808,8 @@
 		uiBlockBeginAlign(block);
 		uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_MATPRV, "GR:",	9, 55, 150, 19, &ma->group, "Limit Lighting to Lamps in this Group"); 
 		uiDefButBitI(block, TOG, MA_GROUP_NOLAY, B_MATPRV,	"Exclusive",	159,55, 85,20, &(ma->mode), 0, 0, 0, 0, "The material exclusively uses Lamps in this Group");
+		
+		
 	}
 }
 





More information about the Bf-blender-cvs mailing list