[Bf-cycles] confusion with background and sample as light
Mohamed Sakr
3dsakr at gmail.com
Thu Aug 13 00:40:09 CEST 2015
Hi,
I'm creating a Cycles exporter, got 1 problem "pretty much a confusion
issue", about the background and sample as light.
so here are the focused functions:
void BlenderSync::sync_world(bool update_all)
{
Background *background = scene->background;
Background prevbackground = *background;
BL::World b_world = b_scene.world();
if(world_recalc || update_all || b_world.ptr.data != world_map) {
Shader *shader = scene->shaders[scene->default_background];
ShaderGraph *graph = new ShaderGraph();
/* create nodes */
if(b_world && b_world.use_nodes() && b_world.node_tree()) {
BL::ShaderNodeTree b_ntree(b_world.node_tree());
add_nodes(scene, b_engine, b_data, b_scene, graph, b_ntree);
/* volume */
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cworld,
"volume_sampling");
shader->volume_interpolation_method =
(VolumeInterpolation)RNA_enum_get(&cworld, "volume_interpolation");
}
else if(b_world) {
ShaderNode *closure, *out;
closure = graph->add(new BackgroundNode());
closure->input("Color")->value = get_float3(b_world.horizon_color());
out = graph->output();
graph->connect(closure->output("Background"), out->input("Surface"));
}
if(b_world) {
/* AO */
BL::WorldLighting b_light = b_world.light_settings();
if(b_light.use_ambient_occlusion())
background->ao_factor = b_light.ao_factor();
else
background->ao_factor = 0.0f;
background->ao_distance = b_light.distance();
/* visibility */
PointerRNA cvisibility = RNA_pointer_get(&b_world.ptr, "cycles_visibility");
uint visibility = 0;
visibility |= get_boolean(cvisibility, "camera")? PATH_RAY_CAMERA: 0;
visibility |= get_boolean(cvisibility, "diffuse")? PATH_RAY_DIFFUSE: 0;
visibility |= get_boolean(cvisibility, "glossy")? PATH_RAY_GLOSSY: 0;
visibility |= get_boolean(cvisibility, "transmission")? PATH_RAY_TRANSMIT:
0;
visibility |= get_boolean(cvisibility, "scatter")? PATH_RAY_VOLUME_SCATTER:
0;
background->visibility = visibility;
}
shader->set_graph(graph);
shader->tag_update(scene);
background->tag_update(scene);
}
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
/* when doing preview render check for BI's transparency settings,
* this is so because bledner's preview render routines are not able
* to tweak all cycles's settings depending on different circumstances
*/
if(b_engine.is_preview() == false)
background->transparent = get_boolean(cscene, "film_transparent");
else
background->transparent = b_scene.render().alpha_mode() ==
BL::RenderSettings::alpha_mode_TRANSPARENT;
background->use = render_layer.use_background;
if(background->modified(prevbackground))
background->tag_update(scene);
}
and
void BlenderSync::sync_background_light(bool use_portal)
{
BL::World b_world = b_scene.world();
if(b_world) {
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
bool sample_as_light = get_boolean(cworld, "sample_as_light");
if(sample_as_light || use_portal) {
/* test if we need to sync */
Light *light;
ObjectKey key(b_world, 0, b_world);
if(light_map.sync(&light, b_world, b_world, key) ||
world_recalc ||
b_world.ptr.data != world_map)
{
light->type = LIGHT_BACKGROUND;
light->map_resolution = get_int(cworld, "sample_map_resolution");
light->shader = scene->default_background;
light->use_mis = sample_as_light;
light->max_bounces = get_int(cworld, "max_bounces");
int samples = get_int(cworld, "samples");
if(get_boolean(cscene, "use_square_samples"))
light->samples = samples * samples;
else
light->samples = samples;
light->tag_update(scene);
light_map.set_recalc(b_world);
}
}
}
world_map = b_world.ptr.data;
world_recalc = false;
}
the confusing part:
if it is background "no mis" , then I can give all parameters "like AO,
visibility, ..."
if it is with mis "sample as light", then I will add a new light with the
same shader graph as the background?? "what will happen to the background
here? it is kinda using 2 things for the same purpose, as the background
which contain all world data like AO,... will emit to the scene using a
shader graph, and another light will emit to the scene using the same
shader graph"
any clarifications will be appreciated.
cheers,
Mohamed Sakr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-cycles/attachments/20150813/e2a57b0f/attachment.htm
More information about the Bf-cycles
mailing list