Пример #1
0
void BlenderSync::sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm)
{
	/* test if we need to sync */
	Light *light;
	ObjectKey key(b_parent, b_index, b_ob);

	if(!light_map.sync(&light, b_ob, b_parent, key))
		return;
	
	BL::Lamp b_lamp(b_ob.data());

	/* type */
	switch(b_lamp.type()) {
		case BL::Lamp::type_POINT: {
			BL::PointLamp b_point_lamp(b_lamp);
			light->size = b_point_lamp.shadow_soft_size();
			light->type = LIGHT_POINT;
			break;
		}
		case BL::Lamp::type_SPOT: {
			BL::SpotLamp b_spot_lamp(b_lamp);
			light->size = b_spot_lamp.shadow_soft_size();
			light->type = LIGHT_POINT;
			break;
		}
		case BL::Lamp::type_HEMI: {
			light->type = LIGHT_DISTANT;
			light->size = 0.0f;
			break;
		}
		case BL::Lamp::type_SUN: {
			BL::SunLamp b_sun_lamp(b_lamp);
			light->size = b_sun_lamp.shadow_soft_size();
			light->type = LIGHT_DISTANT;
			break;
		}
		case BL::Lamp::type_AREA: {
			BL::AreaLamp b_area_lamp(b_lamp);
			light->size = 1.0f;
			light->axisu = make_float3(tfm.x.x, tfm.y.x, tfm.z.x);
			light->axisv = make_float3(tfm.x.y, tfm.y.y, tfm.z.y);
			light->sizeu = b_area_lamp.size();
			if(b_area_lamp.shape() == BL::AreaLamp::shape_RECTANGLE)
				light->sizev = b_area_lamp.size_y();
			else
				light->sizev = light->sizeu;
			light->type = LIGHT_AREA;
			break;
		}
	}

	/* location and (inverted!) direction */
	light->co = make_float3(tfm.x.w, tfm.y.w, tfm.z.w);
	light->dir = -make_float3(tfm.x.z, tfm.y.z, tfm.z.z);

	/* shader */
	vector<uint> used_shaders;

	find_shader(b_lamp, used_shaders, scene->default_light);

	if(used_shaders.size() == 0)
		used_shaders.push_back(scene->default_light);

	light->shader = used_shaders[0];

	/* shadow */
	PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
	light->cast_shadow = get_boolean(clamp, "cast_shadow");

	/* tag */
	light->tag_update(scene);
}
Пример #2
0
void BlenderSync::sync_light(BL::Object& b_parent,
                             int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
                             BL::Object& b_ob,
                             BL::DupliObject& b_dupli_ob,
                             Transform& tfm,
                             bool *use_portal)
{
	/* test if we need to sync */
	Light *light;
	ObjectKey key(b_parent, persistent_id, b_ob);

	if(!light_map.sync(&light, b_ob, b_parent, key)) {
		if(light->is_portal)
			*use_portal = true;
		return;
	}
	
	BL::Lamp b_lamp(b_ob.data());

	/* type */
	switch(b_lamp.type()) {
		case BL::Lamp::type_POINT: {
			BL::PointLamp b_point_lamp(b_lamp);
			light->size = b_point_lamp.shadow_soft_size();
			light->type = LIGHT_POINT;
			break;
		}
		case BL::Lamp::type_SPOT: {
			BL::SpotLamp b_spot_lamp(b_lamp);
			light->size = b_spot_lamp.shadow_soft_size();
			light->type = LIGHT_SPOT;
			light->spot_angle = b_spot_lamp.spot_size();
			light->spot_smooth = b_spot_lamp.spot_blend();
			break;
		}
		case BL::Lamp::type_HEMI: {
			light->type = LIGHT_DISTANT;
			light->size = 0.0f;
			break;
		}
		case BL::Lamp::type_SUN: {
			BL::SunLamp b_sun_lamp(b_lamp);
			light->size = b_sun_lamp.shadow_soft_size();
			light->type = LIGHT_DISTANT;
			break;
		}
		case BL::Lamp::type_AREA: {
			BL::AreaLamp b_area_lamp(b_lamp);
			light->size = 1.0f;
			light->axisu = transform_get_column(&tfm, 0);
			light->axisv = transform_get_column(&tfm, 1);
			light->sizeu = b_area_lamp.size();
			if(b_area_lamp.shape() == BL::AreaLamp::shape_RECTANGLE)
				light->sizev = b_area_lamp.size_y();
			else
				light->sizev = light->sizeu;
			light->type = LIGHT_AREA;
			break;
		}
	}

	/* location and (inverted!) direction */
	light->co = transform_get_column(&tfm, 3);
	light->dir = -transform_get_column(&tfm, 2);
	light->tfm = tfm;

	/* shader */
	vector<Shader*> used_shaders;
	find_shader(b_lamp, used_shaders, scene->default_light);
	light->shader = used_shaders[0];

	/* shadow */
	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
	PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
	light->cast_shadow = get_boolean(clamp, "cast_shadow");
	light->use_mis = get_boolean(clamp, "use_multiple_importance_sampling");
	
	int samples = get_int(clamp, "samples");
	if(get_boolean(cscene, "use_square_samples"))
		light->samples = samples * samples;
	else
		light->samples = samples;

	light->max_bounces = get_int(clamp, "max_bounces");

	if(b_dupli_ob) {
		light->random_id = b_dupli_ob.random_id();
	}
	else {
		light->random_id = hash_int_2d(hash_string(b_ob.name().c_str()), 0);
	}

	if(light->type == LIGHT_AREA)
		light->is_portal = get_boolean(clamp, "is_portal");
	else
		light->is_portal = false;

	if(light->is_portal)
		*use_portal = true;

	/* visibility */
	uint visibility = object_ray_visibility(b_ob);
	light->use_diffuse = (visibility & PATH_RAY_DIFFUSE) != 0;
	light->use_glossy = (visibility & PATH_RAY_GLOSSY) != 0;
	light->use_transmission = (visibility & PATH_RAY_TRANSMIT) != 0;
	light->use_scatter = (visibility & PATH_RAY_VOLUME_SCATTER) != 0;

	/* tag */
	light->tag_update(scene);
}
Пример #3
0
void BlenderSync::sync_light(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::Object b_ob, Transform& tfm)
{
    /* test if we need to sync */
    Light *light;
    ObjectKey key(b_parent, persistent_id, b_ob);

    if(!light_map.sync(&light, b_ob, b_parent, key))
        return;

    BL::Lamp b_lamp(b_ob.data());

    /* type */
    switch(b_lamp.type()) {
    case BL::Lamp::type_POINT: {
        BL::PointLamp b_point_lamp(b_lamp);
        light->size = b_point_lamp.shadow_soft_size();
        light->type = LIGHT_POINT;
        break;
    }
    case BL::Lamp::type_SPOT: {
        BL::SpotLamp b_spot_lamp(b_lamp);
        light->size = b_spot_lamp.shadow_soft_size();
        light->type = LIGHT_SPOT;
        light->spot_angle = b_spot_lamp.spot_size();
        light->spot_smooth = b_spot_lamp.spot_blend();
        break;
    }
    case BL::Lamp::type_HEMI: {
        light->type = LIGHT_DISTANT;
        light->size = 0.0f;
        break;
    }
    case BL::Lamp::type_SUN: {
        BL::SunLamp b_sun_lamp(b_lamp);
        light->size = b_sun_lamp.shadow_soft_size();
        light->type = LIGHT_DISTANT;
        break;
    }
    case BL::Lamp::type_AREA: {
        BL::AreaLamp b_area_lamp(b_lamp);
        light->size = 1.0f;
        light->axisu = transform_get_column(&tfm, 0);
        light->axisv = transform_get_column(&tfm, 1);
        light->sizeu = b_area_lamp.size();
        if(b_area_lamp.shape() == BL::AreaLamp::shape_RECTANGLE)
            light->sizev = b_area_lamp.size_y();
        else
            light->sizev = light->sizeu;
        light->type = LIGHT_AREA;
        break;
    }
    }

    /* location and (inverted!) direction */
    light->co = transform_get_column(&tfm, 3);
    light->dir = -transform_get_column(&tfm, 2);

    /* shader */
    vector<uint> used_shaders;

    find_shader(b_lamp, used_shaders, scene->default_light);

    if(used_shaders.size() == 0)
        used_shaders.push_back(scene->default_light);

    light->shader = used_shaders[0];

    /* shadow */
    PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
    light->cast_shadow = get_boolean(clamp, "cast_shadow");
    light->use_mis = get_boolean(clamp, "use_multiple_importance_sampling");
    light->samples = get_int(clamp, "samples");

    /* tag */
    light->tag_update(scene);
}