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...
This commit is contained in:
@@ -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;
|
||||
|
@@ -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>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user