volume material

* data reorganisation - uses own values now instead of reusing surface material properties (i.e. an individual density value, rather than reusing alpha) Files saved with the old system won't load up the same after this.

* improved defaults and ui
This commit is contained in:
Matt Ebb 2009-08-16 06:10:31 +00:00
parent a8872d99a9
commit fe984a6e6c
10 changed files with 364 additions and 170 deletions

@ -107,7 +107,7 @@ class MATERIAL_PT_strand(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context):
return context.material.type in ['SURFACE', 'WIRE', 'HALO']
return context.material.type in ('SURFACE', 'WIRE', 'HALO')
def draw(self, context):
layout = self.layout
@ -165,7 +165,7 @@ class MATERIAL_PT_options(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
def poll(self, context):
return (context.material.type in ['SURFACE', 'WIRE', 'HALO'])
return (context.material.type in ('SURFACE', 'WIRE', 'HALO'))
def draw(self, context):
layout = self.layout
@ -202,7 +202,7 @@ class MATERIAL_PT_shadows(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
def poll(self, context):
return context.material.type in ['SURFACE', 'WIRE']
return context.material.type in ('SURFACE', 'WIRE')
def draw(self, context):
layout = self.layout
@ -235,7 +235,7 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel):
def poll(self, context):
mat = context.material
return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
@ -289,7 +289,7 @@ class MATERIAL_PT_specular(MaterialButtonsPanel):
def poll(self, context):
mat = context.material
return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
@ -341,7 +341,7 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
def poll(self, context):
mat = context.material
return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context):
layout = self.layout
@ -383,7 +383,7 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel):
def poll(self, context):
mat = context.material
return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context):
layout = self.layout
@ -435,7 +435,7 @@ class MATERIAL_PT_raytransp(MaterialButtonsPanel):
def poll(self, context):
mat = context.material
return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context):
layout = self.layout
@ -481,8 +481,40 @@ class MATERIAL_PT_raytransp(MaterialButtonsPanel):
sub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
sub.itemR(rayt, "gloss_samples", text="Samples")
class MATERIAL_PT_volume(MaterialButtonsPanel):
__label__ = "Volume"
class MATERIAL_PT_volume_shading(MaterialButtonsPanel):
__label__ = "Shading"
__default_closed__ = False
COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context):
return (context.material.type == 'VOLUME') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
mat = context.material
vol = context.material.volume
split = layout.split()
row = split.row()
row.itemR(vol, "density")
row.itemR(vol, "scattering")
split = layout.split()
col = split.column()
col.itemR(vol, "absorption")
col.itemR(vol, "absorption_color", text="")
col = split.column()
col.itemR(vol, "emission")
col.itemR(vol, "emission_color", text="")
class MATERIAL_PT_volume_scattering(MaterialButtonsPanel):
__label__ = "Scattering"
__default_closed__ = False
COMPAT_ENGINES = set(['BLENDER_RENDER'])
@ -498,38 +530,53 @@ class MATERIAL_PT_volume(MaterialButtonsPanel):
split = layout.split()
col = split.column()
col.itemR(vol, "step_calculation")
col.itemR(vol, "step_size")
col.itemR(vol, "shading_step_size")
col.itemR(mat, "alpha", text="Density", slider=True)
col.itemR(vol, "scattering_mode")
if vol.scattering_mode == 'SINGLE':
col.itemR(vol, "scattering_mode", text="")
if vol.scattering_mode == 'SINGLE_SCATTERING':
col.itemR(vol, "light_cache")
sub = col.column()
sub.active = vol.light_cache
sub.itemR(vol, "cache_resolution")
elif vol.scattering_mode in ('MULTIPLE_SCATTERING', 'SINGLE_PLUS_MULTIPLE_SCATTERING'):
col.itemR(vol, "cache_resolution")
elif vol.scattering_mode in ['MULTIPLE', 'SINGLE_PLUS_MULTIPLE']:
col.itemR(vol, "cache_resolution")
col = col.column(align=True)
col.itemR(vol, "ms_diffusion")
col.itemR(vol, "ms_spread")
col.itemR(vol, "ms_intensity")
col.itemR(vol, "density_scale")
col.itemR(vol, "depth_cutoff")
col = split.column()
col.itemR(vol, "absorption")
col.itemR(vol, "absorption_color")
col.itemR(vol, "scattering")
col.itemR(mat, "emit")
col.itemR(mat, "diffuse_color")
col.itemR(vol, "phase_function")
# col.itemL(text="Anisotropic Scattering:")
col.itemR(vol, "phase_function", text="")
if vol.phase_function in ('SCHLICK', 'HENYEY-GREENSTEIN'):
col.itemR(vol, "asymmetry")
class MATERIAL_PT_volume_integration(MaterialButtonsPanel):
__label__ = "Integration"
__default_closed__ = False
COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context):
return (context.material.type == 'VOLUME') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
mat = context.material
vol = context.material.volume
split = layout.split()
col = split.column()
col.itemL(text="Step Calculation:")
col.itemR(vol, "step_calculation", text="")
col = col.column(align=True)
col.itemR(vol, "step_size")
col.itemR(vol, "shading_step_size")
col = split.column()
col.itemL()
col.itemR(vol, "depth_cutoff")
col.itemR(vol, "density_scale")
class MATERIAL_PT_halo(MaterialButtonsPanel):
@ -592,7 +639,9 @@ bpy.types.register(MATERIAL_PT_specular)
bpy.types.register(MATERIAL_PT_raymir)
bpy.types.register(MATERIAL_PT_raytransp)
bpy.types.register(MATERIAL_PT_sss)
bpy.types.register(MATERIAL_PT_volume)
bpy.types.register(MATERIAL_PT_volume_shading)
bpy.types.register(MATERIAL_PT_volume_scattering)
bpy.types.register(MATERIAL_PT_volume_integration)
bpy.types.register(MATERIAL_PT_halo)
bpy.types.register(MATERIAL_PT_physics)
bpy.types.register(MATERIAL_PT_strand)

