Render control feature: shader-level shadowbuffer bias
authorTon Roosendaal <ton@blender.org>
Thu, 17 Jan 2008 19:01:58 +0000 (19:01 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 17 Jan 2008 19:01:58 +0000 (19:01 +0000)
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...

source/blender/makesdna/DNA_material_types.h
source/blender/render/intern/include/shadbuf.h
source/blender/render/intern/source/pixelshading.c
source/blender/render/intern/source/shadbuf.c
source/blender/render/intern/source/shadeoutput.c
source/blender/src/buttons_shading.c

index 1deda6a29d56a60a63542e8045c9f9ff0d373c6a..d885bfcae82c56cb4ca93b4573de5b1056fd4ee4 100644 (file)
@@ -88,8 +88,10 @@ typedef struct Material {
        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;
index 20a266f8579ac1291a0b5d02b714b6efd5fb380c..c5d8f2690c7bd94ae1e9ff0ae4b856c5f02ff80d 100644 (file)
@@ -57,7 +57,7 @@ void threaded_makeshadowbufs(struct Render *re);
  * @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>
index a1088d1a920b2437cf65efeec54353194e8b7113..4e589789412c555f486504a54688a55e9691bee5 100644 (file)
@@ -182,7 +182,7 @@ static void render_lighting_halo(HaloRen *har, float *colf)
                                        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 @@ static void render_lighting_halo(HaloRen *har, float *colf)
                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;
                        }
index 8e37606cdf9bda6816967e7d0fa5c2e8cc6ff9ee..34fd5b0154a44242af3a9430b804d20fbd5fc754 100644 (file)
@@ -648,11 +648,11 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int
 
 /* 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 @@ float testshadowbuf(ShadBuf *shb, float *rco, float *dxco, float *dyco, float in
        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);
index 0823ae146f762ec8537f39a78faf2811d5c116a9..ca81d456487b9f355b2e6a991f0d00fbe5f7660c 100644 (file)
@@ -1054,7 +1054,7 @@ void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float *shadfac, i
                        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);
index 2e73a6db06f857ea1f1d2ecd8f19169c7393dcfe..c7ba1430748c8b59ca581afdf57a8a1db7c797d7 100644 (file)
@@ -3714,7 +3714,7 @@ static void material_panel_shading(Material *ma)
        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 @@ static void material_panel_shading(Material *ma)
                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 @@ static void material_panel_shading(Material *ma)
                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");
+               
+               
        }
 }