-
Notifications
You must be signed in to change notification settings - Fork 7
Materials
- tls_materials.mlx
- t_piIntro_material
- t_materials.m
- t_materials_properties Advanced
Each recipe has a slot where it stores a list of materials. This page is a walkthrough of some of the code in t_piIntro_material.m. The tutorial contains additional code for rendering all the images shown here, as well as illustrating other attributes of materials.
>> thisR.materials
ans =
struct with fields:
list: {[1×1 struct] [1×1 struct] [1×1 struct] [1×1 struct]}
inputFile_materials: '/Users/wandell/Documents/MATLAB/iset3d/data/V3/sphere/sphere_materials.pbrt'
lib: [1×1 struct]
outputfile: '/Users/wandell/Documents/MATLAB/iset3d/local/sphere/sphere_materials.pbrt'
You can print the list of materials stored in a recipe using
>> thisR = piRecipeDefault('scene name', 'SimpleScene');
Read 6 materials.
Read 1 textures.
***Scene parsed.
>> thisR.get('materials print');
Scene materials: SimpleScene
-------------------------------
Name [Type]
-------------------------------
1: uber_blue: [ uber ]
2: uber: [ uber ]
3: BODY: [ uber ]
4: GLASS: [ glass ]
5: mirror: [ uber ]
6: Material: [ uber ]
-------------------------------
An individual material is defined by a structure that defines the parameters of that instance of the material. This is an instance of a glass material.
>> thisR.get('materials','GLASS')
ans =
struct with fields:
name: 'GLASS'
fluorescence: [1×1 struct]
concentration: [1×1 struct]
type: 'glass'
kr: [1×1 struct]
kt: [1×1 struct]
eta: [1×1 struct]
uroughness: [1×1 struct]
vroughness: [1×1 struct]
remaproughness: [1×1 struct]
>>
Each asset is associated with a particular material in the recipe list.
>> thisR.get('asset','Sphere_O','material')
ans =
struct with fields:
name: 'BODY'
fluorescence: [1×1 struct]
concentration: [1×1 struct]
type: 'uber'
kd: [1×1 struct]
ks: [1×1 struct]
kr: [1×1 struct]
kt: [1×1 struct]
roughness: [1×1 struct]
uroughness: [1×1 struct]
vroughness: [1×1 struct]
eta: [1×1 struct]
opacity: [1×1 struct]
remaproughness: [1×1 struct]
This tutorial starts with the simple sphere, adds an environmental light, and then changes the sphere from a matte surface, to glass, and then a mirror.
sceneName = 'sphere';
thisR = piRecipeDefault('scene name',sceneName);
% thisR = piLightAdd(thisR, 'type', 'point', 'camera coordinate', true);
% Create an environmental light source (distant light) that is a 9K
% blackbody radiator.
distLight = piLightCreate('new dist light',...
'type', 'distant',...
'spd', [9000 0.001],...
'cameracoordinate', true);
thisR.set('light','add', distLight);
thisR.set('film resolution',[200 150]);
thisR.set('rays per pixel',32);
thisR.set('fov',45);
thisR.set('nbounces',5);
% Render
piWrite(thisR);
scene = piRender(thisR,'render type','radiance');
scene = sceneSet(scene,'name',sprintf('Uber %s',sceneName));
sceneWindow(scene);
We then change the material, which is a matte white, to a new spectral reflectance
redMatte = piMaterialCreate('redMatte', 'type', 'matte');
% Add the material to the materials list
thisR.set('material', 'add', redMatte);
%% Set the spectral reflectance of the matte material to be very red.
wave = 400:10:700;
reflectance = ones(size(wave));
reflectance(1:17) = 0;
% Put it in the PBRT spd format.
spdRef = piMaterialCreateSPD(wave, reflectance);
% Store the reflectance as the diffuse reflectance of the redMatte
% material
thisR.set('material', redMatte, 'kd value', spdRef);
%% Set the material
assetName = '001_Sphere_O';
thisR.set('asset',assetName,'material name',redMatte.name);
%% Let's have a look
piWrite(thisR);
scene = piRender(thisR,'render type','radiance');
scene = sceneSet(scene,'name',sprintf('Red %s',sceneName));
sceneWindow(scene);
After adding an environmental light, which creates the background image, and scaling the sphere size, we change the sphere material to glass.
glassName = 'glass';
glass = piMaterialCreate(glassName, 'type', 'glass');
thisR.set('material', 'add', glass);
thisR.set('asset', '001_Sphere_O', 'material name', glassName);
And then we change it to a mirror, shifting the camera position a little along the way.
% Where is the sphere ...
assetPosition = thisR.get('asset','001_Sphere_O','world position');
thisR.set('to',assetPosition);
thisR.set('from',assetPosition + [0 100 -400]); % Set the camera from position a little higher and closer
mirrorName = 'mirror2';
mirror = piMaterialCreate(mirrorName, 'type', 'mirror');
thisR.set('material', 'add', mirror);
thisR.set('asset', '001_Sphere_O', 'material name', mirrorName);
ISET3d development is led by Brian Wandell's Vistalab group at Stanford University and supported by contributors from other research institutions and industry.
- Introduction
- Installation
- Workflow
- Camera
- Assets
- Materials Overview
- Textures
- Lights
- Rendering
- Scene data
- Programming overview
- [General Notes on moving to v4]
- Dockerized pbrt-v4 on the GPU