static void light_add(Widget w, XtPointer data, XmAnyCallbackStruct *cbs) { extern void add_light(); if (light_count() > 8) { OOGLError(0, "Can't have more than 8 lights\n"); return; } add_light(); }
void ui_load_lightspanel() { int n; Widget lightsform, lightsadd, lightsdel, ColButton, HideButton; char buf[100]; mib_Widget *lightsload; static char Lights[] = "Lights"; /*****************************************************************************/ ui_make_panel_and_form(Lights, Root, True, True, &lightsform); /*lightsload = mib_load_interface(lightsform, "interface/Lights.mib", MI_FROMFILE);*/ lightsload = mib_load_interface(lightsform, Root, MI_FROMSTRING); XtManageChild(lightsform); /*****************************************************************************/ ColButton = mib_find_name(lightsload, "ColorButton")->me; HideButton = mib_find_name(lightsload, "HideButton")->me; lightslist = mib_find_name(lightsload, "LightsList")->me; lintensity = mib_find_name(lightsload, "IntensityScale")->me; ltoggle = mib_find_name(lightsload, "LightsToggle")->me; lightsadd = mib_find_name(lightsload, "AddButton")->me; lightsdel = mib_find_name(lightsload, "DeleteButton")->me; XtAddCallback(ColButton, XmNactivateCallback, (XtCallbackProc) color_light, (XtPointer) NULL); XtAddCallback(HideButton, XmNactivateCallback, (XtCallbackProc) ui_hide, (XtPointer) Lights); XtAddCallback(lightslist, XmNbrowseSelectionCallback, (XtCallbackProc) select_light, (XtPointer) &lintensity); XtAddCallback(lintensity, XmNdragCallback, (XtCallbackProc) intensity_light, (XtPointer) NULL); XtAddCallback(lintensity, XmNvalueChangedCallback, (XtCallbackProc) intensity_light, (XtPointer) NULL); XtAddCallback(ltoggle, XmNvalueChangedCallback, (XtCallbackProc) toggle_lights, (XtPointer) NULL); XtAddCallback(lightsadd, XmNactivateCallback, (XtCallbackProc) light_add, (XtPointer) NULL); XtAddCallback(lightsdel, XmNactivateCallback, (XtCallbackProc) light_del, (XtPointer) NULL); /*****************************************************************************/ /* Initialize Panel Variables */ lights[0] = "ambient"; for (n = 1; n <= MAXLIGHTS; ++n) { sprintf(buf, "light %1d", n); lights[n] = strdup(buf); } ui_build_browser(lightslist, light_count(), lights); }
void ui_show_lightspanel() { set_light(light_count() > 0 ? 1 : 0); XmListSelectPos(lightslist, uistate.current_light + 1, False); }
void ui_lights_changed() { ui_build_browser(lightslist, light_count(), lights); set_light(uistate.current_light); }
void LightTree::sample(LightQuery* query) const { const Node* node = &(nodes[0]); float tot_prob = 1.0f; // Traverse down the tree, keeping track of the relative probabilities while (!node->is_leaf) { // Calculate the relative probabilities of the two children float p1 = node_prob(*query, node->index1); float p2 = node_prob(*query, node->index2); const float total = p1 + p2; if (total <= 0.0f) { p1 = 0.5f; p2 = 0.5f; } else { p1 /= total; p2 /= total; } if (query->n <= p1) { tot_prob *= p1; node = &(nodes[node->index1]); query->n /= p1; } else { tot_prob *= p2; node = &(nodes[node->index2]); query->n = (query->n - p1) / p2; } } // Instance shorthand const Instance& instance = assembly->instances[node->instance_index]; // Push the instance index onto the ID query->id.push_back(node->instance_index, assembly->element_id_bits()); // Get transforms if any if (instance.transform_count > 0) { auto cbegin = assembly->xforms.cbegin() + instance.transform_index; auto cend = cbegin + instance.transform_count; auto instance_xform = lerp_seq(query->time, cbegin, cend); query->pos = instance_xform.pos_to(query->pos); query->nor = instance_xform.nor_to(query->nor).normalized(); query->xform *= instance_xform; } // Do light sampling if (instance.type == Instance::OBJECT) { const Object* obj = assembly->objects[instance.data_index].get(); // Shorthand if (obj->get_type() == Object::LIGHT) { const Light* light = dynamic_cast<const Light*>(obj); float p = 1.0f; query->spec_samp = light->sample(query->pos, query->u, query->v, query->wavelength, query->time, &(query->to_light), &p); query->to_light = query->xform.dir_from(query->to_light); query->selection_pdf *= (tot_prob * light_count()); query->light_sample_pdf = p; } // TODO: handle non-light objects that emit light } else if (instance.type == Instance::ASSEMBLY) { const Assembly* asmb = assembly->assemblies[instance.data_index].get(); // Shorthand query->selection_pdf *= (tot_prob * light_count()) / asmb->light_accel.light_count(); asmb->light_accel.sample(query); } }