Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is it possible to use SFML with Arnold renderer C++ API?  (Read 3742 times)

0 Members and 1 Guest are viewing this topic.

nektarios

  • Newbie
  • *
  • Posts: 1
    • View Profile
Is it possible to use SFML with Arnold renderer C++ API?
« on: August 25, 2021, 04:45:40 am »
I would like to use the Arnold renderer API with SFML. Basically, to use Arnold to render a scene and show it on an SFML RenderWindow.

Below is a sample Arnold renderer C++ code that renders a scene and outputs it on a JPEG. I want instead of outputting to JPEG, to output on a SFML RenderWindow. Below is the Arnold C++ code:

int main()
{
   // start an Arnold session, log to both a file and the console
   AiBegin();
   AiMsgSetLogFileName("scene1.log");
   AiMsgSetConsoleFlags(AI_LOG_ALL);
 
   // create a sphere geometric primitive
   AtNode *sph = AiNode("sphere");
   AiNodeSetStr(sph, "name", "mysphere");
   AiNodeSetVec(sph, "center", 0.0f, 4.0f, 0.0f);
   AiNodeSetFlt(sph, "radius", 4.0f);
 
   // create a polymesh, with UV coordinates
   AtNode *mesh = AiNode("polymesh");
   AiNodeSetStr(mesh, "name", "mymesh");
   AtArray* nsides_array = AiArray(1, 1, AI_TYPE_UINT, 4);
   AiNodeSetArray(mesh, "nsides", nsides_array);
   AtArray* vlist_array = AiArray(12, 1, AI_TYPE_FLOAT, -10.f, 0.f, 10.f, 10.f, 0.f, 10.f, -10.f, 0.f, -10.f, 10.f, 0.f, -10.f);
   AiNodeSetArray(mesh, "vlist", vlist_array);
   AtArray* vidxs_array = AiArray(4, 1, AI_TYPE_UINT, 0, 1, 3, 2);
   AiNodeSetArray(mesh, "vidxs", vidxs_array);
   AtArray* uvlist_array = AiArray(8, 1, AI_TYPE_FLOAT, 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f);
   AiNodeSetArray(mesh, "uvlist", uvlist_array);
   AtArray* uvidxs_array = AiArray(4, 1, AI_TYPE_UINT, 0, 1, 2, 3);
   AiNodeSetArray(mesh, "uvidxs", uvidxs_array);
 
   // create a red standard surface shader
   AtNode *shader1 = AiNode("standard_surface");
   AiNodeSetStr(shader1, "name", "myshader1");
   AiNodeSetRGB(shader1, "base_color", 1.0f, 0.02f, 0.02f);
   AiNodeSetFlt(shader1, "specular", 0.05f);
 
   // create a textured standard surface shader
   AtNode *shader2 = AiNode("standard_surface");
   AiNodeSetStr(shader2, "name", "myshader2");
   AiNodeSetRGB(shader2, "base_color", 1.0f, 0.0f, 0.0f);
 
   // create an image shader for texture mapping
   AtNode *image = AiNode("image");
   AiNodeSetStr(image, "name", "myimage");
   AiNodeSetStr(image, "filename", "./dad_son.jpg");
   AiNodeSetFlt(image, "sscale", 4.f);
   AiNodeSetFlt(image, "tscale", 4.f);
   // link the output of the image shader to the color input of the surface shader
   AiNodeLink(image, "base_color", shader2);
 
   // assign the shaders to the geometric objects
   AiNodeSetPtr(sph, "shader", shader1);
   AiNodeSetPtr(mesh, "shader", shader2);
 
   // create a perspective camera
   AtNode *camera = AiNode("persp_camera");
   AiNodeSetStr(camera, "name", "mycamera");
   // position the camera (alternatively you can set 'matrix')
   AiNodeSetVec(camera, "position", 0.f, 10.f, 35.f);
   AiNodeSetVec(camera, "look_at", 0.f, 3.f, 0.f);
   AiNodeSetFlt(camera, "fov", 45.f);
 
   // create a point light source
   AtNode *light = AiNode("point_light");
   AiNodeSetStr(light, "name", "mylight");
   // position the light (alternatively use 'matrix')
   AiNodeSetVec(light, "position", 15.f, 30.f, 15.f);
   AiNodeSetFlt(light, "intensity", 4500.f); // alternatively, use 'exposure'
   AiNodeSetFlt(light, "radius", 4.f); // for soft shadows
 
   // get the global options node and set some options
   AtNode *options = AiUniverseGetOptions();
   AiNodeSetInt(options, "AA_samples", 8);
   AiNodeSetInt(options, "xres", 1480);
   AiNodeSetInt(options, "yres", 1360);
   AiNodeSetInt(options, "GI_diffuse_depth", 4);
   // set the active camera (optional, since there is only one camera)
   AiNodeSetPtr(options, "camera", camera);
 
   // create an output driver node
[b]   AtNode *driver = AiNode("driver_jpeg");
   AiNodeSetStr(driver, "name", "mydriver");
   AiNodeSetStr(driver, "filename", "./scene1.jpg");
 
   // create a gaussian filter node
   AtNode *filter = AiNode("gaussian_filter");
   AiNodeSetStr(filter, "name", "myfilter");
 
   // assign the driver and filter to the main (beauty) AOV,
   // which is called "RGBA" and is of type RGBA
   AtArray *outputs_array = AiArrayAllocate(1, 1, AI_TYPE_STRING);
   AiArraySetStr(outputs_array, 0, "RGBA RGBA myfilter mydriver");
   AiNodeSetArray(options, "outputs", outputs_array);
 
   // finally, render the image!
   AiRender(AI_RENDER_MODE_CAMERA);[/b]

   ArnoldWindow arnoldWindow = ArnoldWindow();
   arnoldWindow.show(outputs_array);

   // ... or you can write out an .ass file instead
   //AiASSWrite("scene1.ass", AI_NODE_ALL, FALSE);
 
   // Arnold session shutdown
   AiEnd();
 
   return 0;
};
« Last Edit: August 25, 2021, 02:43:31 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Is it possible to use SFML with Arnold renderer C++ API?
« Reply #1 on: August 25, 2021, 02:46:25 pm »
I don't know the Arnold renderer, but if it can get access to the pixel data, then you can use sf::Texture::update() to update a texture with the image content.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything