* Volume Rendering
authorMatt Ebb <matt@mke3.net>
Tue, 25 Aug 2009 06:30:09 +0000 (06:30 +0000)
committerMatt Ebb <matt@mke3.net>
Tue, 25 Aug 2009 06:30:09 +0000 (06:30 +0000)
Finally in 2.5 branch :)

Still things to do, but will continue working in here. I won't bother
repeating the commit messages from the last year or so, however I've
written up some technical docs to help Ton/Brecht/etc review and find
their way around the code:
http://wiki.blender.org/index.php/User:Broken/VolumeRenderingDev

That above page has some known issues and todos listed, but I'm still
interested in bug reports.

Credits for this code:
* Matt Ebb
(with thanks to Red Cartel/ProMotion Studios)
* Raul Fernandez Hernandez (Farsthary) for patches:
  o Light cache based multiple scattering approximation
  o Initial voxeldata texture code
  o Depth Cutoff threshold
* Andre Susano Pinto for BVH range lookup addition
* Trilinear interpolation adapted from pbrt
* Tricubic interpolation from libtricubic

1  2 
release/ui/buttons_texture.py
source/blender/render/intern/source/shadeinput.c

index 20b3c7bca3e72e17dfafb5e38540dc867d6f79bc,756f96b4803a0c2d2b2daca9298323a109b45869..4827f677336494cf3a6429c257012d5796e64840
@@@ -1,4 -1,4 +1,4 @@@
 -      
 +
  import bpy
  
  class TextureButtonsPanel(bpy.types.Panel):
@@@ -210,35 -210,51 +210,51 @@@ class TEXTURE_PT_influence(TextureSlotP
                        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")
-                       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")
+                       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 = 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")
@@@ -596,6 -612,62 +612,62 @@@ class TEXTURE_PT_distortednoise(Texture
                flow.itemR(tex, "distortion_amount", text="Distortion")
                flow.itemR(tex, "noise_size", text="Size")
                flow.itemR(tex, "nabla")        
+               
+ class TEXTURE_PT_voxeldata(TextureButtonsPanel):
+       __idname__= "TEXTURE_PT_voxeldata"
+       __label__ = "Voxel Data"
+       
+       def poll(self, context):
+               tex = context.texture
+               return (tex and tex.type == 'VOXEL_DATA')
+       def draw(self, context):
+               layout = self.layout
+               tex = context.texture
+               vd = tex.voxeldata
+               layout.itemR(vd, "file_format")
+               if vd.file_format in ['BLENDER_VOXEL', 'RAW_8BIT']:
+                       layout.itemR(vd, "source_path")
+               if vd.file_format == 'RAW_8BIT':
+                       layout.itemR(vd, "resolution")
+               if vd.file_format == 'SMOKE':
+                       layout.itemR(vd, "domain_object")
+               
+               layout.itemR(vd, "still")
+               if vd.still:
+                       layout.itemR(vd, "still_frame_number")
+               
+               layout.itemR(vd, "interpolation")
+               layout.itemR(vd, "intensity")
+               
+ class TEXTURE_PT_pointdensity(TextureButtonsPanel):
+       __idname__= "TEXTURE_PT_pointdensity"
+       __label__ = "Point Density"
+       
+       def poll(self, context):
+               tex = context.texture
+               return (tex and tex.type == 'POINT_DENSITY')
+       def draw(self, context):
+               layout = self.layout
+               tex = context.texture
+               pd = tex.pointdensity
+               layout.itemR(pd, "point_source")
+               layout.itemR(pd, "object")
+               if pd.point_source == 'PARTICLE_SYSTEM':
+                       layout.item_pointerR(pd, "particle_system", pd.object, "particle_systems", text="")
+               layout.itemR(pd, "radius")
+               layout.itemR(pd, "falloff")
+               if pd.falloff == 'SOFT':
+                       layout.itemR(pd, "falloff_softness")
+               layout.itemR(pd, "color_source")
+               layout.itemR(pd, "turbulence")
+               layout.itemR(pd, "turbulence_size")
+               layout.itemR(pd, "turbulence_depth")
+               layout.itemR(pd, "turbulence_influence")
+               
  
  bpy.types.register(TEXTURE_PT_context_texture)
  bpy.types.register(TEXTURE_PT_preview)
@@@ -613,6 -685,8 +685,8 @@@ bpy.types.register(TEXTURE_PT_envmap
  bpy.types.register(TEXTURE_PT_musgrave)
  bpy.types.register(TEXTURE_PT_voronoi)
  bpy.types.register(TEXTURE_PT_distortednoise)
+ bpy.types.register(TEXTURE_PT_voxeldata)
+ bpy.types.register(TEXTURE_PT_pointdensity)
  bpy.types.register(TEXTURE_PT_colors)
  bpy.types.register(TEXTURE_PT_mapping)
  bpy.types.register(TEXTURE_PT_influence)
index 857b401e29885a8ec0659a757d4a2f7988c151da,ed654eaf526c4450fa77316b3a1e9ae0d9f3d0d0..1a0edfd53ed450da892dfec0c3925db8e6a0a66a
@@@ -52,6 -52,7 +52,7 @@@
  #include "shading.h"
  #include "strand.h"
  #include "texture.h"
+ #include "volumetric.h"
  #include "zbuf.h"
  
  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@@ -166,6 -167,11 +167,11 @@@ void shade_material_loop(ShadeInput *sh
                        if((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode==R_ADDSKY))
                                shr->alpha= 1.0f;
        }       
+       
+       if(R.r.mode & R_RAYTRACE) {
+               if (R.render_volumes_inside.first)
+                       shade_volume_inside(shi, shr);
+       }
  }
  
  
@@@ -183,7 -189,12 +189,12 @@@ void shade_input_do_shade(ShadeInput *s
                /* copy all relevant material vars, note, keep this synced with render_types.h */
                shade_input_init_material(shi);
                
-               shade_material_loop(shi, shr);
+               if (shi->mat->material_type == MA_TYPE_VOLUME) {
+                       if(R.r.mode & R_RAYTRACE)
+                               shade_volume_outside(shi, shr);
+               } else { /* MA_TYPE_SURFACE, MA_TYPE_WIRE */
+                       shade_material_loop(shi, shr);
+               }
        }
        
        /* copy additional passes */
        }
        else alpha= 1.0f;
        
 -      
        /* add mist and premul color */
        if(shr->alpha!=1.0f || alpha!=1.0f) {
                float fac= alpha*(shr->alpha);
                shr->combined[3]= fac;
-               shr->combined[0]*= fac;
-               shr->combined[1]*= fac;
-               shr->combined[2]*= fac;
+               
+               if (shi->mat->material_type!= MA_TYPE_VOLUME)
+                       VecMulf(shr->combined, fac);
        }
-       else shr->combined[3]= 1.0f;
+       else
+               shr->combined[3]= 1.0f;
        
        /* add z */
        shr->z= -shi->co[2];
@@@ -698,6 -711,10 +710,10 @@@ void shade_input_calc_viewco(ShadeInpu
                }
        }
        
+       /* set camera coords - for scanline, it's always 0.0,0.0,0.0 (render is in camera space)
+        * however for raytrace it can be different - the position of the last intersection */
+       shi->camera_co[0] = shi->camera_co[1] = shi->camera_co[2] = 0.0f;
+       
        /* cannot normalize earlier, code above needs it at viewplane level */
        Normalize(view);
  }