Results 1 to 3 of 3

Thread: Howto add a lightsource to a scene

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Question Howto add a lightsource to a scene

    Hi,

    I am trying to integrate the iray integration framework into our renderengine as an additional render path. Therefore the complete scenegraph has to be created within this engine.

    As a first test I was able to load a scenegraph file with iray and draw the output within our renderengine.

    Now I am trying to create the complete iray scenegraph in our engine from scratch and populate it with the different objects our scenegraph provides. After hours staring at the documentation and the examples I did not manage to figure out how to create a simple light source without loading a complete scene from file. Can someone give me a hint howto do this? How for example do I create a simple point light?

    Thanks.

  2. #2
    Join Date
    Jul 2012
    Posts
    2

    Lightbulb Now I figured out how to add a light source

    Hi,

    after some more digging I found the answer myself. As a newbie, I found it very hard to put all those pieces together that are required to create a light source (or more important a shader).

    So here is a code snippet for creating a light source. This is just a 'hack' version, because all checks you should normally do are missing. Maybe it is of use for someone else or there are ideas how to do this in an easier way.

    Code:
    	// Import Light-Shader-Class
    	mi::base::Handle<mi::IBoolean> list_elements (transaction->create<mi::IBoolean>( "Boolean"));
    	list_elements->set_value (true);
    	mi::base::Handle<mi::IMap> importer_options (transaction->create<mi::IMap> ("Map<Interface>"));
    	importer_options->insert ("list_elements", list_elements.get());
    
    	mi::base::Handle<mi::neuraylib::IImport_api> import_api (neuray->get_api_component<mi::neuraylib::IImport_api>());
    	check_success( import_api.is_valid_interface());
    	mi::base::Handle<const mi::IImport_result> import_result (import_api->import_elements (transaction, "light_point.msl", importer_options.get()));
    
    	// Create Light-Shader
    	mi::base::Handle<mi::IShader_class> light_shader_class (transaction->edit<mi::IShader_class> (import_result->get_element (0)));
    	light_shader_class->create_function ("light_shader");
    
    	mi::base::Handle<mi::IShader> light_shader (transaction->edit<mi::IShader> ("light_shader"));
    	light_shader->edit_attribute<mi::IFloat32> ("intensity")->set_value (300.0);
    
    	// Create Light
    	mi::base::Handle<mi::ILight> light (transaction->create<mi::ILight> ("Light"));
    
    	light->set_type (mi::LIGHT_POINT);
    	light->set_distance (100.0);
    	light->attach_shader (mi::LIGHT_SHADER, "light_shader");
    	transaction->store (light.get (), _light.c_str ());
    
    	// Create Light-Instance
    	mi::base::Handle<mi::IInstance> light_instance (transaction->create<mi::IInstance> ("Instance"));
    
    	mi::Float64_4_4 matrix_light (1.0);
    	matrix_light.translate (2.0, 2.0, -20.0);
    
    	light_instance->attach (_light.c_str ());
    	light_instance->set_world_to_obj (matrix_light);
    
    	transaction->store (light_instance.get (), _light_instance.c_str ());
    
    	// Add Light-Instance to root group
    	mi::base::Handle<mi::IGroup> edit_group (transaction->edit<mi::IGroup> ( _rootgroup.c_str ()));
    	edit_group->attach (_light_instance.c_str ());

  3. #3
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    22

    Default

    Hi, in the download section of iray (http://www.mentalimages.com/products...framework.html) you will find code examples and there is one specifically on lights.

    Note that you need the latest version.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •