-
Notifications
You must be signed in to change notification settings - Fork 2
Rendering example
The s_mcRender* scripts show how to
- create a kubernetes cluster on the GCP
- upload the data to a GCP bucket
- invoke one or more PBRT docker containers to perform the rendering
- download the rendered scene.
The simplest script is s_mcRender.m, which we describe here.
%% Initialize ISET, Google cloud SDK and Docker
ieInit;
if ~mcDockerExists, mcDockerConfig; end % check whether we can use docker
if ~mcGcloudExists, mcGcloudConfig; end % check whether we can use google cloud sdk;
Next, we create a GCP object using the gCloud class. Starting the cluster from scratch takes about 3 or 4 minutes. If the cluster already exists, the gCloud call finds it and establishes a connection. That takes about 10 seconds.
We frequently set up the same cluster. In our case, we often set up a cluster for PBRT V3 in us-central1 zone with 32 cores. To make the code simpler and clearer, we saved the parameters in a JSON file (accounts/gcp-pbrtv3-central-32.json) and initialize the cluster using the data from that file.
%% Initialize the master Node in the cluster
tic
gCloud('configuration','gcp-pbrtv3-central-32');
toc
You can also set up the GCP parameters by the gCloud command itself, if you do not have a file saved. For an example of how to save a file, see mcGCPaccounts.m
% This prints out a summary of the situation. The command returns a struct
% with the various fields, as well.
str = gcp.Configlist;
Next, we prepare the jobs. The jobs are executed in a structure that kubernetes calls a POD.
%% Data definition
%
% The isetcloud code creates a set of 'target' variables that describe the
% renderings we would like to perform. We clear the variable at the start
% of this script.
gcp.targets =[];
The next section of the code runs iset3d functions to set up the data for rendering. It then uploads the prepared results to a 'bucket' in the GCP.
%% This is the teapot example in iset3d
fName = fullfile(piRootPath,'data','teapot-area','teapot-area-light.pbrt');
thisR = piRead(fName);
thisR.set('camera','pinhole');
thisR.set('rays per pixel',32);
thisR.set('film resolution',256);
[p,n,e] = fileparts(fName);
thisR.outputFile = fullfile(mcRootPath,'local','teapot',[n,e]);
piWrite(thisR);
%% Upload to the bucket attached to pbrtrendering
% This zips all the files needed for rendering into a single file. Then the
% zip file and the critical pbrt scene file is uploaded to the bucket.
gcp.uploadPBRT(thisR);
Now, we manage the targets
%% Add the new PBRT rendering target with necessary information
% After the upload, the target slot has the information needed to
% render
if ~isempty(gcp.targets)
fprintf('%d current targets\n',length(gcp.targets));
end
addPBRTTarget(gcp,thisR);
fprintf('Added one target. Now %d current targets\n',length(gcp.targets));
We invoke the GCP render command and wait for the targets to finish.
%% This invokes the PBRT-V3 docker image
gcp.render();
cnt = 0;
while cnt < length(gcp.targets)
cnt = podSucceeded(gcp);
pause(5);
end
Get the scene and have a look.
%% Download and show
scene = gcp.downloadPBRT(thisR);
% Show the first scene (there is only one in this case) in ISET
ieAddObject(scene{1}); sceneWindow;
sceneSet(scene,'gamma',0.5);