Skip to content

Materials

David Cardinal edited this page Oct 14, 2021 · 35 revisions

Relevant tutorials

  • tls_materials.mlx
  • t_piIntro_material
  • t_materials.m
  • t_materials_properties Advanced

Advanced materials


Material

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]

Example (t_piIntro_material.m)

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);

Clone this wiki locally