[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16718] branches/sim_physics/source/ blender: * Worked a bit on cleaning up the code involving layering volumes on
Matt Ebb
matt at mke3.net
Thu Sep 25 08:08:42 CEST 2008
Revision: 16718
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16718
Author: broken
Date: 2008-09-25 08:08:41 +0200 (Thu, 25 Sep 2008)
Log Message:
-----------
* Worked a bit on cleaning up the code involving layering volumes on
solids, in front of other volumes, etc. Now there's a 'layer depth'
value that works similarly to refraction depth - a limit for how many
times the view ray will penetrate different volumetric surfaces.
I have it close to being able to return alpha, but it's still not 100%
correct and needs a bit more work. Going to sit on this for a while.
Modified Paths:
--------------
branches/sim_physics/source/blender/blenkernel/intern/material.c
branches/sim_physics/source/blender/blenloader/intern/readfile.c
branches/sim_physics/source/blender/makesdna/DNA_material_types.h
branches/sim_physics/source/blender/render/extern/include/RE_shader_ext.h
branches/sim_physics/source/blender/render/intern/source/shadeinput.c
branches/sim_physics/source/blender/render/intern/source/volumetric.c
branches/sim_physics/source/blender/src/buttons_shading.c
Modified: branches/sim_physics/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/material.c 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/blenkernel/intern/material.c 2008-09-25 06:08:41 UTC (rev 16718)
@@ -172,6 +172,7 @@
ma->vol_absorption = 1.0f;
ma->vol_scattering = 1.0f;
ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
+ ma->vol_raydepth = 15;
ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;
Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c 2008-09-25 06:08:41 UTC (rev 16718)
@@ -7871,6 +7871,7 @@
ma->vol_absorption = 1.0f;
ma->vol_scattering = 1.0f;
ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
+ if (ma->vol_raydepth == 0) ma->vol_raydepth = 15;
}
}
}
Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h 2008-09-25 06:08:41 UTC (rev 16718)
@@ -71,8 +71,8 @@
float vol_absorption, vol_scattering;
float vol_absorption_col[3];
float vpad2;
+ short vol_raydepth;
short vol_shadeflag;
- short vpad;
float fresnel_mir, fresnel_mir_i;
float fresnel_tra, fresnel_tra_i;
Modified: branches/sim_physics/source/blender/render/extern/include/RE_shader_ext.h
===================================================================
--- branches/sim_physics/source/blender/render/extern/include/RE_shader_ext.h 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/render/extern/include/RE_shader_ext.h 2008-09-25 06:08:41 UTC (rev 16718)
@@ -113,7 +113,7 @@
/* internal face coordinates */
float u, v, dx_u, dx_v, dy_u, dy_v;
- float co[3], view[3];
+ float co[3], view[3], camera_co[3];
/* copy from material, keep synced so we can do memcopy */
/* current size: 23*4 */
Modified: branches/sim_physics/source/blender/render/intern/source/shadeinput.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/shadeinput.c 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/render/intern/source/shadeinput.c 2008-09-25 06:08:41 UTC (rev 16718)
@@ -671,6 +671,10 @@
}
}
+ /* 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(shi->view);
}
Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c 2008-09-25 03:02:30 UTC (rev 16717)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c 2008-09-25 06:08:41 UTC (rev 16718)
@@ -55,7 +55,7 @@
extern struct Render R;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-#if 0
+
static int vol_backface_intersect_check(Isect *is, int ob, RayFace *face)
{
VlakRen *vlr = (VlakRen *)face;
@@ -64,21 +64,33 @@
* of foward facing geometry don't cause the ray to stop */
return (INPR(is->vec, vlr->n) < 0.0f);
}
-#endif
-#define VOL_IS_SAMEOBJECT 1
+static int vol_frontface_intersect_check(Isect *is, int ob, RayFace *face)
+{
+ VlakRen *vlr = (VlakRen *)face;
+
+ /* only consider faces away, so overlapping layers
+ * of foward facing geometry don't cause the ray to stop */
+ return (INPR(is->vec, vlr->n) > 0.0f);
+}
+
+static int vol_always_intersect_check(Isect *is, int ob, RayFace *face)
+{
+ return 1;
+}
+
+#define VOL_IS_BACKFACE 1
#define VOL_IS_SAMEMATERIAL 2
#define VOL_BOUNDS_DEPTH 0
#define VOL_BOUNDS_SS 1
-static int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco, Isect *isect, int intersect_type)
+/* TODO: Box or sphere intersection types could speed things up */
+static int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco, Isect *isect, int intersect_type, int checkfunc)
{
- /* TODO: Box or sphere intersection types could speed things up */
-
- /* raytrace method */
float maxsize = RE_ray_tree_max_size(R.raytree);
+ int intersected=0;
/* TODO: use object's bounding box to calculate max size */
VECCOPY(isect->start, co);
@@ -86,16 +98,21 @@
isect->end[1] = co[1] + vec[1] * maxsize;
isect->end[2] = co[2] + vec[2] * maxsize;
- if (intersect_type == VOL_BOUNDS_DEPTH) isect->faceorig= (RayFace*)shi->vlr;
- else if (intersect_type == VOL_BOUNDS_SS) isect->faceorig= NULL;
-
isect->mode= RE_RAY_MIRROR;
isect->oborig= RAY_OBJECT_SET(&R, shi->obi);
isect->face_last= NULL;
isect->ob_last= 0;
isect->lay= -1;
- if(RE_ray_tree_intersect(R.raytree, isect))
+ if (intersect_type == VOL_BOUNDS_DEPTH) isect->faceorig= (RayFace*)shi->vlr;
+ else if (intersect_type == VOL_BOUNDS_SS) isect->faceorig= NULL;
+
+ if (checkfunc==VOL_IS_BACKFACE)
+ intersected = RE_ray_tree_intersect_check(R.raytree, isect, vol_backface_intersect_check);
+ else
+ intersected = RE_ray_tree_intersect(R.raytree, isect);
+
+ if(intersected)
{
float isvec[3];
@@ -245,7 +262,7 @@
VecMulf(lv, -1.0f);
/* find minimum of volume bounds, or lamp coord */
- if (vol_get_bounds(shi, co, lv, hitco, &is, VOL_BOUNDS_SS)) {
+ if (vol_get_bounds(shi, co, lv, hitco, &is, VOL_BOUNDS_SS, 0)) {
float dist = VecLenf(co, hitco);
if (ELEM(lar->type, LA_SUN, LA_HEMI))
@@ -312,88 +329,8 @@
VECCOPY(scatter, col);
}
-static void shade_intersection(ShadeInput *shi, float *col, Isect *is)
+static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float *endco)
{
- ShadeInput shi_new;
- ShadeResult shr_new;
-
- memset(&shi_new, 0, sizeof(ShadeInput));
-
- shi_new.mask= shi->mask;
- shi_new.osatex= shi->osatex;
- shi_new.depth= 1; /* only used to indicate tracing */
- shi_new.thread= shi->thread;
- shi_new.xs= shi->xs;
- shi_new.ys= shi->ys;
- shi_new.lay= shi->lay;
- shi_new.passflag= SCE_PASS_COMBINED; /* result of tracing needs no pass info */
- shi_new.combinedflag= 0xFFFFFF; /* ray trace does all options */
- shi_new.light_override= shi->light_override;
- shi_new.mat_override= shi->mat_override;
-
- memset(&shr_new, 0, sizeof(ShadeResult));
-
- shade_ray(is, &shi_new, &shr_new);
-
- col[0]= shr_new.diff[0] + shr_new.spec[0];
- col[1]= shr_new.diff[1] + shr_new.spec[1];
- col[2]= shr_new.diff[2] + shr_new.spec[2];
-}
-
-
-static void vol_trace_behind(ShadeInput *shi, float *co, Isect *isect_first, float *col)
-{
- RayFace *rforig=NULL;
- Isect isect;
- float maxsize = RE_ray_tree_max_size(R.raytree);
-
- if (isect_first != NULL) {
- /* there was already a ray intersection -
- * either the back of volume object or another object */
- ObjectInstanceRen *obi= RAY_OBJECT_GET(&R, isect_first->ob);
-
- if (obi != shi->obi) {
- /* already intersected with another object, so shade it */
- shade_intersection(shi, col, isect_first);
- return;
- } else {
- rforig = isect_first->face;
- }
- }
-
- /* get ready to trace a new ray behind the volume */
- VECCOPY(isect.start, co)
-
- if (rforig == NULL) {
- /* if there's no original ray intersection then the original
- * shaded surface is the inside of the volume at the far bounds.
- * We can use this face for the raytrace orig face */
- isect.faceorig= (RayFace *)shi->vlr;
- } else {
- isect.faceorig= rforig;
- }
-
- isect.end[0] = isect.start[0] + shi->view[0] * maxsize;
- isect.end[1] = isect.start[1] + shi->view[1] * maxsize;
- isect.end[2] = isect.start[2] + shi->view[2] * maxsize;
-
- isect.mode= RE_RAY_MIRROR;
- isect.oborig= RAY_OBJECT_SET(&R, shi->obi);
- isect.face_last= NULL;
- isect.ob_last= 0;
- isect.lay= -1;
-
- /* check to see if there's anything behind the volume, otherwise shade the sky */
- if(RE_ray_tree_intersect(R.raytree, &isect)) {
- shade_intersection(shi, col, &isect);
- } else {
- shadeSkyView(col, co, shi->view, NULL);
- }
-
-}
-
-static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float *endco, Isect *isect)
-{
float tr[3] = {1.0f, 1.0f, 1.0f}; /* total transmittance */
float radiance[3] = {0.f, 0.f, 0.f}, d_radiance[3] = {0.f, 0.f, 0.f};
float stepsize = shi->mat->vol_stepsize;
@@ -403,18 +340,17 @@
int s;
float step_sta[3], step_end[3], step_mid[3];
float col_behind[3];
- float total_density = 0.f;
-
+ float alpha;
float density = vol_get_density(shi, co);
/* multiply col_behind with beam transmittance over entire distance */
- vol_trace_behind(shi, endco, isect, col_behind);
vol_get_attenuation(shi, tau, co, endco, density, stepsize);
tr[0] *= exp(-tau[0]);
tr[1] *= exp(-tau[1]);
tr[2] *= exp(-tau[2]);
- VecMulVecf(radiance, tr, col_behind);
+ VecMulVecf(radiance, tr, col);
tr[0] = tr[1] = tr[2] = 1.0f;
+
/* ray marching */
nsteps = (int)ceil(VecLenf(co, endco) / stepsize);
@@ -444,7 +380,7 @@
tr[2] *= exp(-tau[2]);
/* Terminate raymarching if transmittance is small */
- //if (rgb_to_luminance(tr[0], tr[1], tr[2]) < 1e-3) break;
+ //if ((tr[0] + tr[1] + tr[2] * 0.333f) < 0.01f) continue;
/* incoming light via emission or scattering (additive) */
vol_get_emission(shi, step_emit, step_mid, density);
@@ -461,18 +397,14 @@
VECCOPY(step_sta, step_end);
VecAddf(step_end, step_end, stepvec);
-
- total_density += density;
}
-
-
col[0] = radiance[0];
col[1] = radiance[1];
col[2] = radiance[2];
- col[3] = 1.0f;
- //col[3] = total_density * stepsize;
+ alpha = 1.0f -(tr[0] + tr[1] + tr[2]) * 0.333f;
+ col[3] = alpha;
/*
Incoming radiance =
@@ -492,56 +424,124 @@
-- To find radiance from segments along the way:
find radiance for one step:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list