* A few volume rendering tweaks:
- modified point density so that it returns a more consistent density with regards to search radius. Previously larger radii would give much higher density but this is equalised out now. - Added a new volume material option 'density scale'. This is an overall scale multiplier for density, allowing you to (for example) crank down the density to a more desirable range if you're working at a large physical scale. Volume rendering is fundamentally scale dependant so this lets you correct to get the right visual result. - Also tweaked a few constants, old files won't render exactly the same, just minor things though.
This commit is contained in:
@@ -167,6 +167,7 @@ void init_material(Material *ma)
|
||||
ma->sss_front= 1.0f;
|
||||
ma->sss_back= 1.0f;
|
||||
|
||||
ma->vol_density_scale = 1.0f;
|
||||
ma->vol_stepsize = 0.2f;
|
||||
ma->vol_shade_stepsize = 0.2f;
|
||||
ma->vol_absorption = 1.0f;
|
||||
|
||||
@@ -7893,6 +7893,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
ma->vol_scattering = 1.0f;
|
||||
ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
|
||||
}
|
||||
if (ma->vol_density_scale < 0.0001f)
|
||||
ma->vol_density_scale = 1.0f;
|
||||
}
|
||||
|
||||
for(tex=main->tex.first; tex; tex= tex->id.next) {
|
||||
|
||||
@@ -66,7 +66,7 @@ typedef struct Material {
|
||||
short pad5[3];
|
||||
|
||||
/* volumetrics */
|
||||
float vol_alphathresh;
|
||||
float vol_density_scale;
|
||||
float vol_stepsize, vol_shade_stepsize;
|
||||
float vol_absorption, vol_scattering;
|
||||
float vol_absorption_col[3];
|
||||
|
||||
@@ -255,7 +255,7 @@ typedef struct PointDensityRangeData
|
||||
void accum_density(void *userdata, int index, float squared_dist)
|
||||
{
|
||||
PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
|
||||
const float dist = pdr->squared_radius - squared_dist;
|
||||
const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f;
|
||||
float density;
|
||||
|
||||
if (pdr->falloff_type == TEX_PD_FALLOFF_STD)
|
||||
@@ -287,7 +287,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
|
||||
float density=0.0f;
|
||||
float vec[3] = {0.0, 0.0, 0.0};
|
||||
float tv[3];
|
||||
float turb;
|
||||
float turb, noise_fac;
|
||||
|
||||
if ((!pd) || (!pd->point_tree)) {
|
||||
texres->tin = 0.0f;
|
||||
@@ -299,6 +299,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
|
||||
pdr.point_data = pd->point_data;
|
||||
pdr.falloff_type = pd->falloff_type;
|
||||
pdr.vec = vec;
|
||||
noise_fac = pd->noise_fac * 0.5f; /* better default */
|
||||
|
||||
if (pd->flag & TEX_PD_TURBULENCE) {
|
||||
VECCOPY(tv, texvec);
|
||||
@@ -313,9 +314,9 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
|
||||
|
||||
turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */
|
||||
|
||||
tv[0] = texvec[0] + pd->noise_fac * turb;
|
||||
tv[1] = texvec[1] + pd->noise_fac * turb;
|
||||
tv[2] = texvec[2] + pd->noise_fac * turb;
|
||||
tv[0] = texvec[0] + noise_fac * turb;
|
||||
tv[1] = texvec[1] + noise_fac * turb;
|
||||
tv[2] = texvec[2] + noise_fac * turb;
|
||||
|
||||
/* do density lookup with altered coordinates */
|
||||
BLI_bvhtree_range_query(pd->point_tree, tv, pd->radius, accum_density, &pdr);
|
||||
|
||||
@@ -131,13 +131,14 @@ static int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco,
|
||||
float vol_get_density(struct ShadeInput *shi, float *co)
|
||||
{
|
||||
float density = shi->mat->alpha;
|
||||
float density_scale = shi->mat->vol_density_scale;
|
||||
float col[3] = {0.0, 0.0, 0.0};
|
||||
|
||||
if (shi->mat->flag & MA_IS_TEXTURED) {
|
||||
do_volume_tex(shi, co, MAP_ALPHA, col, &density);
|
||||
}
|
||||
|
||||
return density;
|
||||
return density * density_scale;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4363,7 +4363,7 @@ static void material_panel_material_volume(Material *ma)
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
|
||||
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_stepsize), 0.001, 100.0, 10, 2, "Ray marching step size");
|
||||
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_stepsize), 0.001, 100.0, 100, 2, "Ray marching step size");
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
yco -= YSPACE;
|
||||
@@ -4372,7 +4372,7 @@ static void material_panel_material_volume(Material *ma)
|
||||
uiDefButBitS(block, TOG, MA_VOL_ATTENUATED, B_MATPRV, "Shading",
|
||||
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shadeflag), 0, 0, 0, 0, "Uses absorption for light attenuation");
|
||||
uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
|
||||
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shade_stepsize), 0.001, 100.0, 10, 2, "Step");
|
||||
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_shade_stepsize), 0.001, 100.0, 100, 2, "Step");
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
yco -= YSPACE;
|
||||
@@ -4389,14 +4389,18 @@ static void material_panel_material_volume(Material *ma)
|
||||
|
||||
yco = PANEL_YMAX;
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButF(block, NUMSLI, B_MATPRV, "Density: ",
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base opacity value");
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base density value - textured density is added on top");
|
||||
uiDefButF(block, NUM, B_MATPRV, "Density Scale: ",
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_density_scale), 0.000001, 100.0, 100, 2, "Global density multiplier");
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
yco -= YSPACE;
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButF(block, NUM, B_MATPRV, "Absorption: ",
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_absorption), 0.0, 10.0, 10, 0, "Multiplier for absorption");
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_absorption), 0.0, 100.0, 10, 0, "Multiplier for absorption");
|
||||
uiDefButF(block, COL, B_MATPRV, "",
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, ma->vol_absorption_col, 0, 0, 0, B_MATCOL, "");
|
||||
uiBlockEndAlign(block);
|
||||
@@ -4413,7 +4417,7 @@ static void material_panel_material_volume(Material *ma)
|
||||
yco -= YSPACE;
|
||||
|
||||
uiDefButF(block, NUM, B_MATPRV, "Scattering: ",
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_scattering), 0.0, 10.0, 10, 0, "Multiplier for scattering");
|
||||
X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_scattering), 0.0, 100.0, 10, 0, "Multiplier for scattering");
|
||||
}
|
||||
|
||||
static void material_panel_nodes(Material *ma)
|
||||
|
||||
Reference in New Issue
Block a user