@ -176,6 +176,7 @@ class TEXTURE_PT_influence(TextureButtonsPanel):
sub.itemR(tex, factor, text=name, slider=True)
if ma:
if ma.type in ['SURFACE', 'HALO', 'WIRE']:
split = layout.split()
col = split.column()
@ -205,6 +206,21 @@ class TEXTURE_PT_influence(TextureButtonsPanel):
#sub = col.column()
#sub.active = tex.map_translucency or tex.map_emit or tex.map_alpha or tex.map_raymir or tex.map_hardness or tex.map_ambient or tex.map_specularity or tex.map_reflection or tex.map_mirror
#sub.itemR(tex, "default_value", text="Amount", slider=True)
elif ma.type == 'VOLUME':
split = layout.split()
col = split.column()
factor_but(col, tex.map_density, "map_density", "density_factor", "Density")
factor_but(col, tex.map_emission, "map_emission", "emission_factor", "Emission")
factor_but(col, tex.map_absorption, "map_absorption", "absorption_factor", "Absorption")
factor_but(col, tex.map_scattering, "map_scattering", "scattering_factor", "Scattering")
col = split.column()
col.itemL(text=" ")
factor_but(col, tex.map_alpha, "map_coloremission", "coloremission_factor", "Emission Color")
factor_but(col, tex.map_colorabsorption, "map_colorabsorption", "colorabsorption_factor", "Absorption Color")
elif la:
row = layout.row()
factor_but(row, tex.map_color, "map_color", "color_factor", "Color")
@ -641,7 +657,7 @@ class TEXTURE_PT_voxeldata(TextureButtonsPanel):
if vd.file_format == 'RAW_8BIT':
layout.itemR(vd, "resolution")
if vd.file_format == 'SMOKE':
layout.itemR(vd, "object")
layout.itemR(vd, "domain_object")
layout.itemR(vd, "still")
if vd.still:

