volume material
authorMatt Ebb <matt@mke3.net>
Sun, 16 Aug 2009 06:10:31 +0000 (06:10 +0000)
committerMatt Ebb <matt@mke3.net>
Sun, 16 Aug 2009 06:10:31 +0000 (06:10 +0000)
* 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

release/ui/buttons_material.py
release/ui/buttons_texture.py
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/texture.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_texture.c
source/blender/render/intern/source/texture.c
source/blender/render/intern/source/volumetric.c

index 4c919f813e230ba56711bc27a562c47cf49121c6..5b3ad34a09a43a1a38beb165a2345150202f998d 100644 (file)
@@ -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,8 @@ 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'])
        
@@ -497,41 +497,88 @@ class MATERIAL_PT_volume(MaterialButtonsPanel):
                
                split = layout.split()
                
+               row = split.row()
+               row.itemR(vol, "density")
+               row.itemR(vol, "scattering")
+               
+               split = layout.split()
                col = split.column()
-               col.itemR(vol, "step_calculation")
-               col.itemR(vol, "step_size")
-               col.itemR(vol, "shading_step_size")
+               col.itemR(vol, "absorption")
+               col.itemR(vol, "absorption_color", text="")
+               
+                               
+               col = split.column()
+               col.itemR(vol, "emission")
+               col.itemR(vol, "emission_color", text="")
                
-               col.itemR(mat, "alpha", text="Density", slider=True)
                
-               col.itemR(vol, "scattering_mode")
-               if vol.scattering_mode == 'SINGLE':
+
+class MATERIAL_PT_volume_scattering(MaterialButtonsPanel):
+       __label__ = "Scattering"
+       __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.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.itemL(text="Anisotropic Scattering:")
+               col.itemR(vol, "phase_function", text="")
+               if vol.phase_function in ('SCHLICK', 'HENYEY-GREENSTEIN'):
+                       col.itemR(vol, "asymmetry")
                
-               col.itemR(mat, "emit")
-               col.itemR(mat, "diffuse_color")
+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")
                
-               col.itemR(vol, "phase_function")
-               col.itemR(vol, "asymmetry")
                
-
-
 class MATERIAL_PT_halo(MaterialButtonsPanel):
        __label__= "Halo"
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
@@ -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)
index 5998eca870af1b02c156eb9b63f46df14e7771f3..5b48fdfbaa4f45cbdbd894dfb9a815c2da7df1c9 100644 (file)
@@ -176,35 +176,51 @@ class TEXTURE_PT_influence(TextureButtonsPanel):
                        sub.itemR(tex, factor, text=name, slider=True)
                
                if ma:
-                       split = layout.split()
-                       
-                       col = split.column()
-                       col.itemL(text="Diffuse:")
-                       factor_but(col, tex.map_diffuse, "map_diffuse", "diffuse_factor", "Intensity")
-                       factor_but(col, tex.map_colordiff, "map_colordiff", "colordiff_factor", "Color")
-                       factor_but(col, tex.map_alpha, "map_alpha", "alpha_factor", "Alpha")
-                       factor_but(col, tex.map_translucency, "map_translucency", "translucency_factor", "Translucency")
+                       if ma.type in ['SURFACE', 'HALO', 'WIRE']:
+                               split = layout.split()
+                               
+                               col = split.column()
+                               col.itemL(text="Diffuse:")
+                               factor_but(col, tex.map_diffuse, "map_diffuse", "diffuse_factor", "Intensity")
+                               factor_but(col, tex.map_colordiff, "map_colordiff", "colordiff_factor", "Color")
+                               factor_but(col, tex.map_alpha, "map_alpha", "alpha_factor", "Alpha")
+                               factor_but(col, tex.map_translucency, "map_translucency", "translucency_factor", "Translucency")
+
+                               col.itemL(text="Specular:")
+                               factor_but(col, tex.map_specular, "map_specular", "specular_factor", "Intensity")
+                               factor_but(col, tex.map_colorspec, "map_colorspec", "colorspec_factor", "Color")
+                               factor_but(col, tex.map_hardness, "map_hardness", "hardness_factor", "Hardness")
+
+                               col = split.column()
+                               col.itemL(text="Shading:")
+                               factor_but(col, tex.map_ambient, "map_ambient", "ambient_factor", "Ambient")
+                               factor_but(col, tex.map_emit, "map_emit", "emit_factor", "Emit")
+                               factor_but(col, tex.map_mirror, "map_mirror", "mirror_factor", "Mirror")
+                               factor_but(col, tex.map_raymir, "map_raymir", "raymir_factor", "Ray Mirror")
+
+                               col.itemL(text="Geometry:")
+                               factor_but(col, tex.map_normal, "map_normal", "normal_factor", "Normal")
+                               factor_but(col, tex.map_warp, "map_warp", "warp_factor", "Warp")
+                               factor_but(col, tex.map_displacement, "map_displacement", "displacement_factor", "Displace")
+
+                               #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")
+                               
 
