* Volume Rendering
[blender.git] / source / blender / render / intern / source / shadeinput.c
index 857b401e29885a8ec0659a757d4a2f7988c151da..1a0edfd53ed450da892dfec0c3925db8e6a0a66a 100644 (file)
@@ -52,6 +52,7 @@
 #include "shading.h"
 #include "strand.h"
 #include "texture.h"
+#include "volumetric.h"
 #include "zbuf.h"
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -166,6 +167,11 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr)
                        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 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr)
                /* 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 */
@@ -210,11 +221,12 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr)
        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 +710,10 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float *
                }
        }
        
+       /* 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);
 }