Skip to content
Snippets Groups Projects
Commit 51fb5f0e authored by Ben Heasly's avatar Ben Heasly
Browse files

rtbMakeCrytekSponza don't need to cd()

parent 70464dc3
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
% camera positions using a pinhole camera.
% Once rendered, it saves each multispectral image as an ISET optical image
% and uses ISET to display the oi's.
% and uses ISET to display the oi's.
% The Crytek model was imported into Blender, an Area Light mesh was added,
% and then exported as an OBJ file. The scene was organized in meter units
......@@ -32,12 +32,32 @@
% TL
%% Initialize
% tbUse('isetbio')
clear; close all;
ieInit;
% We must be in the same folder as this script
[path,name,ext] = fileparts(mfilename('fullpath'));
cd(path);
%% Choose batch renderer options.
hints.imageWidth = 144;
hints.imageHeight = 88;
hints.recipeName = 'CrytekSponza';
hints.renderer = 'PBRT';
hints.batchRenderStrategy = RtbAssimpStrategy(hints);
% This function modifies general scene paraemters
hints.batchRenderStrategy.remodelPerConditionAfterFunction = @rtbCrytekMexximpRemodeler;
% This function modifies PBRT specific parameters
hints.batchRenderStrategy.converter.remodelAfterMappingsFunction = @rtbCrytekPBRTRemodeler;
% Change the docker container to our version of PBRT-spectral
hints.batchRenderStrategy.renderer.pbrt.dockerImage = 'vistalab/pbrt-v2-spectral';
resourceFolder = rtbWorkingFolder( ...
'folderName', 'resources',...
'hints', hints);
%% Load scene
% When exporting as an OBJ Blender, we must keep the coordinate system
......@@ -45,7 +65,8 @@ cd(path);
% images right now.
% The following scenefile must be a full path.
sceneFile = fullfile(path,'Data','scaledCrytek.obj');
sceneFile = fullfile(rtbRoot(), 'ExampleScenes', 'IsetbioExamples', ...
'CrytekSponza', 'Data', 'scaledCrytek.obj');
% The import will convert the JPG texture files into EXR format if
% necessary.
......@@ -53,11 +74,12 @@ sceneFile = fullfile(path,'Data','scaledCrytek.obj');
'flipUVs',true,...
'imagemagicImage','hblasins/imagemagic-docker',...
'toReplace',{'jpg','tiff'},...
'targetFormat','exr');
'targetFormat','exr', ...
'workingFolder', resourceFolder);
%% Add a camera and move it to a starting position
scene = mexximpCentralizeCamera(scene);
scene = mexximpCentralizeCamera(scene, 'viewExterior', false);
% In general, these camera positions are determined by positioning the
% camera in Blender
......@@ -70,27 +92,12 @@ cameraTransform = mexximpLookAt(from, to, up);
cameraNodeSelector = strcmp(scene.cameras.name, {scene.rootNode.children.name});
scene.rootNode.children(cameraNodeSelector).transformation = cameraTransform;
%% Choose batch renderer options.
hints.imageWidth = 144;
hints.imageHeight = 88;
hints.recipeName = 'rtbMakeCrytek';
hints.renderer = 'PBRT';
hints.batchRenderStrategy = RtbAssimpStrategy(hints);
% This function modifies general scene paraemters
hints.batchRenderStrategy.remodelPerConditionAfterFunction = @rtbCrytekMexximpRemodeler;
% This function modifies PBRT specific parameters
hints.batchRenderStrategy.converter.remodelAfterMappingsFunction = @rtbCrytekPBRTRemodeler;
% Change the docker container to our version of PBRT-spectral
hints.batchRenderStrategy.renderer.pbrt.dockerImage = 'vistalab/pbrt-v2-spectral';
%% Write any spectrum files.
% Load up D65 and move into the working folder.
% Load up D65 and move into the working folder.
[wls,spd] = rtbReadSpectrum('D65.spd');
rtbWriteSpectrumFile(wls, spd, fullfile(rtbWorkingFolder('hints', hints),'D65.spd'));
workingFolder = rtbWorkingFolder('hints', hints);
rtbWriteSpectrumFile(wls, spd, fullfile(workingFolder, 'D65.spd'));
%% Write conditions and generate scene files
......@@ -98,19 +105,19 @@ rtbWriteSpectrumFile(wls, spd, fullfile(rtbWorkingFolder('hints', hints),'D65.sp
nConditions = 3;
pixelSamples = ones(1,nConditions).*1024;
lightRotateAxis = [1 0 0;...
1 0 0;...
1 0 0]';
1 0 0;...
1 0 0]';
lightRotation = deg2rad([0 0 -25]);
cameraLocation = [-5 0 1;...
-6 0.77 4;...
-7 -3.5 6.18]'.*10^3;
-6 0.77 4;...
-7 -3.5 6.18]'.*10^3;
cameraTarget = [8 0 1;...
7 0.5 -0.65;...
7 -1.7 3.37]'.*10^3;
7 0.5 -0.65;...
7 -1.7 3.37]'.*10^3;
cameraUp = [0 0 1;...
0 0 1;...
0 0 1]';
0 0 1;...
0 0 1]';
lightSpectra = {'D65.spd','D65.spd','D65.spd'};
......@@ -124,11 +131,8 @@ values(:,5) = num2cell(cameraTarget, 1);
values(:,6) = num2cell(cameraUp, 1);
values(:,7) = lightSpectra;
% Write the parameters in a conditions file.
% Write the parameters in a conditions file.
conditionsFile = 'CrytekConditions.txt';
resourceFolder = rtbWorkingFolder( ...
'folderName', 'resources',...
'hints', hints);
conditionsPath = fullfile(resourceFolder, conditionsFile);
rtbWriteConditionsFile(conditionsPath, names, values);
......@@ -155,27 +159,27 @@ renderingsFolder = rtbWorkingFolder( ...
% Load in rendered data
for i = 1:nConditions
radianceData = load(radianceDataFiles{i});
photons = radianceData.multispectralImage;
oiName = sprintf('%s_%i',hints.recipeName,i);
% Create an oi
oi = oiCreate;
oi = initDefaultSpectrum(oi);
oi = oiSet(oi, 'photons', single(photons));
oi = oiSet(oi,'name',oiName);
vcAddAndSelectObject(oi);
% Save oi
% TODO: Save rendering parameters in oi?
save(fullfile(renderingsFolder,sprintf('oi%i',i)),'oi');
% Save RGB images
rgb = oiGet(oi,'rgb');
imwrite(rgb,sprintf('%s.png',oiName))
radianceData = load(radianceDataFiles{i});
photons = radianceData.multispectralImage;
oiName = sprintf('%s_%i',hints.recipeName,i);
% Create an oi
oi = oiCreate;
oi = initDefaultSpectrum(oi);
oi = oiSet(oi, 'photons', single(photons));
oi = oiSet(oi,'name',oiName);
vcAddAndSelectObject(oi);
% Save oi
% TODO: Save rendering parameters in oi?
save(fullfile(renderingsFolder,sprintf('oi%i',i)),'oi');
% Save RGB images
rgb = oiGet(oi,'rgb');
imwrite(rgb,sprintf('%s.png',oiName))
end
oiWindow;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment