[Bf-blender-cvs] [99b1037] cycles_point_density: Cycles point density: Particle state coordinates are actually in the world space
Sergey Sharybin
noreply at git.blender.org
Wed Apr 1 12:31:43 CEST 2015
Commit: 99b10373dbade15401ce087adbc8bc1762f4fe92
Author: Sergey Sharybin
Date: Wed Apr 1 15:30:56 2015 +0500
Branches: cycles_point_density
https://developer.blender.org/rB99b10373dbade15401ce087adbc8bc1762f4fe92
Cycles point density: Particle state coordinates are actually in the world space
Code was assuming they're in the object space which caused wrong
texture sampling and translation to the world location.
===================================================================
M intern/cycles/blender/blender_texture.cpp
M source/blender/render/intern/source/pointdensity.c
===================================================================
diff --git a/intern/cycles/blender/blender_texture.cpp b/intern/cycles/blender/blender_texture.cpp
index 0598d26..cb4dd17 100644
--- a/intern/cycles/blender/blender_texture.cpp
+++ b/intern/cycles/blender/blender_texture.cpp
@@ -51,6 +51,7 @@ static void density_object_texture_space(BL::Object b_ob,
}
static void density_particle_system_texture_space(
+ BL::Object b_ob,
BL::ParticleSystem b_particle_system,
float radius,
float3& loc,
@@ -60,12 +61,15 @@ static void density_particle_system_texture_space(
/* TODO(sergey): Not supported currently. */
return;
}
+ Transform tfm = get_transform(b_ob.matrix_world());
+ Transform itfm = transform_inverse(tfm);
float3 min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX),
max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
float3 particle_size = make_float3(radius, radius, radius);
for(int i = 0; i < b_particle_system.particles.length(); ++i) {
BL::Particle particle = b_particle_system.particles[i];
float3 location = get_float3(particle.location());
+ location = transform_point(&itfm, location);
min = ccl::min(min, location - particle_size);
max = ccl::max(max, location + particle_size);
}
@@ -94,7 +98,8 @@ void point_density_texture_space(BL::ShaderNodeTexPointDensity b_point_density_n
BL::ParticleSystem b_particle_system(
b_point_density_node.particle_system());
if(b_particle_system) {
- density_particle_system_texture_space(b_particle_system,
+ density_particle_system_texture_space(b_ob,
+ b_particle_system,
b_point_density_node.radius(),
loc,
size);
diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c
index 21237e4..aae2c03 100644
--- a/source/blender/render/intern/source/pointdensity.c
+++ b/source/blender/render/intern/source/pointdensity.c
@@ -607,10 +607,13 @@ static void sample_dummy_point_density(int resolution, float *density)
memset(density, 0, sizeof(float) * resolution * resolution * resolution);
}
-static void particle_system_minmax(ParticleSystem *psys, float radius,
+static void particle_system_minmax(Object *object,
+ ParticleSystem *psys,
+ float radius,
float min[3], float max[3])
{
ParticleSettings *part = psys->part;
+ float imat[4][4];
float size[3] = {radius, radius, radius};
PARTICLE_P;
INIT_MINMAX(min, max);
@@ -618,10 +621,12 @@ static void particle_system_minmax(ParticleSystem *psys, float radius,
/* TOOD(sergey): Not supported currently. */
return;
}
+ invert_m4_m4(imat, object->obmat);
LOOP_PARTICLES {
- float co_min[3], co_max[3];
- sub_v3_v3v3(co_min, pa->state.co, size);
- add_v3_v3v3(co_max, pa->state.co, size);
+ float co_object[3], co_min[3], co_max[3];
+ mul_v3_m4v3(co_object, imat, pa->state.co);
+ 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);
}
@@ -651,7 +656,7 @@ void RE_sample_point_density(Scene *scene, PointDensity *pd,
sample_dummy_point_density(resolution, density);
return;
}
- particle_system_minmax(psys, pd->radius, min, max);
+ particle_system_minmax(object, psys, pd->radius, min, max);
}
else {
float radius[3] = {pd->radius, pd->radius, pd->radius};
More information about the Bf-blender-cvs
mailing list