2015-03-28 23:50:36 +05:00
|
|
|
/*
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributors: Matt Ebb
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 19:31:27 +00:00
|
|
|
/** \file blender/render/intern/source/pointdensity.c
|
|
|
|
|
* \ingroup render
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-10-02 01:38:12 +00:00
|
|
|
#include <math.h>
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2008-10-02 01:38:12 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2012-10-12 00:18:32 +00:00
|
|
|
#include "BLI_noise.h"
|
2008-10-01 03:35:53 +00:00
|
|
|
#include "BLI_kdopbvh.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2016-02-23 12:19:56 +01:00
|
|
|
#include "BLI_task.h"
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-10 16:55:01 +00:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
|
|
2017-12-07 15:36:26 +11:00
|
|
|
#include "BKE_colorband.h"
|
2016-03-24 11:41:44 +01:00
|
|
|
#include "BKE_deform.h"
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2008-10-31 05:29:54 +00:00
|
|
|
#include "BKE_lattice.h"
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
#include "BKE_main.h"
|
2015-07-18 21:42:39 +02:00
|
|
|
#include "BKE_object.h"
|
Point Density texture
The Point Density texture now has some additional options for how
the point locations are cached. Previously it was all relative to
worldspace, but there are now some other options that make things
a lot more convenient for mapping the texture to Local (or Orco).
Thanks to theeth for helping with the space conversions!
The new Object space options allow this sort of thing to be possible
- a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov
It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.
The new particle cache options are:
* Emit Object space
This caches the particles relative to the emitter object's
coordinate space (i.e. relative to the emitter's object center).
This makes it possible to map the Texture to Local or Orco
easily, so you can easily move, rotate or scale the rendering
object that has the Point Density texture. It's relative to the
emitter's location, rotation and scale, so if the object you're
rendering the texture on is aligned differently to the emitter,
the results will be rotated etc.
* Emit Object Location
This offsets the particles to the emitter object's location in 3D
space. It's similar to Emit Object Space, however the emitter
object's rotation and scale are ignored. This is probably the
easiest to use, since you don't need to worry about the rotation
and scale of the emitter object (just the rendered object), so
it's the default.
* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
2008-09-29 04:19:24 +00:00
|
|
|
#include "BKE_particle.h"
|
2010-06-27 05:39:55 +00:00
|
|
|
#include "BKE_scene.h"
|
2011-05-01 03:57:53 +00:00
|
|
|
#include "BKE_colortools.h"
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
#include "render_types.h"
|
|
|
|
|
#include "texture.h"
|
2011-02-14 18:20:10 +00:00
|
|
|
#include "pointdensity.h"
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
#include "RE_render_ext.h"
|
|
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
|
|
|
/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
|
|
|
|
|
/* only to be used here in this file, it's for speed */
|
|
|
|
|
extern struct Render R;
|
|
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
static ThreadMutex sample_mutex = PTHREAD_MUTEX_INITIALIZER;
|
2008-11-09 01:16:12 +00:00
|
|
|
|
|
|
|
|
static int point_data_used(PointDensity *pd)
|
|
|
|
|
{
|
|
|
|
|
int pd_bitflag = 0;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2011-03-16 18:21:31 +00:00
|
|
|
if (pd->source == TEX_PD_PSYS) {
|
2015-03-28 23:50:36 +05:00
|
|
|
if ((pd->noise_influence == TEX_PD_NOISE_VEL) ||
|
|
|
|
|
(pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_VEL) ||
|
|
|
|
|
(pd->color_source == TEX_PD_COLOR_PARTVEL) ||
|
|
|
|
|
(pd->color_source == TEX_PD_COLOR_PARTSPEED))
|
|
|
|
|
{
|
2011-03-16 18:21:31 +00:00
|
|
|
pd_bitflag |= POINT_DATA_VEL;
|
2015-03-28 23:50:36 +05:00
|
|
|
}
|
|
|
|
|
if ((pd->noise_influence == TEX_PD_NOISE_AGE) ||
|
|
|
|
|
(pd->color_source == TEX_PD_COLOR_PARTAGE) ||
|
|
|
|
|
(pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_AGE))
|
|
|
|
|
{
|
2011-03-16 18:21:31 +00:00
|
|
|
pd_bitflag |= POINT_DATA_LIFE;
|
2015-03-28 23:50:36 +05:00
|
|
|
}
|
2011-03-16 18:21:31 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
else if (pd->source == TEX_PD_OBJECT) {
|
|
|
|
|
if (ELEM(pd->ob_color_source, TEX_PD_COLOR_VERTCOL, TEX_PD_COLOR_VERTWEIGHT, TEX_PD_COLOR_VERTNOR)) {
|
|
|
|
|
pd_bitflag |= POINT_DATA_COLOR;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
return pd_bitflag;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
static void point_data_pointers(PointDensity *pd,
|
|
|
|
|
float **r_data_velocity, float **r_data_life, float **r_data_color)
|
|
|
|
|
{
|
|
|
|
|
const int data_used = point_data_used(pd);
|
|
|
|
|
const int totpoint = pd->totpoints;
|
|
|
|
|
float *data = pd->point_data;
|
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
|
|
if (data_used & POINT_DATA_VEL) {
|
|
|
|
|
if (r_data_velocity)
|
|
|
|
|
*r_data_velocity = data + offset;
|
|
|
|
|
offset += 3 * totpoint;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (r_data_velocity)
|
|
|
|
|
*r_data_velocity = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data_used & POINT_DATA_LIFE) {
|
|
|
|
|
if (r_data_life)
|
|
|
|
|
*r_data_life = data + offset;
|
|
|
|
|
offset += totpoint;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (r_data_life)
|
|
|
|
|
*r_data_life = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data_used & POINT_DATA_COLOR) {
|
|
|
|
|
if (r_data_color)
|
|
|
|
|
*r_data_color = data + offset;
|
|
|
|
|
offset += 3 * totpoint;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (r_data_color)
|
|
|
|
|
*r_data_color = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
/* additional data stored alongside the point density BVH,
|
|
|
|
|
* accessible by point index number to retrieve other information
|
2008-11-09 01:16:12 +00:00
|
|
|
* such as particle velocity or lifetime */
|
2016-03-24 11:41:44 +01:00
|
|
|
static void alloc_point_data(PointDensity *pd)
|
2008-11-09 01:16:12 +00:00
|
|
|
{
|
2016-03-24 11:41:44 +01:00
|
|
|
const int totpoints = pd->totpoints;
|
|
|
|
|
int data_used = point_data_used(pd);
|
2008-11-09 01:16:12 +00:00
|
|
|
int data_size = 0;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
if (data_used & POINT_DATA_VEL) {
|
2008-11-09 01:16:12 +00:00
|
|
|
/* store 3 channels of velocity data */
|
|
|
|
|
data_size += 3;
|
|
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (data_used & POINT_DATA_LIFE) {
|
2008-11-09 01:16:12 +00:00
|
|
|
/* store 1 channel of lifetime data */
|
|
|
|
|
data_size += 1;
|
|
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (data_used & POINT_DATA_COLOR) {
|
|
|
|
|
/* store 3 channels of RGB data */
|
|
|
|
|
data_size += 3;
|
|
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
if (data_size) {
|
2016-03-24 11:41:44 +01:00
|
|
|
pd->point_data = MEM_callocN(sizeof(float) * data_size * totpoints,
|
2015-03-28 23:50:36 +05:00
|
|
|
"particle point data");
|
|
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:55:02 -03:00
|
|
|
static void pointdensity_cache_psys(const EvaluationContext *eval_ctx, Scene *scene,
|
2015-03-29 02:34:44 +05:00
|
|
|
PointDensity *pd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
ParticleSystem *psys,
|
|
|
|
|
float viewmat[4][4],
|
|
|
|
|
float winmat[4][4],
|
2015-10-08 12:09:28 +05:00
|
|
|
int winx, int winy,
|
|
|
|
|
const bool use_render_params)
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
{
|
2015-03-28 23:50:36 +05:00
|
|
|
DerivedMesh *dm;
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
ParticleKey state;
|
2013-08-08 15:36:03 +00:00
|
|
|
ParticleCacheKey *cache;
|
2015-03-28 23:50:36 +05:00
|
|
|
ParticleSimulationData sim = {NULL};
|
|
|
|
|
ParticleData *pa = NULL;
|
2015-03-29 02:34:44 +05:00
|
|
|
float cfra = BKE_scene_frame_get(scene);
|
2011-09-20 08:48:48 +00:00
|
|
|
int i /*, childexists*/ /* UNUSED */;
|
2016-03-24 11:41:44 +01:00
|
|
|
int total_particles;
|
|
|
|
|
int data_used;
|
|
|
|
|
float *data_vel, *data_life;
|
Point Density texture
The Point Density texture now has some additional options for how
the point locations are cached. Previously it was all relative to
worldspace, but there are now some other options that make things
a lot more convenient for mapping the texture to Local (or Orco).
Thanks to theeth for helping with the space conversions!
The new Object space options allow this sort of thing to be possible
- a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov
It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.
The new particle cache options are:
* Emit Object space
This caches the particles relative to the emitter object's
coordinate space (i.e. relative to the emitter's object center).
This makes it possible to map the Texture to Local or Orco
easily, so you can easily move, rotate or scale the rendering
object that has the Point Density texture. It's relative to the
emitter's location, rotation and scale, so if the object you're
rendering the texture on is aligned differently to the emitter,
the results will be rotated etc.
* Emit Object Location
This offsets the particles to the emitter object's location in 3D
space. It's similar to Emit Object Space, however the emitter
object's rotation and scale are ignored. This is probably the
easiest to use, since you don't need to worry about the rotation
and scale of the emitter object (just the rendered object), so
it's the default.
* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
2008-09-29 04:19:24 +00:00
|
|
|
float partco[3];
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-10-31 05:29:54 +00:00
|
|
|
/* init everything */
|
2015-03-28 23:50:36 +05:00
|
|
|
if (!psys || !ob || !pd) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-11-03 06:31:53 +00:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
data_used = point_data_used(pd);
|
|
|
|
|
|
2008-10-31 05:29:54 +00:00
|
|
|
/* Just to create a valid rendering context for particles */
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
|
|
|
|
psys_render_set(ob, psys, viewmat, winmat, winx, winy, 0);
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
2017-07-21 11:53:13 +02:00
|
|
|
dm = mesh_create_derived_render(eval_ctx, scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
ob,
|
|
|
|
|
CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-07-21 11:53:13 +02:00
|
|
|
dm = mesh_get_derived_final(eval_ctx, scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
ob,
|
|
|
|
|
CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-06-23 07:53:49 +10:00
|
|
|
if (!psys_check_enabled(ob, psys, use_render_params)) {
|
2016-01-07 20:10:57 +11:00
|
|
|
psys_render_restore(ob, psys);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
sim.eval_ctx = eval_ctx;
|
2015-03-29 02:34:44 +05:00
|
|
|
sim.scene = scene;
|
2015-03-28 23:50:36 +05:00
|
|
|
sim.ob = ob;
|
|
|
|
|
sim.psys = psys;
|
2015-07-18 22:36:09 +02:00
|
|
|
sim.psmd = psys_get_modifier(ob, psys);
|
2010-11-03 06:31:53 +00:00
|
|
|
|
Point Density texture
The Point Density texture now has some additional options for how
the point locations are cached. Previously it was all relative to
worldspace, but there are now some other options that make things
a lot more convenient for mapping the texture to Local (or Orco).
Thanks to theeth for helping with the space conversions!
The new Object space options allow this sort of thing to be possible
- a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov
It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.
The new particle cache options are:
* Emit Object space
This caches the particles relative to the emitter object's
coordinate space (i.e. relative to the emitter's object center).
This makes it possible to map the Texture to Local or Orco
easily, so you can easily move, rotate or scale the rendering
object that has the Point Density texture. It's relative to the
emitter's location, rotation and scale, so if the object you're
rendering the texture on is aligned differently to the emitter,
the results will be rotated etc.
* Emit Object Location
This offsets the particles to the emitter object's location in 3D
space. It's similar to Emit Object Space, however the emitter
object's rotation and scale are ignored. This is probably the
easiest to use, since you don't need to worry about the rotation
and scale of the emitter object (just the rendered object), so
it's the default.
* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
2008-09-29 04:19:24 +00:00
|
|
|
/* in case ob->imat isn't up-to-date */
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
|
|
|
|
total_particles = psys->totpart + psys->totchild;
|
2013-08-19 10:11:48 +00:00
|
|
|
psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-10-12 11:38:28 +00:00
|
|
|
pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6);
|
2008-11-09 01:16:12 +00:00
|
|
|
pd->totpoints = total_particles;
|
2016-03-24 11:41:44 +01:00
|
|
|
alloc_point_data(pd);
|
|
|
|
|
point_data_pointers(pd, &data_vel, &data_life, NULL);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2011-09-20 08:48:48 +00:00
|
|
|
#if 0 /* UNUSED */
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
|
|
|
|
|
childexists = 1;
|
2011-09-20 08:48:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
for (i = 0, pa = psys->particles; i < total_particles; i++, pa++) {
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
2013-08-08 15:36:03 +00:00
|
|
|
if (psys->part->type == PART_HAIR) {
|
|
|
|
|
/* hair particles */
|
|
|
|
|
if (i < psys->totpart && psys->pathcache)
|
|
|
|
|
cache = psys->pathcache[i];
|
|
|
|
|
else if (i >= psys->totpart && psys->childcache)
|
|
|
|
|
cache = psys->childcache[i - psys->totpart];
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
|
2015-01-13 17:24:20 +01:00
|
|
|
cache += cache->segments; /* use endpoint */
|
2013-08-08 15:36:03 +00:00
|
|
|
|
|
|
|
|
copy_v3_v3(state.co, cache->co);
|
|
|
|
|
zero_v3(state.vel);
|
|
|
|
|
state.time = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* emitter particles */
|
|
|
|
|
state.time = cfra;
|
|
|
|
|
|
|
|
|
|
if (!psys_get_particle_state(&sim, i, &state, 0))
|
|
|
|
|
continue;
|
|
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
if (data_used & POINT_DATA_LIFE) {
|
2008-11-10 00:14:35 +00:00
|
|
|
if (i < psys->totpart) {
|
2015-03-28 23:50:36 +05:00
|
|
|
state.time = (cfra - pa->time) / pa->lifetime;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-03-28 23:50:36 +05:00
|
|
|
ChildParticle *cpa = (psys->child + i) - psys->totpart;
|
2009-08-13 05:21:25 +00:00
|
|
|
float pa_birthtime, pa_dietime;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-08-08 15:36:03 +00:00
|
|
|
state.time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
|
2008-11-10 00:14:35 +00:00
|
|
|
}
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
}
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
2013-08-08 15:36:03 +00:00
|
|
|
|
|
|
|
|
copy_v3_v3(partco, state.co);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-08-08 15:36:03 +00:00
|
|
|
if (pd->psys_cache_space == TEX_PD_OBJECTSPACE)
|
|
|
|
|
mul_m4_v3(ob->imat, partco);
|
|
|
|
|
else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) {
|
|
|
|
|
sub_v3_v3(partco, ob->loc);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* TEX_PD_WORLDSPACE */
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-08-08 15:36:03 +00:00
|
|
|
BLI_bvhtree_insert(pd->point_tree, i, partco, 1);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
if (data_vel) {
|
|
|
|
|
data_vel[i*3 + 0] = state.vel[0];
|
|
|
|
|
data_vel[i*3 + 1] = state.vel[1];
|
|
|
|
|
data_vel[i*3 + 2] = state.vel[2];
|
2013-08-08 15:36:03 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (data_life) {
|
|
|
|
|
data_life[i] = state.time;
|
2013-08-08 15:36:03 +00:00
|
|
|
}
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-10-01 03:35:53 +00:00
|
|
|
BLI_bvhtree_balance(pd->point_tree);
|
2008-10-22 05:24:41 +00:00
|
|
|
dm->release(dm);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
if (psys->lattice_deform_data) {
|
|
|
|
|
end_latt_deform(psys->lattice_deform_data);
|
|
|
|
|
psys->lattice_deform_data = NULL;
|
2008-10-22 05:24:41 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
2016-01-07 20:10:57 +11:00
|
|
|
psys_render_restore(ob, psys);
|
2015-10-08 12:09:28 +05:00
|
|
|
}
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob), DerivedMesh *dm, float *data_color)
|
|
|
|
|
{
|
|
|
|
|
const MLoop *mloop = dm->getLoopArray(dm);
|
|
|
|
|
const int totloop = dm->getNumLoops(dm);
|
|
|
|
|
const MLoopCol *mcol;
|
|
|
|
|
char layername[MAX_CUSTOMDATA_LAYER_NAME];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BLI_assert(data_color);
|
|
|
|
|
|
|
|
|
|
if (!CustomData_has_layer(&dm->loopData, CD_MLOOPCOL))
|
|
|
|
|
return;
|
|
|
|
|
CustomData_validate_layer_name(&dm->loopData, CD_MLOOPCOL, pd->vertex_attribute_name, layername);
|
|
|
|
|
mcol = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, layername);
|
|
|
|
|
if (!mcol)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Stores the number of MLoops using the same vertex, so we can normalize colors. */
|
|
|
|
|
int *mcorners = MEM_callocN(sizeof(int) * pd->totpoints, "point density corner count");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < totloop; i++) {
|
|
|
|
|
int v = mloop[i].v;
|
2016-10-09 13:16:19 +02:00
|
|
|
|
|
|
|
|
if (mcorners[v] == 0) {
|
|
|
|
|
rgb_uchar_to_float(&data_color[v * 3], &mcol[i].r);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float col[3];
|
|
|
|
|
rgb_uchar_to_float(col, &mcol[i].r);
|
|
|
|
|
add_v3_v3(&data_color[v * 3], col);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
++mcorners[v];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Normalize colors by averaging over mcorners.
|
|
|
|
|
* All the corners share the same vertex, ie. occupy the same point in space.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < pd->totpoints; i++) {
|
|
|
|
|
if (mcorners[i] > 0)
|
|
|
|
|
mul_v3_fl(&data_color[i*3], 1.0f / mcorners[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(mcorners);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, DerivedMesh *dm, float *data_color)
|
|
|
|
|
{
|
|
|
|
|
const int totvert = dm->getNumVerts(dm);
|
|
|
|
|
const MDeformVert *mdef, *dv;
|
|
|
|
|
int mdef_index;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BLI_assert(data_color);
|
|
|
|
|
|
|
|
|
|
mdef = CustomData_get_layer(&dm->vertData, CD_MDEFORMVERT);
|
|
|
|
|
if (!mdef)
|
|
|
|
|
return;
|
|
|
|
|
mdef_index = defgroup_name_index(ob, pd->vertex_attribute_name);
|
|
|
|
|
if (mdef_index < 0)
|
|
|
|
|
mdef_index = ob->actdef - 1;
|
|
|
|
|
if (mdef_index < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0, dv = mdef; i < totvert; ++i, ++dv, data_color += 3) {
|
|
|
|
|
MDeformWeight *dw;
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
|
|
for (j = 0, dw = dv->dw; j < dv->totweight; ++j, ++dw) {
|
|
|
|
|
if (dw->def_nr == mdef_index) {
|
|
|
|
|
copy_v3_fl(data_color, dw->weight);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob), DerivedMesh *dm, float *data_color)
|
|
|
|
|
{
|
|
|
|
|
MVert *mvert = dm->getVertArray(dm), *mv;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BLI_assert(data_color);
|
|
|
|
|
|
|
|
|
|
for (i = 0, mv = mvert; i < pd->totpoints; i++, mv++, data_color += 3) {
|
|
|
|
|
normal_short_to_float_v3(data_color, mv->no);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:55:02 -03:00
|
|
|
static void pointdensity_cache_object(const EvaluationContext *eval_ctx, Scene *scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
PointDensity *pd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
const bool use_render_params)
|
2008-09-29 07:56:41 +00:00
|
|
|
{
|
2016-03-24 11:41:44 +01:00
|
|
|
float *data_color;
|
2008-09-29 07:56:41 +00:00
|
|
|
int i;
|
2009-11-03 06:04:42 +00:00
|
|
|
DerivedMesh *dm;
|
2016-03-24 11:41:44 +01:00
|
|
|
CustomDataMask mask = CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL;
|
|
|
|
|
MVert *mvert = NULL, *mv;
|
|
|
|
|
|
|
|
|
|
switch (pd->ob_color_source) {
|
|
|
|
|
case TEX_PD_COLOR_VERTCOL:
|
|
|
|
|
mask |= CD_MASK_MLOOPCOL;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_VERTWEIGHT:
|
|
|
|
|
mask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
2017-07-21 11:53:13 +02:00
|
|
|
dm = mesh_create_derived_render(eval_ctx, scene, ob, mask);
|
2015-10-08 12:09:28 +05:00
|
|
|
}
|
|
|
|
|
else {
|
2017-07-21 11:53:13 +02:00
|
|
|
dm = mesh_get_derived_final(eval_ctx, scene, ob, mask);
|
2015-10-08 12:09:28 +05:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
mvert = dm->getVertArray(dm); /* local object space */
|
2015-03-28 23:50:36 +05:00
|
|
|
pd->totpoints = dm->getNumVerts(dm);
|
|
|
|
|
if (pd->totpoints == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-11-03 06:04:42 +00:00
|
|
|
|
|
|
|
|
pd->point_tree = BLI_bvhtree_new(pd->totpoints, 0.0, 4, 6);
|
2016-03-24 11:41:44 +01:00
|
|
|
alloc_point_data(pd);
|
|
|
|
|
point_data_pointers(pd, NULL, NULL, &data_color);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
for (i = 0, mv = mvert; i < pd->totpoints; i++, mv++) {
|
2009-11-03 06:04:42 +00:00
|
|
|
float co[3];
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
copy_v3_v3(co, mv->co);
|
2009-11-03 06:04:42 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (pd->ob_cache_space) {
|
2009-11-03 06:04:42 +00:00
|
|
|
case TEX_PD_OBJECTSPACE:
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_OBJECTLOC:
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(ob->obmat, co);
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(co, ob->loc);
|
2009-11-03 06:04:42 +00:00
|
|
|
break;
|
|
|
|
|
case TEX_PD_WORLDSPACE:
|
|
|
|
|
default:
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(ob->obmat, co);
|
2009-11-03 06:04:42 +00:00
|
|
|
break;
|
2008-09-29 07:56:41 +00:00
|
|
|
}
|
2009-11-03 06:04:42 +00:00
|
|
|
|
|
|
|
|
BLI_bvhtree_insert(pd->point_tree, i, co, 1);
|
2008-09-29 07:56:41 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
|
|
|
|
|
switch (pd->ob_color_source) {
|
|
|
|
|
case TEX_PD_COLOR_VERTCOL:
|
|
|
|
|
pointdensity_cache_vertex_color(pd, ob, dm, data_color);
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_VERTWEIGHT:
|
|
|
|
|
pointdensity_cache_vertex_weight(pd, ob, dm, data_color);
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_VERTNOR:
|
|
|
|
|
pointdensity_cache_vertex_normal(pd, ob, dm, data_color);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-10-01 03:35:53 +00:00
|
|
|
BLI_bvhtree_balance(pd->point_tree);
|
2009-11-03 06:04:42 +00:00
|
|
|
dm->release(dm);
|
2008-09-29 07:56:41 +00:00
|
|
|
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2018-02-20 12:55:02 -03:00
|
|
|
static void cache_pointdensity_ex(const EvaluationContext *eval_ctx,
|
|
|
|
|
Scene *scene,
|
2015-03-29 02:34:44 +05:00
|
|
|
PointDensity *pd,
|
|
|
|
|
float viewmat[4][4],
|
|
|
|
|
float winmat[4][4],
|
2015-10-08 12:09:28 +05:00
|
|
|
int winx, int winy,
|
|
|
|
|
const bool use_render_params)
|
2015-03-29 02:14:06 +05:00
|
|
|
{
|
|
|
|
|
if (pd == NULL) {
|
2010-07-26 05:31:31 +00:00
|
|
|
return;
|
2015-03-29 02:14:06 +05:00
|
|
|
}
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
|
|
|
|
if (pd->point_tree) {
|
2008-10-01 03:35:53 +00:00
|
|
|
BLI_bvhtree_free(pd->point_tree);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
pd->point_tree = NULL;
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
Point Density texture
The Point Density texture now has some additional options for how
the point locations are cached. Previously it was all relative to
worldspace, but there are now some other options that make things
a lot more convenient for mapping the texture to Local (or Orco).
Thanks to theeth for helping with the space conversions!
The new Object space options allow this sort of thing to be possible
- a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov
It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.
The new particle cache options are:
* Emit Object space
This caches the particles relative to the emitter object's
coordinate space (i.e. relative to the emitter's object center).
This makes it possible to map the Texture to Local or Orco
easily, so you can easily move, rotate or scale the rendering
object that has the Point Density texture. It's relative to the
emitter's location, rotation and scale, so if the object you're
rendering the texture on is aligned differently to the emitter,
the results will be rotated etc.
* Emit Object Location
This offsets the particles to the emitter object's location in 3D
space. It's similar to Emit Object Space, however the emitter
object's rotation and scale are ignored. This is probably the
easiest to use, since you don't need to worry about the rotation
and scale of the emitter object (just the rendered object), so
it's the default.
* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
2008-09-29 04:19:24 +00:00
|
|
|
if (pd->source == TEX_PD_PSYS) {
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
Object *ob = pd->object;
|
2009-11-04 08:44:42 +00:00
|
|
|
ParticleSystem *psys;
|
2009-08-20 08:18:54 +00:00
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
if (!ob || !pd->psys) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
psys = BLI_findlink(&ob->particlesystem, pd->psys - 1);
|
|
|
|
|
if (!psys) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-11-04 08:44:42 +00:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
pointdensity_cache_psys(eval_ctx,
|
|
|
|
|
scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
pd,
|
|
|
|
|
ob,
|
|
|
|
|
psys,
|
|
|
|
|
viewmat, winmat,
|
|
|
|
|
winx, winy,
|
|
|
|
|
use_render_params);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
2008-09-29 07:56:41 +00:00
|
|
|
else if (pd->source == TEX_PD_OBJECT) {
|
|
|
|
|
Object *ob = pd->object;
|
2010-09-20 02:53:39 +00:00
|
|
|
if (ob && ob->type == OB_MESH)
|
2017-07-21 11:53:13 +02:00
|
|
|
pointdensity_cache_object(eval_ctx, scene, pd, ob, use_render_params);
|
2008-09-29 07:56:41 +00:00
|
|
|
}
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:55:02 -03:00
|
|
|
void cache_pointdensity(const EvaluationContext *eval_ctx, Render *re, PointDensity *pd)
|
2015-03-29 02:34:44 +05:00
|
|
|
{
|
2018-02-20 12:55:02 -03:00
|
|
|
cache_pointdensity_ex(eval_ctx,
|
2017-07-21 11:53:13 +02:00
|
|
|
re->scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
pd,
|
|
|
|
|
re->viewmat, re->winmat,
|
|
|
|
|
re->winx, re->winy,
|
|
|
|
|
true);
|
2015-03-29 02:34:44 +05:00
|
|
|
}
|
|
|
|
|
|
2015-03-29 02:14:06 +05:00
|
|
|
void free_pointdensity(PointDensity *pd)
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
{
|
2015-03-29 02:14:06 +05:00
|
|
|
if (pd == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
if (pd->point_tree) {
|
2008-10-01 03:35:53 +00:00
|
|
|
BLI_bvhtree_free(pd->point_tree);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
pd->point_tree = NULL;
|
|
|
|
|
}
|
2008-10-01 03:35:53 +00:00
|
|
|
|
|
|
|
|
if (pd->point_data) {
|
|
|
|
|
MEM_freeN(pd->point_data);
|
|
|
|
|
pd->point_data = NULL;
|
|
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
pd->totpoints = 0;
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:55:02 -03:00
|
|
|
void make_pointdensities(const EvaluationContext *eval_ctx, Render *re)
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
{
|
|
|
|
|
Tex *tex;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
|
|
|
|
if (re->scene->r.scemode & R_BUTS_PREVIEW) {
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
return;
|
2015-03-28 23:50:36 +05:00
|
|
|
}
|
|
|
|
|
|
2013-03-10 16:55:01 +00:00
|
|
|
re->i.infostr = IFACE_("Caching Point Densities");
|
2009-08-13 05:21:25 +00:00
|
|
|
re->stats_draw(re->sdh, &re->i);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
for (tex = re->main->tex.first; tex != NULL; tex = tex->id.next) {
|
|
|
|
|
if (tex->id.us && tex->type == TEX_POINTDENSITY) {
|
2018-02-20 12:55:02 -03:00
|
|
|
cache_pointdensity(eval_ctx, re, tex->pd);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-03-10 16:55:01 +00:00
|
|
|
re->i.infostr = NULL;
|
2009-08-13 05:21:25 +00:00
|
|
|
re->stats_draw(re->sdh, &re->i);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free_pointdensities(Render *re)
|
|
|
|
|
{
|
|
|
|
|
Tex *tex;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2013-05-15 17:09:45 +00:00
|
|
|
if (re->scene->r.scemode & R_BUTS_PREVIEW)
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
return;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
|
|
|
|
for (tex = re->main->tex.first; tex != NULL; tex = tex->id.next) {
|
|
|
|
|
if (tex->id.us && tex->type == TEX_POINTDENSITY) {
|
2015-03-29 02:14:06 +05:00
|
|
|
free_pointdensity(tex->pd);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 22:38:39 +00:00
|
|
|
typedef struct PointDensityRangeData {
|
2010-03-22 09:30:00 +00:00
|
|
|
float *density;
|
|
|
|
|
float squared_radius;
|
2016-03-24 11:41:44 +01:00
|
|
|
float *point_data_life;
|
|
|
|
|
float *point_data_velocity;
|
|
|
|
|
float *point_data_color;
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
float *vec;
|
2016-03-24 11:41:44 +01:00
|
|
|
float *col;
|
2008-10-22 01:31:46 +00:00
|
|
|
float softness;
|
2010-03-22 09:30:00 +00:00
|
|
|
short falloff_type;
|
2008-10-31 05:29:54 +00:00
|
|
|
short noise_influence;
|
2008-11-09 01:16:12 +00:00
|
|
|
float *age;
|
2011-05-01 03:57:53 +00:00
|
|
|
struct CurveMapping *density_curve;
|
|
|
|
|
float velscale;
|
2008-10-02 01:38:12 +00:00
|
|
|
} PointDensityRangeData;
|
2008-10-01 07:13:28 +00:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
static float density_falloff(PointDensityRangeData *pdr, int index, float squared_dist)
|
|
|
|
|
{
|
|
|
|
|
const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f;
|
|
|
|
|
float density = 0.0f;
|
|
|
|
|
|
|
|
|
|
switch (pdr->falloff_type) {
|
|
|
|
|
case TEX_PD_FALLOFF_STD:
|
|
|
|
|
density = dist;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_SMOOTH:
|
|
|
|
|
density = 3.0f * dist * dist - 2.0f * dist * dist * dist;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_SOFT:
|
|
|
|
|
density = pow(dist, pdr->softness);
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_CONSTANT:
|
|
|
|
|
density = pdr->squared_radius;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_ROOT:
|
|
|
|
|
density = sqrtf(dist);
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_PARTICLE_AGE:
|
|
|
|
|
if (pdr->point_data_life)
|
|
|
|
|
density = dist * MIN2(pdr->point_data_life[index], 1.0f);
|
|
|
|
|
else
|
|
|
|
|
density = dist;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_FALLOFF_PARTICLE_VEL:
|
|
|
|
|
if (pdr->point_data_velocity)
|
|
|
|
|
density = dist * len_v3(&pdr->point_data_velocity[index * 3]) * pdr->velscale;
|
|
|
|
|
else
|
|
|
|
|
density = dist;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pdr->density_curve && dist != 0.0f) {
|
|
|
|
|
curvemapping_initialize(pdr->density_curve);
|
|
|
|
|
density = curvemapping_evaluateF(pdr->density_curve, 0, density / dist) * dist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return density;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 17:16:50 +11:00
|
|
|
static void accum_density(void *userdata, int index, const float co[3], float squared_dist)
|
2008-10-01 07:13:28 +00:00
|
|
|
{
|
2008-10-02 01:38:12 +00:00
|
|
|
PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
|
2009-08-26 00:38:43 +00:00
|
|
|
float density = 0.0f;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-19 17:16:50 +11:00
|
|
|
UNUSED_VARS(co);
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
if (pdr->point_data_velocity) {
|
|
|
|
|
pdr->vec[0] += pdr->point_data_velocity[index * 3 + 0]; // * density;
|
|
|
|
|
pdr->vec[1] += pdr->point_data_velocity[index * 3 + 1]; // * density;
|
|
|
|
|
pdr->vec[2] += pdr->point_data_velocity[index * 3 + 2]; // * density;
|
2011-06-02 16:59:12 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (pdr->point_data_life) {
|
|
|
|
|
*pdr->age += pdr->point_data_life[index]; // * density;
|
2011-06-02 16:59:12 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (pdr->point_data_color) {
|
|
|
|
|
add_v3_v3(pdr->col, &pdr->point_data_color[index * 3]); // * density;
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
density = density_falloff(pdr, index, squared_dist);
|
|
|
|
|
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
*pdr->density += density;
|
2008-10-01 07:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
|
2015-03-28 23:50:36 +05:00
|
|
|
static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *pdr,
|
2016-03-24 11:41:44 +01:00
|
|
|
float *density, float *vec, float *age, float *col, struct CurveMapping *density_curve, float velscale)
|
2008-11-09 01:16:12 +00:00
|
|
|
{
|
2015-03-28 23:50:36 +05:00
|
|
|
pdr->squared_radius = pd->radius * pd->radius;
|
2008-11-09 01:16:12 +00:00
|
|
|
pdr->density = density;
|
|
|
|
|
pdr->falloff_type = pd->falloff_type;
|
|
|
|
|
pdr->vec = vec;
|
|
|
|
|
pdr->age = age;
|
2016-03-24 11:41:44 +01:00
|
|
|
pdr->col = col;
|
2008-11-09 01:16:12 +00:00
|
|
|
pdr->softness = pd->falloff_softness;
|
|
|
|
|
pdr->noise_influence = pd->noise_influence;
|
2016-03-24 11:41:44 +01:00
|
|
|
point_data_pointers(pd, &pdr->point_data_velocity, &pdr->point_data_life, &pdr->point_data_color);
|
2011-05-01 03:57:53 +00:00
|
|
|
pdr->density_curve = density_curve;
|
|
|
|
|
pdr->velscale = velscale;
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
static int pointdensity(PointDensity *pd,
|
|
|
|
|
const float texvec[3],
|
|
|
|
|
TexResult *texres,
|
2016-03-24 11:41:44 +01:00
|
|
|
float r_vec[3],
|
2015-07-18 21:42:39 +02:00
|
|
|
float *r_age,
|
2016-03-24 11:41:44 +01:00
|
|
|
float r_col[3])
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
{
|
2009-03-17 05:33:05 +00:00
|
|
|
int retval = TEX_INT;
|
2008-10-02 01:38:12 +00:00
|
|
|
PointDensityRangeData pdr;
|
2015-03-28 23:50:36 +05:00
|
|
|
float density = 0.0f, age = 0.0f, time = 0.0f;
|
2016-03-24 11:41:44 +01:00
|
|
|
float vec[3] = {0.0f, 0.0f, 0.0f}, col[3] = {0.0f, 0.0f, 0.0f}, co[3];
|
2008-10-12 23:39:52 +00:00
|
|
|
float turb, noise_fac;
|
2015-03-28 23:50:36 +05:00
|
|
|
int num = 0;
|
|
|
|
|
|
2009-03-17 05:33:05 +00:00
|
|
|
texres->tin = 0.0f;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
if ((!pd) || (!pd->point_tree))
|
2009-03-17 05:33:05 +00:00
|
|
|
return 0;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
init_pointdensityrangedata(pd, &pdr, &density, vec, &age, col,
|
2015-03-28 23:50:36 +05:00
|
|
|
(pd->flag & TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL),
|
|
|
|
|
pd->falloff_speed_scale * 0.001f);
|
2008-10-12 23:39:52 +00:00
|
|
|
noise_fac = pd->noise_fac * 0.5f; /* better default */
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2011-11-07 01:38:32 +00:00
|
|
|
copy_v3_v3(co, texvec);
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
if (point_data_used(pd)) {
|
|
|
|
|
/* does a BVH lookup to find accumulated density and additional point data *
|
|
|
|
|
* stores particle velocity vector in 'vec', and particle lifetime in 'time' */
|
|
|
|
|
num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
|
|
|
|
|
if (num > 0) {
|
|
|
|
|
age /= num;
|
2015-03-28 23:50:36 +05:00
|
|
|
mul_v3_fl(vec, 1.0f / num);
|
2016-03-24 11:41:44 +01:00
|
|
|
mul_v3_fl(col, 1.0f / num);
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2009-03-17 05:33:05 +00:00
|
|
|
/* reset */
|
2016-03-24 11:41:44 +01:00
|
|
|
density = 0.0f;
|
|
|
|
|
zero_v3(vec);
|
|
|
|
|
zero_v3(col);
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
if (pd->flag & TEX_PD_TURBULENCE) {
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-11-09 01:16:12 +00:00
|
|
|
if (pd->noise_influence == TEX_PD_NOISE_AGE) {
|
2015-03-28 23:50:36 +05:00
|
|
|
turb = BLI_gTurbulence(pd->noise_size, texvec[0] + age, texvec[1] + age, texvec[2] + age,
|
|
|
|
|
pd->noise_depth, 0, pd->noise_basis);
|
2008-10-31 05:29:54 +00:00
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
else if (pd->noise_influence == TEX_PD_NOISE_TIME) {
|
2012-12-17 20:37:10 +00:00
|
|
|
time = R.r.cfra / (float)R.r.efra;
|
2015-03-28 23:50:36 +05:00
|
|
|
turb = BLI_gTurbulence(pd->noise_size, texvec[0] + time, texvec[1] + time, texvec[2] + time,
|
|
|
|
|
pd->noise_depth, 0, pd->noise_basis);
|
2008-12-05 04:06:41 +00:00
|
|
|
//turb = BLI_turbulence(pd->noise_size, texvec[0]+time, texvec[1]+time, texvec[2]+time, pd->noise_depth);
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-03-28 23:50:36 +05:00
|
|
|
turb = BLI_gTurbulence(pd->noise_size, texvec[0] + vec[0], texvec[1] + vec[1], texvec[2] + vec[2],
|
|
|
|
|
pd->noise_depth, 0, pd->noise_basis);
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2008-10-31 05:29:54 +00:00
|
|
|
/* 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;
|
2008-11-19 05:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-17 05:33:05 +00:00
|
|
|
/* BVH query with the potentially perturbed coordinates */
|
2008-11-19 05:30:52 +00:00
|
|
|
num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
|
|
|
|
|
if (num > 0) {
|
|
|
|
|
age /= num;
|
2015-03-28 23:50:36 +05:00
|
|
|
mul_v3_fl(vec, 1.0f / num);
|
2016-03-24 11:41:44 +01:00
|
|
|
mul_v3_fl(col, 1.0f / num);
|
* New point density update: Turbulence
This addition allows you to perturb the point density with noise, to give
the impression of more resolution. It's a quick way to add detail, without
having to use large, complex, and slower to render particle systems.
Rather than just overlaying noise, like you might do by adding a secondary
clouds texture, it uses noise to perturb the actual coordinate looked up
in the density evaluation. This gives a much better looking result, as it
actually alters the original density.
Comparison of the particle cloud render without, and with added turbulence
(the render with turbulence only renders slightly more slowly):
http://mke3.net/blender/devel/rendering/volumetrics/pd_turbulence.jpg
Using the same constant noise function/spatial coordinates will give a
static appearance. This is fine (and quicker) if the particles aren't
moving, but on animated particle systems, it looks bad, as if the
particles are moving through a static noise field. To overcome this, there
are additional options for particle systems, to influence the turbulence
with the particles' average velocity, or average angular velocity. This
information is only available for particle systems at the present.
Here you can see the (dramatic) difference between no turbulence, static
turbulence, and turbulence influenced by particle velocity:
http://mke3.net/blender/devel/rendering/volumetrics/turbu_compare.mov
2008-10-06 12:25:22 +00:00
|
|
|
}
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2015-07-18 22:36:09 +02:00
|
|
|
texres->tin = density;
|
2015-07-18 21:42:39 +02:00
|
|
|
if (r_age != NULL) {
|
|
|
|
|
*r_age = age;
|
|
|
|
|
}
|
|
|
|
|
if (r_vec != NULL) {
|
|
|
|
|
copy_v3_v3(r_vec, vec);
|
|
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
if (r_col != NULL) {
|
|
|
|
|
copy_v3_v3(r_col, col);
|
|
|
|
|
}
|
2015-07-18 21:42:39 +02:00
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, const float vec[3], const float col[3])
|
2015-07-18 21:42:39 +02:00
|
|
|
{
|
2016-03-24 11:41:44 +01:00
|
|
|
int retval = TEX_RGB;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
if (pd->source == TEX_PD_PSYS) {
|
|
|
|
|
float rgba[4];
|
|
|
|
|
|
|
|
|
|
switch (pd->color_source) {
|
|
|
|
|
case TEX_PD_COLOR_PARTAGE:
|
|
|
|
|
if (pd->coba) {
|
2017-12-07 15:52:59 +11:00
|
|
|
if (BKE_colorband_evaluate(pd->coba, age, rgba)) {
|
2016-03-24 11:41:44 +01:00
|
|
|
texres->talpha = true;
|
|
|
|
|
copy_v3_v3(&texres->tr, rgba);
|
|
|
|
|
texres->tin *= rgba[3];
|
|
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
}
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_PARTSPEED:
|
|
|
|
|
{
|
|
|
|
|
float speed = len_v3(vec) * pd->speed_scale;
|
|
|
|
|
|
|
|
|
|
if (pd->coba) {
|
2017-12-07 15:52:59 +11:00
|
|
|
if (BKE_colorband_evaluate(pd->coba, speed, rgba)) {
|
2016-03-24 11:41:44 +01:00
|
|
|
texres->talpha = true;
|
|
|
|
|
copy_v3_v3(&texres->tr, rgba);
|
|
|
|
|
texres->tin *= rgba[3];
|
|
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
case TEX_PD_COLOR_PARTVEL:
|
|
|
|
|
texres->talpha = true;
|
|
|
|
|
mul_v3_v3fl(&texres->tr, vec, pd->speed_scale);
|
|
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_CONSTANT:
|
|
|
|
|
default:
|
|
|
|
|
texres->tr = texres->tg = texres->tb = texres->ta = 1.0f;
|
|
|
|
|
retval = TEX_INT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float rgba[4];
|
|
|
|
|
|
|
|
|
|
switch (pd->ob_color_source) {
|
|
|
|
|
case TEX_PD_COLOR_VERTCOL:
|
|
|
|
|
texres->talpha = true;
|
|
|
|
|
copy_v3_v3(&texres->tr, col);
|
|
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_VERTWEIGHT:
|
|
|
|
|
texres->talpha = true;
|
2017-12-07 15:52:59 +11:00
|
|
|
if (pd->coba && BKE_colorband_evaluate(pd->coba, col[0], rgba)) {
|
2016-03-24 11:41:44 +01:00
|
|
|
copy_v3_v3(&texres->tr, rgba);
|
|
|
|
|
texres->tin *= rgba[3];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-11-07 01:38:32 +00:00
|
|
|
copy_v3_v3(&texres->tr, col);
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
2016-03-24 11:41:44 +01:00
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_VERTNOR:
|
|
|
|
|
texres->talpha = true;
|
|
|
|
|
copy_v3_v3(&texres->tr, col);
|
|
|
|
|
texres->ta = texres->tin;
|
|
|
|
|
break;
|
|
|
|
|
case TEX_PD_COLOR_CONSTANT:
|
|
|
|
|
default:
|
|
|
|
|
texres->tr = texres->tg = texres->tb = texres->ta = 1.0f;
|
|
|
|
|
retval = TEX_INT;
|
|
|
|
|
break;
|
2008-11-09 01:16:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-18 22:36:09 +02:00
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pointdensitytex(Tex *tex, const float texvec[3], TexResult *texres)
|
|
|
|
|
{
|
|
|
|
|
PointDensity *pd = tex->pd;
|
|
|
|
|
float age = 0.0f;
|
|
|
|
|
float vec[3] = {0.0f, 0.0f, 0.0f};
|
2016-03-24 11:41:44 +01:00
|
|
|
float col[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
int retval = pointdensity(pd, texvec, texres, vec, &age, col);
|
2015-07-18 22:36:09 +02:00
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
retval |= pointdensity_color(pd, texres, age, vec, col);
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
BRICONTRGB;
|
2016-03-24 11:41:44 +01:00
|
|
|
|
2008-10-31 05:29:54 +00:00
|
|
|
return retval;
|
2015-03-28 23:50:36 +05:00
|
|
|
|
2012-03-09 18:28:30 +00:00
|
|
|
#if 0
|
* Volumetrics
Removed all the old particle rendering code and options I had in there
before, in order to make way for...
A new procedural texture: 'Point Density'
Point Density is a 3d texture that find the density of a group of 'points'
in space and returns that in the texture as an intensity value. Right now,
its at an early stage and it's only enabled for particles, but it would be
cool to extend it later for things like object vertices, or point cache
files from disk - i.e. to import point cloud data into Blender for
rendering volumetrically.
Currently there are just options for an Object and its particle system
number, this is the particle system that will get cached before rendering,
and then used for the texture's density estimation.
It works totally consistent with as any other procedural texture, so
previously where I've mapped a clouds texture to volume density to make
some of those test renders, now I just map a point density texture to
volume density.
Here's a version of the same particle smoke test file from before, updated
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend
There are a few cool things about implementing this as a texture:
- The one texture (and cache) can be instanced across many different
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png
This means you can calculate and bake one particle system, but render it
multiple times across the scene, with different material settings, at no
extra memory cost.
Right now, the particles are cached in world space, so you have to map it
globally, and if you want it offset, you have to do it in the material (as
in the file above). I plan to add an option to bake in local space, so you
can just map the texture to local and it just works.
- It also works for solid surfaces too, it just gets the density at that
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov
- You can map it to whatever you want, not only density but the various
emissions and colours as well. I'd like to investigate using the other
outputs in the texture too (like the RGB or normal outputs), perhaps with
options to colour by particle age, generating normals for making particle
'dents' in a surface, whatever!
2008-09-28 08:00:22 +00:00
|
|
|
if (texres->nor!=NULL) {
|
|
|
|
|
texres->nor[0] = texres->nor[1] = texres->nor[2] = 0.0f;
|
|
|
|
|
}
|
2012-03-09 18:28:30 +00:00
|
|
|
#endif
|
Point Density texture
The Point Density texture now has some additional options for how
the point locations are cached. Previously it was all relative to
worldspace, but there are now some other options that make things
a lot more convenient for mapping the texture to Local (or Orco).
Thanks to theeth for helping with the space conversions!
The new Object space options allow this sort of thing to be possible
- a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov
It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.
The new particle cache options are:
* Emit Object space
This caches the particles relative to the emitter object's
coordinate space (i.e. relative to the emitter's object center).
This makes it possible to map the Texture to Local or Orco
easily, so you can easily move, rotate or scale the rendering
object that has the Point Density texture. It's relative to the
emitter's location, rotation and scale, so if the object you're
rendering the texture on is aligned differently to the emitter,
the results will be rotated etc.
* Emit Object Location
This offsets the particles to the emitter object's location in 3D
space. It's similar to Emit Object Space, however the emitter
object's rotation and scale are ignored. This is probably the
easiest to use, since you don't need to worry about the rotation
and scale of the emitter object (just the rendered object), so
it's the default.
* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.
2008-09-29 04:19:24 +00:00
|
|
|
}
|
2015-07-18 21:42:39 +02:00
|
|
|
|
|
|
|
|
static void sample_dummy_point_density(int resolution, float *values)
|
|
|
|
|
{
|
|
|
|
|
memset(values, 0, sizeof(float) * 4 * resolution * resolution * resolution);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
static void particle_system_minmax(EvaluationContext *eval_ctx,
|
|
|
|
|
Scene *scene,
|
2015-09-28 20:10:01 +05:00
|
|
|
Object *object,
|
2015-07-18 21:42:39 +02:00
|
|
|
ParticleSystem *psys,
|
|
|
|
|
float radius,
|
2015-10-08 12:09:28 +05:00
|
|
|
const bool use_render_params,
|
2015-07-18 21:42:39 +02:00
|
|
|
float min[3], float max[3])
|
|
|
|
|
{
|
2015-09-28 20:10:01 +05:00
|
|
|
const float size[3] = {radius, radius, radius};
|
|
|
|
|
const float cfra = BKE_scene_frame_get(scene);
|
2015-07-18 21:42:39 +02:00
|
|
|
ParticleSettings *part = psys->part;
|
2015-09-28 20:10:01 +05:00
|
|
|
ParticleSimulationData sim = {NULL};
|
|
|
|
|
ParticleData *pa = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
int total_particles;
|
|
|
|
|
float mat[4][4], imat[4][4];
|
|
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
if (part->type == PART_HAIR) {
|
|
|
|
|
/* TOOD(sergey): Not supported currently. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-28 20:10:01 +05:00
|
|
|
|
|
|
|
|
unit_m4(mat);
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
|
|
|
|
psys_render_set(object, psys, mat, mat, 1, 1, 0);
|
|
|
|
|
}
|
2015-09-28 20:10:01 +05:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
sim.eval_ctx = eval_ctx;
|
2015-09-28 20:10:01 +05:00
|
|
|
sim.scene = scene;
|
|
|
|
|
sim.ob = object;
|
|
|
|
|
sim.psys = psys;
|
|
|
|
|
sim.psmd = psys_get_modifier(object, psys);
|
|
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
invert_m4_m4(imat, object->obmat);
|
2015-09-28 20:10:01 +05:00
|
|
|
total_particles = psys->totpart + psys->totchild;
|
|
|
|
|
psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
|
|
|
|
|
|
|
|
|
|
for (i = 0, pa = psys->particles; i < total_particles; i++, pa++) {
|
2015-07-18 21:42:39 +02:00
|
|
|
float co_object[3], co_min[3], co_max[3];
|
2015-09-28 20:10:01 +05:00
|
|
|
ParticleKey state;
|
|
|
|
|
state.time = cfra;
|
|
|
|
|
if (!psys_get_particle_state(&sim, i, &state, 0)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
mul_v3_m4v3(co_object, imat, state.co);
|
2015-07-18 21:42:39 +02:00
|
|
|
sub_v3_v3v3(co_min, co_object, size);
|
|
|
|
|
add_v3_v3v3(co_max, co_object, size);
|
|
|
|
|
minmax_v3v3_v3(min, max, co_min);
|
|
|
|
|
minmax_v3v3_v3(min, max, co_max);
|
|
|
|
|
}
|
2015-09-28 20:10:01 +05:00
|
|
|
|
|
|
|
|
if (psys->lattice_deform_data) {
|
|
|
|
|
end_latt_deform(psys->lattice_deform_data);
|
|
|
|
|
psys->lattice_deform_data = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 12:09:28 +05:00
|
|
|
if (use_render_params) {
|
2016-01-07 20:10:57 +11:00
|
|
|
psys_render_restore(object, psys);
|
2015-10-08 12:09:28 +05:00
|
|
|
}
|
2015-07-18 21:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-27 07:32:48 +11:00
|
|
|
void RE_point_density_cache(
|
|
|
|
|
Scene *scene,
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer,
|
2016-01-27 07:32:48 +11:00
|
|
|
PointDensity *pd,
|
|
|
|
|
const bool use_render_params)
|
2015-11-25 17:38:12 +05:00
|
|
|
{
|
2017-07-21 11:53:13 +02:00
|
|
|
EvaluationContext eval_ctx = {0};
|
2015-11-25 17:38:12 +05:00
|
|
|
float mat[4][4];
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2017-07-26 16:21:43 +02:00
|
|
|
DEG_evaluation_context_init(&eval_ctx, use_render_params ? DAG_EVAL_RENDER
|
|
|
|
|
: DAG_EVAL_VIEWPORT);
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
eval_ctx.view_layer = view_layer;
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2015-11-25 17:38:12 +05:00
|
|
|
/* Same matricies/resolution as dupli_render_particle_set(). */
|
|
|
|
|
unit_m4(mat);
|
|
|
|
|
BLI_mutex_lock(&sample_mutex);
|
2017-07-21 11:53:13 +02:00
|
|
|
cache_pointdensity_ex(&eval_ctx, scene, pd, mat, mat, 1, 1, use_render_params);
|
2015-11-25 17:38:12 +05:00
|
|
|
BLI_mutex_unlock(&sample_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 07:32:48 +11:00
|
|
|
void RE_point_density_minmax(
|
|
|
|
|
struct Scene *scene,
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer,
|
2016-01-27 07:32:48 +11:00
|
|
|
struct PointDensity *pd,
|
|
|
|
|
const bool use_render_params,
|
|
|
|
|
float r_min[3], float r_max[3])
|
2015-07-18 21:42:39 +02:00
|
|
|
{
|
|
|
|
|
Object *object = pd->object;
|
|
|
|
|
if (object == NULL) {
|
2016-01-26 12:50:55 +01:00
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
2016-02-01 08:34:29 +01:00
|
|
|
return;
|
2015-07-18 21:42:39 +02:00
|
|
|
}
|
|
|
|
|
if (pd->source == TEX_PD_PSYS) {
|
|
|
|
|
ParticleSystem *psys;
|
2017-07-21 11:53:13 +02:00
|
|
|
EvaluationContext eval_ctx = {0};
|
|
|
|
|
|
2015-07-18 21:42:39 +02:00
|
|
|
if (pd->psys == 0) {
|
2016-01-26 12:50:55 +01:00
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
2015-07-18 21:42:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
psys = BLI_findlink(&object->particlesystem, pd->psys - 1);
|
|
|
|
|
if (psys == NULL) {
|
2016-01-26 12:50:55 +01:00
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
2015-07-18 21:42:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2017-07-21 11:53:13 +02:00
|
|
|
|
|
|
|
|
DEG_evaluation_context_init(&eval_ctx, use_render_params ? DAG_EVAL_RENDER :
|
|
|
|
|
DAG_EVAL_VIEWPORT);
|
|
|
|
|
|
|
|
|
|
eval_ctx.ctime = (float)scene->r.cfra + scene->r.subframe;
|
2017-11-22 10:52:39 -02:00
|
|
|
eval_ctx.view_layer = view_layer;
|
2017-07-21 11:53:13 +02:00
|
|
|
|
|
|
|
|
particle_system_minmax(&eval_ctx,
|
|
|
|
|
scene,
|
2015-10-08 12:09:28 +05:00
|
|
|
object,
|
|
|
|
|
psys,
|
|
|
|
|
pd->radius,
|
|
|
|
|
use_render_params,
|
2016-01-26 12:50:55 +01:00
|
|
|
r_min, r_max);
|
2015-07-18 21:42:39 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float radius[3] = {pd->radius, pd->radius, pd->radius};
|
2017-02-28 12:39:40 +01:00
|
|
|
BoundBox *bb = BKE_object_boundbox_get(object);
|
2016-02-28 22:56:18 +01:00
|
|
|
|
2017-02-28 12:39:40 +01:00
|
|
|
if (bb != NULL) {
|
|
|
|
|
BLI_assert((bb->flag & BOUNDBOX_DIRTY) == 0);
|
|
|
|
|
copy_v3_v3(r_min, bb->vec[0]);
|
|
|
|
|
copy_v3_v3(r_max, bb->vec[6]);
|
2016-02-28 22:56:18 +01:00
|
|
|
/* Adjust texture space to include density points on the boundaries. */
|
|
|
|
|
sub_v3_v3(r_min, radius);
|
|
|
|
|
add_v3_v3(r_max, radius);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
|
|
|
|
}
|
2016-01-26 12:50:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 12:19:56 +01:00
|
|
|
typedef struct SampleCallbackData {
|
|
|
|
|
PointDensity *pd;
|
|
|
|
|
int resolution;
|
|
|
|
|
float *min, *dim;
|
|
|
|
|
float *values;
|
|
|
|
|
} SampleCallbackData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void point_density_sample_func(
|
|
|
|
|
void *__restrict data_v,
|
|
|
|
|
const int iter,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2016-02-23 12:19:56 +01:00
|
|
|
{
|
|
|
|
|
SampleCallbackData *data = (SampleCallbackData *)data_v;
|
|
|
|
|
|
|
|
|
|
const int resolution = data->resolution;
|
|
|
|
|
const int resolution2 = resolution * resolution;
|
|
|
|
|
const float *min = data->min, *dim = data->dim;
|
|
|
|
|
PointDensity *pd = data->pd;
|
|
|
|
|
float *values = data->values;
|
|
|
|
|
|
|
|
|
|
size_t z = (size_t)iter;
|
|
|
|
|
for (size_t y = 0; y < resolution; ++y) {
|
|
|
|
|
for (size_t x = 0; x < resolution; ++x) {
|
|
|
|
|
size_t index = z * resolution2 + y * resolution + x;
|
|
|
|
|
float texvec[3];
|
2016-03-24 11:41:44 +01:00
|
|
|
float age, vec[3], col[3];
|
2016-02-23 12:19:56 +01:00
|
|
|
TexResult texres;
|
|
|
|
|
|
|
|
|
|
copy_v3_v3(texvec, min);
|
|
|
|
|
texvec[0] += dim[0] * (float)x / (float)resolution;
|
|
|
|
|
texvec[1] += dim[1] * (float)y / (float)resolution;
|
|
|
|
|
texvec[2] += dim[2] * (float)z / (float)resolution;
|
|
|
|
|
|
2016-03-24 11:41:44 +01:00
|
|
|
pointdensity(pd, texvec, &texres, vec, &age, col);
|
|
|
|
|
pointdensity_color(pd, &texres, age, vec, col);
|
2016-02-23 12:19:56 +01:00
|
|
|
|
|
|
|
|
copy_v3_v3(&values[index*4 + 0], &texres.tr);
|
|
|
|
|
values[index*4 + 3] = texres.tin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 07:32:48 +11:00
|
|
|
/* NOTE 1: Requires RE_point_density_cache() to be called first.
|
2016-01-26 12:50:55 +01:00
|
|
|
* NOTE 2: Frees point density structure after sampling.
|
|
|
|
|
*/
|
2016-01-27 07:32:48 +11:00
|
|
|
void RE_point_density_sample(
|
|
|
|
|
Scene *scene,
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer,
|
2016-01-27 07:32:48 +11:00
|
|
|
PointDensity *pd,
|
|
|
|
|
const int resolution,
|
|
|
|
|
const bool use_render_params,
|
|
|
|
|
float *values)
|
2016-01-26 12:50:55 +01:00
|
|
|
{
|
|
|
|
|
Object *object = pd->object;
|
|
|
|
|
float min[3], max[3], dim[3];
|
|
|
|
|
|
|
|
|
|
/* TODO(sergey): Implement some sort of assert() that point density
|
|
|
|
|
* was cached already.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (object == NULL) {
|
|
|
|
|
sample_dummy_point_density(resolution, values);
|
|
|
|
|
return;
|
2015-07-18 21:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 14:28:35 +01:00
|
|
|
BLI_mutex_lock(&sample_mutex);
|
2016-01-27 07:32:48 +11:00
|
|
|
RE_point_density_minmax(scene,
|
2017-11-22 10:52:39 -02:00
|
|
|
view_layer,
|
2016-01-26 12:50:55 +01:00
|
|
|
pd,
|
|
|
|
|
use_render_params,
|
|
|
|
|
min,
|
|
|
|
|
max);
|
2016-02-24 14:28:35 +01:00
|
|
|
BLI_mutex_unlock(&sample_mutex);
|
2015-07-18 21:42:39 +02:00
|
|
|
sub_v3_v3v3(dim, max, min);
|
|
|
|
|
if (dim[0] <= 0.0f || dim[1] <= 0.0f || dim[2] <= 0.0f) {
|
|
|
|
|
sample_dummy_point_density(resolution, values);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 12:19:56 +01:00
|
|
|
SampleCallbackData data;
|
|
|
|
|
data.pd = pd;
|
|
|
|
|
data.resolution = resolution;
|
|
|
|
|
data.min = min;
|
|
|
|
|
data.dim = dim;
|
|
|
|
|
data.values = values;
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (resolution > 32);
|
2016-02-23 12:19:56 +01:00
|
|
|
BLI_task_parallel_range(0,
|
|
|
|
|
resolution,
|
|
|
|
|
&data,
|
|
|
|
|
point_density_sample_func,
|
2018-01-08 11:35:48 +01:00
|
|
|
&settings);
|
2016-02-23 12:19:56 +01:00
|
|
|
|
2016-02-23 14:33:15 +01:00
|
|
|
free_pointdensity(pd);
|
2015-07-18 21:42:39 +02:00
|
|
|
}
|
2016-02-23 11:58:27 +01:00
|
|
|
|
|
|
|
|
void RE_point_density_free(struct PointDensity *pd)
|
|
|
|
|
{
|
|
|
|
|
free_pointdensity(pd);
|
|
|
|
|
}
|