@ -170,12 +170,19 @@ 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.density = 1.0f;
ma->vol.emission = 0.0f;
ma->vol.absorption = 1.0f;
ma->vol.scattering = 1.0f;
ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
ma->vol.absorption_col[0] = ma->vol.absorption_col[1] = ma->vol.absorption_col[2] = 0.0f;
ma->vol.density_scale = 1.0f;
ma->vol.depth_cutoff = 0.01f;
ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
ma->vol.stepsize = 0.2f;
ma->vol.shade_stepsize = 0.2f;
ma->vol.shade_type = MA_VOL_SHADE_SINGLE;
ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
ma->vol.precache_resolution = 50;
ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;

@ -496,7 +496,8 @@ void default_tex(Tex *tex)
if (tex->vd) {
tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0;
tex->vd->interp_type=0;
tex->vd->interp_type=TEX_VD_LINEAR;
tex->vd->file_format=TEX_VD_SMOKE;
}
pit = tex->plugin;
if (pit) {
@ -978,7 +979,8 @@ struct VoxelData *BKE_add_voxeldata(void)
vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata");
vd->dataset = NULL;
vd->resol[0] = vd->resol[1] = vd->resol[2] = 1;
vd->interp_type= TEX_VD_NEARESTNEIGHBOR;
vd->interp_type= TEX_VD_LINEAR;
vd->file_format= TEX_VD_SMOKE;
vd->int_multiplier = 1.0;
return vd;

@ -9491,12 +9491,19 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
/* volume rendering settings */
ma->vol.density_scale = 1.0f;
ma->vol.stepsize = 0.2f;
ma->vol.shade_stepsize = 0.2f;
ma->vol.density = 1.0f;
ma->vol.emission = 0.0f;
ma->vol.absorption = 1.0f;
ma->vol.scattering = 1.0f;
ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
ma->vol.absorption_col[0] = ma->vol.absorption_col[1] = ma->vol.absorption_col[2] = 0.0f;
ma->vol.density_scale = 1.0f;
ma->vol.depth_cutoff = 0.01f;
ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
ma->vol.stepsize = 0.2f;
ma->vol.shade_stepsize = 0.2f;
ma->vol.shade_type = MA_VOL_SHADE_SINGLE;
ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
ma->vol.precache_resolution = 50;
}