-                       col.itemL(text="Specular:")
-                       factor_but(col, tex.map_specular, "map_specular", "specular_factor", "Intensity")
-                       factor_but(col, tex.map_colorspec, "map_colorspec", "colorspec_factor", "Color")
-                       factor_but(col, tex.map_hardness, "map_hardness", "hardness_factor", "Hardness")
-
-                       col = split.column()
-                       col.itemL(text="Shading:")
-                       factor_but(col, tex.map_ambient, "map_ambient", "ambient_factor", "Ambient")
-                       factor_but(col, tex.map_emit, "map_emit", "emit_factor", "Emit")
-                       factor_but(col, tex.map_mirror, "map_mirror", "mirror_factor", "Mirror")
-                       factor_but(col, tex.map_raymir, "map_raymir", "raymir_factor", "Ray Mirror")
-
-                       col.itemL(text="Geometry:")
-                       factor_but(col, tex.map_normal, "map_normal", "normal_factor", "Normal")
-                       factor_but(col, tex.map_warp, "map_warp", "warp_factor", "Warp")
-                       factor_but(col, tex.map_displacement, "map_displacement", "displacement_factor", "Displace")
-
-                       #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 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:
index a46014d0a7c4527a47bb92db406a87f619f7c1cc..51748443c977e02febb07d82e1fe71fabb61acaa 100644 (file)
@@ -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;
index 234078f66ae9b6ec464be5c61174489ee9ae30fb..fc9948f8d955739252125bb37f9e1690ead5d716 100644 (file)
@@ -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;
index 4ee71ea92dbb729b71ce004f331cb77b806815f2..c5588ccf7d6ea29f741174f300738bc5a2899693 100644 (file)
@@ -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;
                }
 
index 22ec0f6d59ea04cc95f75cb201e553d0440b8161..1729db37ad14d1dc34d3066d1351f79a7fb4bbba 100644 (file)
@@ -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 density;
+       float emission;
+       float absorption;
+       float scattering;
+
+       float emission_col[3];
        float absorption_col[3];
-       short shadeflag;
+       float density_scale;
+       float depth_cutoff;
+
        short phasefunc_type;
+       short vpad[3];
        float phasefunc_g;
-       float vpad2[2];
        
-       float ms_diff, ms_intensity;
+       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
index 4ca1db09374422563d369e290d8774c8f37e03e4..3f2253210249dedb6908b7bbead0b5e26db55c9e 100644 (file)
@@ -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);
-       */
 }
 
 
index 203012dbc80036fa32c27a599f06401ebb357511..01078ac24120be5d9fbb5156d30aabed65498994 100644 (file)
@@ -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);
 
index 27cf698aabe25083957b2ea60e3b8051ca3ee25a..1b25edaab3492e9508266f6181e37f3632974dcf 100644 (file)
@@ -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,15 +2408,27 @@ 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);
                                }
index 04eb1b5e3bf62b612ee4c4f8d09f33a0d27da698..63c4e97f86ee2e0e09c663ee3c6fd95771ff9f87 100644 (file)
@@ -165,82 +165,91 @@ 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)
+/* scattering multiplier, values above 1.0 are non-physical, 
+ * but can be useful to tweak lighting */
+float vol_get_scattering_fac(ShadeInput *shi, float *co)
 {
-       float emission = shi->mat->emit;
+       float scatter = shi->mat->vol.scattering;
        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);
+       do_volume_tex(shi, co, MAP_SCATTERING, col, &scatter);
        
-       em[0] = em[1] = em[2] = emission * density;
-       VecMulVecf(em, em, col);
+       return scatter;
 }
 
-/* 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)
-{
-       *scatter_fac = shi->mat->vol.scattering;
-}
-
-/* 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)
+/* 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)
 {
-       const float costheta = Inpf(w, wp);
+       float emission = shi->mat->vol.emission;
+       VECCOPY(emission_col, shi->mat->vol.emission_col);
        
-       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) {
-               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;
-       }
+       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 dummy = 1.0f;
-       const float absorption = shi->mat->vol.absorption;
-       
+       float absorption = shi->mat->vol.absorption;
        VECCOPY(absorb_col, shi->mat->vol.absorption_col);
        
-       do_volume_tex(shi, co, MAP_COLMIR, absorb_col, &dummy);
+       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;
+       
+       /*
+        * 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 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));
+       }
+}
+
 /* Compute attenuation, otherwise known as 'optical thickness', extinction, or tau.
  * Used in the relationship Transmittance = e^(-attenuation)
  */
@@ -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];