Automating Octane Baking for Unity - (SOLVED)

Forums: Automating Octane Baking for Unity - (SOLVED)
A public forum for discussing and asking questions about the Octane for Unity Alpha

Moderator: ChrisHekman

Automating Octane Baking for Unity - (SOLVED)

Postby SamuelAB » Sat Apr 20, 2019 3:10 pm

SamuelAB Sat Apr 20, 2019 3:10 pm
I've been working on automating lightmapping in Unity with a few developers for the last 5 months. We are almost done our workflow, but there are a few blockages.

This is our overall workflow for the script:

-- In 3ds Max --
1 Split the object into maximum 18,000 pieces and rename the new pieces in a logical manner (Art001, Art002, etc). This is done because UV mapped objects in Unity over a certain amount of triangles cannot receive baked maps.

-- In Unity --
2a Set a baking ID for each geometry object
2b Create a backing camera for each individual object
2c Give the camera a logical name (Cam-Art001, etc)
2d Place all cameras in a "Camera" empty object for organization purposes
2e Set the appropriate baking ID for each camera to match the Object Baking ID

-- In Octane --
3 The user batch renders the baking cameras

-- In Unity --
4a Look into the rendered image folder
4b For each images create a material and assign the image to the albedo and self illumination slot
4c For each new material, go assign it to the associated object in the scene
(We may also implement a material shell switcher to part 4 )

-------

The main problem is that there is a loss of information between Unity and Octane.

In step 2a, we cannot set the Baking ID of the geometry with a script. The API does not allow it.
In step 2e, we cannot set the Baking ID of the camera with a script. The API does not allow it.

In step 3, we cannot render the images in a logical manner because the names of the cameras are lost in Octane and become "PBR Render Target, PBR Render Target (2), PBR Render Target (3)" in a seemingly random order compared to the camera creation order, Ideally the names of the cameras would flow from Unity to Octane so that we would get a render name like "Cam-Art001_Denoised beauty".

Could you help us out in our quest for automated lightbaking in Unity with Octane? I'm hoping to finish automating this in the next 1.5 months.
Last edited by SamuelAB on Sat Jan 04, 2020 7:46 pm, edited 1 time in total.
User avatar
SamuelAB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Sun Apr 15, 2012 8:25 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby ChrisHekman » Tue Apr 23, 2019 10:05 am

ChrisHekman Tue Apr 23, 2019 10:05 am
In the current public build(1.2.0.1370 ) you should be able to fix your issues.
In step 2a, we cannot set the Baking ID of the geometry with a script. The API does not allow it.

You should be able to get the PBRInstanceProperties component from the gameobject and set the
Code: Select all
var PBRInstanceProps = targetGameobject.GetComponent<OctaneUnity.PBRInstanceProperties>();
PBRInstanceProps.BakingGroupID = 12;


In step 2e, we cannot set the Baking ID of the camera with a script. The API does not allow it.

This one is a bit more difficult, but should be doable.
Code: Select all
var RTComp = targetGameobject.GetComponent<OctaneUnity.PBRRenderTargetComponent>();
var RT = RTComp.RenderTarget;
RT.Camera.SetPinInt(Octane.PinId.P_BAKING_GROUP_ID, 12);


If this dosnt work, let me know.


That being said, is there areason you are not using the inbuild octane pbr lightmapper?
Last edited by ChrisHekman on Mon Apr 29, 2019 8:35 am, edited 1 time in total.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby SamuelAB » Tue Apr 23, 2019 10:50 am

SamuelAB Tue Apr 23, 2019 10:50 am
Hi, thanks for the quick reply!

I am not sure what you mean about the built in PBR lightmapper? You mean creating a single camera for every object and not rendering it in batch? Or making it render directly to the object texture image?

I've looked at the proposed workflows and nothing seems to batch the process or allow users to use it for the whole scene. Also, if I bake a texture to an object, I cannot bake it after, it just renders blacks if I try again, so I have to render everything at once and using the batch function of Octane seems more efficient.

Please let me know if there is something I do not understand that I could do better.

--

Also, please let me know if there is a way for the PBR Camera in Unity to keeps its name when going to Octane.

Thank you
User avatar
SamuelAB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Sun Apr 15, 2012 8:25 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby SamuelAB » Fri Apr 26, 2019 4:37 pm

SamuelAB Fri Apr 26, 2019 4:37 pm
Hi Chris,

