// forces arise from pressure difference and viscosity void apply_forces(std::vector<interaction> interactions, fluid f) { btVector3 dir; for (long ii=0; ii<interactions.size(); ii++) { interaction i = interactions[ii]; float pf_fraction = - f.particle_mass * (i.p0->p_d2 + i.p1->p_d2) * press_kg(i.distance, f.smoothing_radius); float vf_fraction = f.dynamic_viscosity * (particle_velocity(i.p0)- particle_velocity(i.p1)).length() * visc_kl(i.distance, f.smoothing_radius); dir = i.direction; i.p0->pforce += (dir *= pf_fraction); i.p1->pforce -= dir; dir = i.direction; i.p0->vforce += (dir *= vf_fraction); i.p1->vforce -= dir; } for (particle* pp=f.particles; pp<f.particles + f.particle_count; pp++) { pp->rigid_body->applyCentralImpulse((pp->pforce + pp->vforce) * f.dt); // printf("Samples = %lu, density = %f\n", pp->samples, pp->density/f.density); } }
bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val) { /* todo: turn this into hash table? */ /* Object Attributes */ if (name == u_object_location) { float3 f = object_location(kg, sd); return set_attribute_float3(f, type, derivatives, val); } else if (name == u_object_index) { float f = object_pass_id(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } else if (name == u_geom_dupli_generated) { float3 f = object_dupli_generated(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } else if (name == u_geom_dupli_uv) { float3 f = object_dupli_uv(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } else if (name == u_material_index) { float f = shader_pass_id(kg, sd); return set_attribute_float(f, type, derivatives, val); } else if (name == u_object_random) { float f = object_random_number(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } /* Particle Attributes */ else if (name == u_particle_index) { uint particle_id = object_particle_id(kg, sd->object); float f = particle_index(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if (name == u_particle_age) { uint particle_id = object_particle_id(kg, sd->object); float f = particle_age(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if (name == u_particle_lifetime) { uint particle_id = object_particle_id(kg, sd->object); float f= particle_lifetime(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if (name == u_particle_location) { uint particle_id = object_particle_id(kg, sd->object); float3 f = particle_location(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } #if 0 /* unsupported */ else if (name == u_particle_rotation) { uint particle_id = object_particle_id(kg, sd->object); float4 f = particle_rotation(kg, particle_id); return set_attribute_float4(f, type, derivatives, val); } #endif else if (name == u_particle_size) { uint particle_id = object_particle_id(kg, sd->object); float f = particle_size(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if (name == u_particle_velocity) { uint particle_id = object_particle_id(kg, sd->object); float3 f = particle_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } else if (name == u_particle_angular_velocity) { uint particle_id = object_particle_id(kg, sd->object); float3 f = particle_angular_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } /* Geometry Attributes */ else if (name == u_geom_numpolyvertices) { return set_attribute_int(3, type, derivatives, val); } else if ((name == u_geom_trianglevertices || name == u_geom_polyvertices) #ifdef __HAIR__ && sd->segment == ~0) { #else ) { #endif float3 P[3]; triangle_vertices(kg, sd->prim, P); if(!(sd->flag & SD_TRANSFORM_APPLIED)) { object_position_transform(kg, sd, &P[0]); object_position_transform(kg, sd, &P[1]); object_position_transform(kg, sd, &P[2]); } return set_attribute_float3_3(P, type, derivatives, val); } else if(name == u_geom_name) { ustring object_name = kg->osl->object_names[sd->object]; return set_attribute_string(object_name, type, derivatives, val); } #ifdef __HAIR__ /* Hair Attributes */ else if (name == u_is_curve) { float f = (sd->segment != ~0); return set_attribute_float(f, type, derivatives, val); } else if (name == u_curve_thickness) { float f = curve_thickness(kg, sd); return set_attribute_float(f, type, derivatives, val); } else if (name == u_curve_tangent_normal) { float3 f = curve_tangent_normal(kg, sd); return set_attribute_float3(f, type, derivatives, val); } #endif else return false; }
bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val) { /* todo: turn this into hash table? */ /* Object Attributes */ if(name == u_object_location) { float3 f = object_location(kg, sd); return set_attribute_float3(f, type, derivatives, val); } else if(name == u_object_index) { float f = object_pass_id(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } else if(name == u_geom_dupli_generated) { float3 f = object_dupli_generated(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } else if(name == u_geom_dupli_uv) { float3 f = object_dupli_uv(kg, sd->object); return set_attribute_float3(f, type, derivatives, val); } else if(name == u_material_index) { float f = shader_pass_id(kg, sd); return set_attribute_float(f, type, derivatives, val); } else if(name == u_object_random) { float f = object_random_number(kg, sd->object); return set_attribute_float(f, type, derivatives, val); } /* Particle Attributes */ else if(name == u_particle_index) { int particle_id = object_particle_id(kg, sd->object); float f = particle_index(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if(name == u_particle_age) { int particle_id = object_particle_id(kg, sd->object); float f = particle_age(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if(name == u_particle_lifetime) { int particle_id = object_particle_id(kg, sd->object); float f = particle_lifetime(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if(name == u_particle_location) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_location(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } #if 0 /* unsupported */ else if(name == u_particle_rotation) { int particle_id = object_particle_id(kg, sd->object); float4 f = particle_rotation(kg, particle_id); return set_attribute_float4(f, type, derivatives, val); } #endif else if(name == u_particle_size) { int particle_id = object_particle_id(kg, sd->object); float f = particle_size(kg, particle_id); return set_attribute_float(f, type, derivatives, val); } else if(name == u_particle_velocity) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } else if(name == u_particle_angular_velocity) { int particle_id = object_particle_id(kg, sd->object); float3 f = particle_angular_velocity(kg, particle_id); return set_attribute_float3(f, type, derivatives, val); } /* Geometry Attributes */ else if(name == u_geom_numpolyvertices) { return set_attribute_int(3, type, derivatives, val); } else if((name == u_geom_trianglevertices || name == u_geom_polyvertices) #ifdef __HAIR__ && sd->type & PRIMITIVE_ALL_TRIANGLE) #else ) #endif { float3 P[3]; if(sd->type & PRIMITIVE_TRIANGLE) triangle_vertices(kg, sd->prim, P); else motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P); if(!(sd->flag & SD_TRANSFORM_APPLIED)) { object_position_transform(kg, sd, &P[0]); object_position_transform(kg, sd, &P[1]); object_position_transform(kg, sd, &P[2]); } return set_attribute_float3_3(P, type, derivatives, val); } else if(name == u_geom_name) {