@ -48,21 +48,30 @@ struct Ipo;
/* WATCH IT: change type? also make changes in ipo.h */
typedef struct VolumeSettings {
short stepsize_type;
short precache_resolution;
float stepsize, shade_stepsize;
float depth_cutoff;
short shade_type;
short vpad;
float density_scale;
float absorption, scattering;
float absorption_col[3];
short shadeflag;
short phasefunc_type;
float phasefunc_g;
float vpad2[2];
float density;
float emission;
float absorption;
float scattering;
float ms_diff, ms_intensity;
float emission_col[3];
float absorption_col[3];
float density_scale;
float depth_cutoff;
short phasefunc_type;
short vpad[3];
float phasefunc_g;
float stepsize;
float shade_stepsize;
short stepsize_type;
short shadeflag;
short shade_type;
short precache_resolution;
float ms_diff;
float ms_intensity;
int ms_steps;
} VolumeSettings;
@ -308,6 +317,14 @@ typedef struct Material {
#define MAP_WARP 8192
#define MAP_LAYER 16384
/* volume mapto - reuse definitions for now - a bit naughty! */
#define MAP_DENSITY 128
#define MAP_EMISSION 64
#define MAP_EMISSION_COL 1
#define MAP_ABSORPTION 512
#define MAP_ABSORPTION_COL 8
#define MAP_SCATTERING 16
/* mapto for halo */
//#define MAP_HA_COL 1
//#define MAP_HA_ALPHA 128

@ -468,6 +468,75 @@ static void rna_def_material_mtex(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Ambient Factor", "Amount texture affects ambient.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
/* volume material */
prop= RNA_def_property(srna, "map_coloremission", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION_COL);
RNA_def_property_ui_text(prop, "Emission Color", "Causes the texture to affect the colour of emission");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "map_colorabsorption", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_ABSORPTION_COL);
RNA_def_property_ui_text(prop, "Absorption Color", "Causes the texture to affect the result colour after absorption");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "map_density", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_DENSITY);
RNA_def_property_ui_text(prop, "Density", "Causes the texture to affect the volume's density");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "map_emission", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION);
RNA_def_property_ui_text(prop, "Emission", "Causes the texture to affect the volume's emission");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "map_absorption", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_ABSORPTION);
RNA_def_property_ui_text(prop, "Absorption", "Causes the texture to affect the volume's absorption");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "map_scattering", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SCATTERING);
RNA_def_property_ui_text(prop, "Scattering", "Causes the texture to affect the volume's scattering");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "coloremission_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "colfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Emission Color Factor", "Amount texture affects emission color.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "colorabsorption_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "colfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Absorpion Color Factor", "Amount texture affects diffuse color.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "density_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "varfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Density Factor", "Amount texture affects density.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "emission_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "varfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Emission Factor", "Amount texture affects emission.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "absorption_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "varfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Absorption Factor", "Amount texture affects absorption.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "scattering_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "varfac");
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Scattering Factor", "Amount texture affects scattering.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
/* end volume material */
prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_MaterialTextureSlot_enabled_get", "rna_MaterialTextureSlot_enabled_set");
RNA_def_property_ui_text(prop, "Enabled", "Enable this material texture slot.");
@ -810,9 +879,9 @@ static void rna_def_material_volume(BlenderRNA *brna)
static EnumPropertyItem prop_scattering_items[] = {
{MA_VOL_SHADE_NONE, "NONE", 0, "None", ""},
{MA_VOL_SHADE_SINGLE, "SINGLE", 0, "Single", ""},
{MA_VOL_SHADE_MULTIPLE, "MULTIPLE", 0, "Multiple", ""},
{MA_VOL_SHADE_SINGLEPLUSMULTIPLE, "SINGLE_PLUS_MULTIPLE", 0, "Single + Multiple", ""},
{MA_VOL_SHADE_SINGLE, "SINGLE_SCATTERING", 0, "Single Scattering", ""},
{MA_VOL_SHADE_MULTIPLE, "MULTIPLE_SCATTERING", 0, "Multiple Scattering", ""},
{MA_VOL_SHADE_SINGLEPLUSMULTIPLE, "SINGLE_PLUS_MULTIPLE_SCATTERING", 0, "Single + Multiple Scattering", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem prop_stepsize_items[] = {
@ -844,12 +913,14 @@ static void rna_def_material_volume(BlenderRNA *brna)
prop= RNA_def_property(srna, "step_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "stepsize");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
RNA_def_property_ui_text(prop, "Step Size", "Distance between subsequent volume depth samples.");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "shading_step_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "shade_stepsize");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
RNA_def_property_ui_text(prop, "Shading Step Size", "Distance between subsequent volume shading samples.");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
@ -894,15 +965,23 @@ static void rna_def_material_volume(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Depth Cutoff", "Stop ray marching early if transmission drops below this luminance - higher values give speedups in dense volumes at the expense of accuracy.");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "density", PROP_FLOAT, PROP_PERCENTAGE);
RNA_def_property_float_sdna(prop, NULL, "density");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Density", "The base density of the volume");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "density_scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "density_scale");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
RNA_def_property_ui_text(prop, "Density Scale", "Multiplier for the material's density");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "absorption", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "absorption");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
RNA_def_property_ui_text(prop, "Absorption", "Amount of light that gets absorbed by the volume - higher values mean light travels less distance");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
@ -915,9 +994,23 @@ static void rna_def_material_volume(BlenderRNA *brna)
prop= RNA_def_property(srna, "scattering", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "scattering");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1 ,3);
RNA_def_property_ui_text(prop, "Scattering", "Amount of light that gets scattered by the volume - values > 1.0 are non-physical");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "emission", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "emission");
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
RNA_def_property_ui_text(prop, "Emission", "Amount of light that gets emitted by the volume");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
prop= RNA_def_property(srna, "emission_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "emission_col");
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Emission Color", "");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW, NULL);
prop= RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "shadeflag", MA_VOL_USEALPHA); /* use bitflags */
RNA_def_property_ui_text(prop, "Use Alpha", "Temp method for getting a usable alpha channel");
@ -934,14 +1027,6 @@ static void rna_def_material_volume(BlenderRNA *brna)
RNA_def_property_range(prop, -1.0f, 1.0f);
RNA_def_property_ui_text(prop, "Asymmetry", "Continuum between forward scattering and back scattering");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
/*
prop= RNA_def_property(srna, "samples", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "samp_gloss_mir");
RNA_def_property_range(prop, 0, 1024);
RNA_def_property_ui_text(prop, "Gloss Samples", "Number of cone samples averaged for blurry reflections.");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING, NULL);
*/
}

@ -1448,9 +1448,9 @@ static void rna_def_texture_voxeldata(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Still Frame Number", "The frame number to always use");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
prop= RNA_def_property(srna, "domain_object", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "object");
RNA_def_property_ui_text(prop, "Object", "Object to use for smoke simulations");
RNA_def_property_ui_text(prop, "Domain Object", "Object used as the smoke simulation domain");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_update(prop, NC_TEXTURE, NULL);

@ -2362,7 +2362,7 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa
}
if((mapto_flag & (MAP_COL+MAP_COLMIR)) && (mtex->mapto & (MAP_COL+MAP_COLMIR))) {
if((mapto_flag & (MAP_EMISSION_COL+MAP_ABSORPTION_COL)) && (mtex->mapto & (MAP_EMISSION_COL+MAP_ABSORPTION_COL))) {
float tcol[3], colfac;
/* stencil maps on the texture control slider, not texture intensity value */
@ -2386,12 +2386,12 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa
}
/* used for emit */
if((mapto_flag & MAP_COL) && (mtex->mapto & MAP_COL)) {
if((mapto_flag & MAP_EMISSION_COL) && (mtex->mapto & MAP_EMISSION_COL)) {
texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype);
}
/* MAP_COLMIR is abused for absorption colour at the moment */
if((mapto_flag & MAP_COLMIR) && (mtex->mapto & MAP_COLMIR)) {
if((mapto_flag & MAP_ABSORPTION_COL) && (mtex->mapto & MAP_ABSORPTION_COL)) {
texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype);
}
}
@ -2408,14 +2408,26 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa
}
}
if((mapto_flag & MAP_EMIT) && (mtex->mapto & MAP_EMIT)) {
int flip= mtex->maptoneg & MAP_EMIT;
if((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) {
int flip= mtex->maptoneg & MAP_EMISSION;
*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
if(*val<0.0) *val= 0.0;
}
if((mapto_flag & MAP_ALPHA) && (mtex->mapto & MAP_ALPHA)) {
int flip= mtex->maptoneg & MAP_ALPHA;
if((mapto_flag & MAP_DENSITY) && (mtex->mapto & MAP_DENSITY)) {
int flip= mtex->maptoneg & MAP_DENSITY;
*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
CLAMP(*val, 0.0, 1.0);
}
if((mapto_flag & MAP_ABSORPTION) && (mtex->mapto & MAP_ABSORPTION)) {
int flip= mtex->maptoneg & MAP_ABSORPTION;
*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
CLAMP(*val, 0.0, 1.0);
}
if((mapto_flag & MAP_SCATTERING) && (mtex->mapto & MAP_SCATTERING)) {
int flip= mtex->maptoneg & MAP_SCATTERING;
*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
CLAMP(*val, 0.0, 1.0);

@ -165,80 +165,89 @@ static void vol_get_precached_scattering(ShadeInput *shi, float *scatter_col, fl
float vol_get_density(struct ShadeInput *shi, float *co)
{
float density = shi->mat->alpha;
float density = shi->mat->vol.density;
float density_scale = shi->mat->vol.density_scale;
float col[3] = {0.0, 0.0, 0.0};
do_volume_tex(shi, co, MAP_ALPHA, col, &density);
do_volume_tex(shi, co, MAP_DENSITY, col, &density);
return density * density_scale;
}
/* compute emission component, amount of radiance to add per segment
* can be textured with 'emit' */
void vol_get_emission(ShadeInput *shi, float *em, float *co, float density)
{
float emission = shi->mat->emit;
float col[3] = {0.0, 0.0, 0.0};
VECCOPY(col, &shi->mat->r);
do_volume_tex(shi, co, MAP_EMIT+MAP_COL, col, &emission);
em[0] = em[1] = em[2] = emission * density;
VecMulVecf(em, em, col);
}
/* scattering multiplier, values above 1.0 are non-physical,
* but can be useful to tweak lighting */
void vol_get_scattering_fac(ShadeInput *shi, float *scatter_fac, float *co, float density)
float vol_get_scattering_fac(ShadeInput *shi, float *co)
{
*scatter_fac = shi->mat->vol.scattering;
float scatter = shi->mat->vol.scattering;
float col[3] = {0.0, 0.0, 0.0};
do_volume_tex(shi, co, MAP_SCATTERING, col, &scatter);
return scatter;
}
/* compute emission component, amount of radiance to add per segment
* can be textured with 'emit' */
void vol_get_emission(ShadeInput *shi, float *emission_col, float *co, float density)
{
float emission = shi->mat->vol.emission;
VECCOPY(emission_col, shi->mat->vol.emission_col);
do_volume_tex(shi, co, MAP_EMISSION+MAP_EMISSION_COL, emission_col, &emission);
emission_col[0] = emission_col[0] * emission * density;
emission_col[1] = emission_col[1] * emission * density;
emission_col[2] = emission_col[2] * emission * density;
}
void vol_get_absorption(ShadeInput *shi, float *absorb_col, float *co)
{
float absorption = shi->mat->vol.absorption;
VECCOPY(absorb_col, shi->mat->vol.absorption_col);
do_volume_tex(shi, co, MAP_ABSORPTION+MAP_ABSORPTION_COL, absorb_col, &absorption);
absorb_col[0] = (1.0f - absorb_col[0]) * absorption;
absorb_col[1] = (1.0f - absorb_col[1]) * absorption;
absorb_col[2] = (1.0f - absorb_col[2]) * absorption;
}
/* phase function - determines in which directions the light
* is scattered in the volume relative to incoming direction
* and view direction */
float vol_get_phasefunc(ShadeInput *shi, short phasefunc_type, float g, float *w, float *wp)
{
const float costheta = Inpf(w, wp);
const float scale = M_PI;
if (phasefunc_type == MA_VOL_PH_ISOTROPIC) {
return 1.f / (4.f * M_PI);
}
else if (phasefunc_type == MA_VOL_PH_MIEHAZY) {
return (0.5f + 4.5f * powf(0.5 * (1.f + costheta), 8.f)) / (4.f*M_PI);
}
else if (phasefunc_type == MA_VOL_PH_MIEMURKY) {
return (0.5f + 16.5f * powf(0.5 * (1.f + costheta), 32.f)) / (4.f*M_PI);
}
else if (phasefunc_type == MA_VOL_PH_RAYLEIGH) {
return 3.f/(16.f*M_PI) * (1 + costheta * costheta);
}
else if (phasefunc_type == MA_VOL_PH_HG) {
return 1.f / (4.f * M_PI) * (1.f - g*g) / powf(1.f + g*g - 2.f * g * costheta, 1.5f);
}
else if (phasefunc_type == MA_VOL_PH_SCHLICK) {
/*
* Scale constant is required, since Blender's shading system doesn't normalise for
* energy conservation - eg. scaling by 1/pi for a lambert shader.
* This makes volumes darker than other solid objects, for the same lighting intensity.
* To correct this, scale up the phase function values
* until Blender's shading system supports this better. --matt
*/
switch (phasefunc_type) {
case MA_VOL_PH_MIEHAZY:
return scale * (0.5f + 4.5f * powf(0.5 * (1.f + costheta), 8.f)) / (4.f*M_PI);
case MA_VOL_PH_MIEMURKY:
return scale * (0.5f + 16.5f * powf(0.5 * (1.f + costheta), 32.f)) / (4.f*M_PI);
case MA_VOL_PH_RAYLEIGH:
return scale * 3.f/(16.f*M_PI) * (1 + costheta * costheta);
case MA_VOL_PH_HG:
return scale * (1.f / (4.f * M_PI) * (1.f - g*g) / powf(1.f + g*g - 2.f * g * costheta, 1.5f));
case MA_VOL_PH_SCHLICK:
{
const float k = 1.55f * g - .55f * g * g * g;
const float kcostheta = k * costheta;
return 1.f / (4.f * M_PI) * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta));
} else {
return 1.0f;
return scale * (1.f / (4.f * M_PI) * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta)));
}
case MA_VOL_PH_ISOTROPIC:
default:
return scale * (1.f / (4.f * M_PI));
}
}
void vol_get_absorption(ShadeInput *shi, float *absorb_col, float *co)
{
float dummy = 1.0f;
const float absorption = shi->mat->vol.absorption;
VECCOPY(absorb_col, shi->mat->vol.absorption_col);
do_volume_tex(shi, co, MAP_COLMIR, absorb_col, &dummy);
absorb_col[0] = (1.0f - absorb_col[0]) * absorption;
absorb_col[1] = (1.0f - absorb_col[1]) * absorption;
absorb_col[2] = (1.0f - absorb_col[2]) * absorption;
}
/* Compute attenuation, otherwise known as 'optical thickness', extinction, or tau.
@ -360,7 +369,7 @@ void vol_shade_one_lamp(struct ShadeInput *shi, float *co, LampRen *lar, float *
}
}
vol_get_scattering_fac(shi, &scatter_fac, co, density);
scatter_fac = vol_get_scattering_fac(shi, co);
VecMulf(lacol, scatter_fac);
}
@ -371,16 +380,13 @@ void vol_get_scattering(ShadeInput *shi, float *scatter, float *co, float stepsi
GroupObject *go;
LampRen *lar;
float col[3] = {0.f, 0.f, 0.f};
int i=0;
lights= get_lights(shi);
for(go=lights->first; go; go= go->next)
{
float lacol[3] = {0.f, 0.f, 0.f};
i++;
lar= go->lampren;
if (lar) {
vol_shade_one_lamp(shi, co, lar, lacol, stepsize, density);
VecAddf(col, col, lacol);
@ -575,9 +581,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in
/* shade volume from 'camera' to 1st hit point */
volumeintegrate(shi, col, shi->camera_co, shi->co);
shr->combined[0] = col[0];
shr->combined[1] = col[1];
shr->combined[2] = col[2];
VecCopyf(shr->combined, col);
if (shi->mat->vol.shadeflag & MA_VOL_USEALPHA) {
if (col[3] > 1.0f)
@ -606,9 +610,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in
/* shade volume from 1st hit point to 2nd hit point */
volumeintegrate(shi, col, shi->co, hitco);
shr->combined[0] = col[0];
shr->combined[1] = col[1];
shr->combined[2] = col[2];
VecCopyf(shr->combined, col);
if (shi->mat->vol.shadeflag & MA_VOL_USEALPHA) {
if (col[3] > 1.0f)
@ -650,9 +652,8 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct
tr[1] = exp(-tau[1]);
tr[2] = exp(-tau[2]);
shr->combined[0] = tr[0];
shr->combined[1] = tr[1];
shr->combined[2] = tr[2];
VecCopyf(shr->combined, tr);
shr->combined[3] = 1.0f -(tr[0] + tr[1] + tr[2]) * 0.333f;
shr->alpha = shr->combined[3];
@ -666,9 +667,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct
tr[1] = exp(-tau[1]);
tr[2] = exp(-tau[2]);
shr->combined[0] = tr[0];
shr->combined[1] = tr[1];
shr->combined[2] = tr[2];
VecCopyf(shr->combined, tr);
shr->combined[3] = 1.0f -(tr[0] + tr[1] + tr[2]) * 0.333f;
shr->alpha = shr->combined[3];