Here's a few notes from my programmer:
- You might want to flag to Chris from Octane that he had a typo in his suggested code. Octane.P_BAKING_GROUP_ID doesn't exist. It is actually Octane.PinId.P_BAKING_GROUP_ID.
- Second, when instantiating the PBRRenderTargets in the CSV Writer script, these are created without a RenderTarget property. So I can't call the obj.RenderTarget.Camera.SetPinInt function. I found that I can call obj.CreateNewRenderTarget() after instantiating the object, and then set the PinInt, and I don't get any errors but it also doesn't actually update the BakingGroupID. So probably more work to be done there.

Thanks,
Sam
User avatar
SamuelAB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Sun Apr 15, 2012 8:25 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby ChrisHekman » Mon Apr 29, 2019 9:48 am

ChrisHekman Mon Apr 29, 2019 9:48 am
- Second, when instantiating the PBRRenderTargets in the CSV Writer script, these are created without a RenderTarget property. So I can't call the obj.RenderTarget.Camera.SetPinInt function. I found that I can call obj.CreateNewRenderTarget() after instantiating the object, and then set the PinInt, and I don't get any errors but it also doesn't actually update the BakingGroupID. So probably more work to be done there.


Octane for Unity updates changes in batches. This means that changes are buffered and will only have effect after OctaneUnity.Scene.Instance.UpdateScene() is called.
Additionally, if you instantiate a PBRRenderTarget component via code, you will need to


I thought you already had an RT ready. If you want to set everything up from script for baking you need to do the following:
Code: Select all
//Create the rendertarget
var RTComp = targetGameobject.AddComponent<OctaneUnity.PBRRenderTargetComponent>();
RT.CreateNewRenderTarget();
var RT = RTComp.RenderTarget;

//Create a new baking camera node for the rendertarget
RT.CreateInternal(Octane.PinId.P_CAMERA, Octane.NodeType.NT_CAM_BAKING);

//Set the baking ID
RT.Camera.SetPinInt(Octane.PinId.P_BAKING_GROUP_ID, 12);

//Set the rendertarget to the scene. (This will make the OctaneUnity use the new RT for rendering)
OctaneUnity.Scene.Instance.RenderTarget = RT;

//Update. This will update all the changes up till now
OctaneUnity.Scene.Instance.UpdateScene()


This should create a new render target, give it a baking camera and then set the desired baking ID.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby SamuelAB » Wed May 01, 2019 10:53 pm

SamuelAB Wed May 01, 2019 10:53 pm
Hi, it's all working except a little thing, The film resolution does not follow through.

In Unity it is 2048 x 2048, but in Octane it is 512 x 1024 for some reason. Would you know a line of code to fix this?

---

I am also assuming there is not documentation for Otoy's API in Unity? If there is, please let us know where we could look :)

Thank you for you help!
User avatar
SamuelAB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Sun Apr 15, 2012 8:25 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby SamuelAB » Wed May 01, 2019 11:14 pm

SamuelAB Wed May 01, 2019 11:14 pm
Oops, I forgot to include some of the code for context. Here it is:
Code.jpg
User avatar
SamuelAB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Sun Apr 15, 2012 8:25 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby ChrisHekman » Fri May 03, 2019 1:19 pm

ChrisHekman Fri May 03, 2019 1:19 pm
SamuelAB wrote:Hi, it's all working except a little thing, The film resolution does not follow through.

In Unity it is 2048 x 2048, but in Octane it is 512 x 1024 for some reason. Would you know a line of code to fix this?

---

I am also assuming there is not documentation for Otoy's API in Unity? If there is, please let us know where we could look :)

Thank you for you help!


There are two places you can see the Octane API. One is in visual studio. When you go to the Octane.Node definition you should be able to see all the available functions.
To see what PinIds each node type hs, you can open the OctaneGUI inside of unity and right click on a node and select "LUA API Browser"

Code: Select all
RT.FilmSettings.SetPinInt2(PinId.P_RESOLUTION, 2048, 2048);
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby vishakhadikara » Thu Aug 29, 2019 5:36 am

vishakhadikara Thu Aug 29, 2019 5:36 am
@ChrisHekman : How to access and change the GI values in the dropdown, SetPinInt on an enum is not working. please help.. Urgent
vishakhadikara
 
Posts: 1
Joined: Wed Aug 14, 2019 3:45 pm

Re: Automating Octane Baking for Unity - Octane API Problems

Postby ChrisHekman » Fri Aug 30, 2019 1:29 pm

ChrisHekman Fri Aug 30, 2019 1:29 pm
The problem might be that the values for GI are a bit weird?

DL_GI_NONE = 0,
DL_GI_AMBIENT_OCCLUSION = 3,
DL_GI_DIFFUSE = 4,

Hope that helps.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm
Next

Return to Octane for Unity


Who is online

Users browsing this forum: No registered users and 6 guests

Fri Mar 29, 2024 1:58 pm [ UTC ]