diff options
author | Matt Ebb <matt@mke3.net> | 2008-10-31 08:29:54 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2008-10-31 08:29:54 +0300 |
commit | 15579884b1255cba9de7662f72cd21323ad2c701 (patch) | |
tree | cd3caed0c9e71fcd4c3c3e732ab979f3e9962dad /source/blender | |
parent | 5fb8debada3db41d2ff40ee9a30e10ddcf35d35e (diff) |
* Added a new turbulence type: Time. It's not entirely well tested, but so far working ok. It's smoother looking than 'velocity' but may need more in depth investigation.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/render/intern/source/pointdensity.c | 85 | ||||
-rw-r--r-- | source/blender/render/intern/source/texture.c | 13 | ||||
-rw-r--r-- | source/blender/src/buttons_shading.c | 2 |
3 files changed, 55 insertions, 45 deletions
diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index 28d8c2388c4..483cc96122b 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -35,6 +35,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_global.h" +#include "BKE_lattice.h" #include "BKE_main.h" #include "BKE_object.h" #include "BKE_particle.h" @@ -56,12 +57,12 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa float partco[3]; float obview[4][4]; - /* init crap */ + /* init everything */ if (!psys || !ob || !pd) return; Mat4MulMat4(obview, re->viewinv, ob->obmat); - /* Just to create a valid rendering context */ + /* Just to create a valid rendering context for particles */ psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0); dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); @@ -79,8 +80,10 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6); - if (pd->noise_influence != TEX_PD_NOISE_STATIC) - pd->point_data = MEM_mallocN(sizeof(float)*3*total_particles, "point_data"); + if (pd->noise_influence == TEX_PD_NOISE_VEL) + pd->point_data = MEM_mallocN(sizeof(float)*3*total_particles, "velocity point data"); + else if (pd->noise_influence == TEX_PD_NOISE_TIME) + pd->point_data = MEM_mallocN(sizeof(float)*total_particles, "time point data"); if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) childexists = 1; @@ -108,6 +111,8 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa pd->point_data[i*3 + 0] = state.vel[0]; pd->point_data[i*3 + 1] = state.vel[1]; pd->point_data[i*3 + 2] = state.vel[2]; + } else if (pd->noise_influence == TEX_PD_NOISE_TIME) { + pd->point_data[i] = state.time; } } } @@ -256,7 +261,9 @@ typedef struct PointDensityRangeData float *point_data; float *vec; float softness; - short falloff_type; + short falloff_type; + short noise_influence; + float *time; } PointDensityRangeData; void accum_density(void *userdata, int index, float squared_dist) @@ -277,10 +284,14 @@ void accum_density(void *userdata, int index, float squared_dist) density = sqrt(dist); if (pdr->point_data) { - pdr->vec[0] += pdr->point_data[index*3 + 0];// * density; - pdr->vec[1] += pdr->point_data[index*3 + 1];// * density; - pdr->vec[2] += pdr->point_data[index*3 + 2];// * density; - } + if (pdr->noise_influence == TEX_PD_NOISE_VEL) { + pdr->vec[0] += pdr->point_data[index*3 + 0];// * density; + pdr->vec[1] += pdr->point_data[index*3 + 1];// * density; + pdr->vec[2] += pdr->point_data[index*3 + 2];// * density; + } else if (pdr->noise_influence == TEX_PD_NOISE_TIME) { + *pdr->time += pdr->point_data[index]; // * density; + } + } *pdr->density += density; } @@ -288,12 +299,13 @@ void accum_density(void *userdata, int index, float squared_dist) #define MAX_POINTS_NEAREST 25 int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) { - int rv = TEX_INT; + int retval = TEX_INT; PointDensity *pd = tex->pd; PointDensityRangeData pdr; - float density=0.0f; + float density=0.0f, time=0.0f; float vec[3] = {0.0, 0.0, 0.0}; float tv[3]; + float co[3]; float turb, noise_fac; if ((!pd) || (!pd->point_tree)) { @@ -306,54 +318,53 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) pdr.point_data = pd->point_data; pdr.falloff_type = pd->falloff_type; pdr.vec = vec; + pdr.time = &time; pdr.softness = pd->falloff_softness; + pdr.noise_influence = pd->noise_influence; noise_fac = pd->noise_fac * 0.5f; /* better default */ + VECCOPY(co, texvec); + if (pd->flag & TEX_PD_TURBULENCE) { - VECCOPY(tv, texvec); + retval |= TEX_RGB; - /* find the average speed vectors, for perturbing final density lookup with */ - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr); + if (ELEM(pd->noise_influence, TEX_PD_NOISE_VEL, TEX_PD_NOISE_TIME)) { + /* find the average speed vectors or particle time, + * for perturbing final density lookup with */ + BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr); + density = 0.0f; + + if (pd->noise_influence == TEX_PD_NOISE_TIME) + vec[0] = vec[1] = vec[2] = time; + + Normalize(vec); + } - density = 0.0f; - Normalize(vec); - turb = BLI_turbulence(pd->noise_size, texvec[0]+vec[0], texvec[1]+vec[1], texvec[2]+vec[2], pd->noise_depth); - turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */ - tv[0] = texvec[0] + noise_fac * turb; - tv[1] = texvec[1] + noise_fac * turb; - tv[2] = texvec[2] + noise_fac * turb; - - /* do density lookup with altered coordinates */ - BLI_bvhtree_range_query(pd->point_tree, tv, pd->radius, accum_density, &pdr); + /* now we have an offset coordinate to use for the density lookup */ + co[0] = texvec[0] + noise_fac * turb; + co[1] = texvec[1] + noise_fac * turb; + co[2] = texvec[2] + noise_fac * turb; } - else - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr); + + BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr); texres->tin = density; - - - BRICONT; - return TEX_INT; - - /* texres->tr = vec[0]; texres->tg = vec[1]; texres->tb = vec[2]; + texres->ta = density; BRICONTRGB; - texres->ta = 1.0; + return retval; + /* if (texres->nor!=NULL) { texres->nor[0] = texres->nor[1] = texres->nor[2] = 0.0f; } */ - - //BRICONT; - - //return rv; } diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c index dfeb775aca6..972ab4b55a9 100644 --- a/source/blender/render/intern/source/texture.c +++ b/source/blender/render/intern/source/texture.c @@ -1565,17 +1565,15 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa /* stencil maps on the texture control slider, not texture intensity value */ colfac= mtex->colfac*stencilTin; - tcol[0]=texres.tr; tcol[1]=texres.tg; tcol[2]=texres.tb; - if((rgbnor & TEX_RGB)==0) { tcol[0]= mtex->r; tcol[1]= mtex->g; tcol[2]= mtex->b; + } else { + tcol[0]=texres.tr; + tcol[1]=texres.tg; + tcol[2]=texres.tb; } - else if(mtex->mapto & MAP_ALPHA) { - texres.tin= stencilTin; - } - else texres.tin= texres.ta; if((mapto_flag & MAP_COL) && (mtex->mapto & MAP_COL)) { texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype); @@ -1591,7 +1589,8 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa /* stencil maps on the texture control slider, not texture intensity value */ float varfac= mtex->varfac*stencilTin; - if(rgbnor & TEX_RGB) { + /* convert RGB to intensity if intensity info isn't provided */ + if((rgbnor & TEX_RGB) && !(rgbnor & TEX_INT)) { if(texres.talpha) texres.tin= texres.ta; else texres.tin= (0.35*texres.tr+0.45*texres.tg+0.2*texres.tb); } diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index 04fc9d5314f..dbe3db871b4 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -788,7 +788,7 @@ static void texture_panel_pointdensity(Tex *tex) yco -= YSPACE; if (pd->source == TEX_PD_PSYS) { - uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1", + uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1|Time %x2", X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence"); } } |