• Assets

Predefined Material Parameters

By: SKY ENGINE AI
scroll down ↓to find out more

PredefinedMaterialParameters

In this case you will get familiar with PredefinedMaterialParameters file concept and how it is used in
SkyRenderer.

Agenda:

  • Predefined Material Parameters basics
  • Adding new materials to Predefined Material Parameters

Predefined Material Parameters basics

As described in MaterialSlots case, material slots are fields that can be fulfilled automatically by
MaterialSlotFiller with textures. Usually one can use file textures (like base_color, normal, roughness and other
maps) stored as images or Substance Archives (.sbsar), however it is possible to store the most common settings
of shaders as predefined materials.

Predefined Material Parameters file is a .json file consisting of materials.
Obligatory parts of a material are:

  • name - name of material, that will be assigned to corresponding material slots
  • type - shader type that will be assigned to the particular material

Optional parameters that are processed by any shader in SkyRenderer. To see available shaders' parameters check
documentation of each shader.

import json from skyrenderer.cases.utils import ObjectlessSceneComposer from skyrenderer.core.asset_manager.asset_manager import AssetsTypes scene_composer = ObjectlessSceneComposer(antialiasing_level=64) predefined_parameters_path = scene_composer.renderer_context.get_abs_path( file_path=scene_composer.renderer_context.material_slot_filler.PREDEFINED_MATERIAL_PARAMETERS_PATH, asset_type=AssetsTypes.NONE, ) scene_composer.logger.info(predefined_parameters_path) with predefined_parameters_path.open() as f: predefined_materials = json.load(f) head_predefined_materials = predefined_materials[:5] scene_composer.logger.info(f"\n{json.dumps(head_predefined_materials, indent=4)}")
2025-01-29 13:48:31,836 | skyrenderer.scene.renderer_context | INFO: Root paths: - root path: /dli/skyenvironment/skyrenderer/skyrenderer - assets path: /dli/mount/assets - config path: /dli/skyenvironment/skyrenderer/skyrenderer/config - gpu sources path: /dli/skyenvironment/skyrenderer/skyrenderer/optix_sources/sources - cache path: /dli/mount/cache - ptx cache path: compiled_ptx/ptx - ocio path: ocio_configs/aces_1.2/config.ocio 2025-01-29 13:48:31,866 | skyrenderer | INFO: /dli/mount/assets/renderer/predefined_material_parameters.json 2025-01-29 13:48:31,867 | skyrenderer | INFO: [ { "name": "default", "type (PBR, emissive, glass)": "PBR", "base_color (RGB 0-1 / hex)": "(0.5, 0.5, 0.5)", "alpha (0-1)": 1, "roughness (0-1)": 1, "metallic (0-1)": 0, "reflectivity (0-1)": 0, "tex_scale (any number)": 1 }, { "name": "MetallicVeryRough", "type (PBR, emissive, glass)": "", "base_color (RGB 0-1 / hex)": "(0.7, 0.7, 0.7)", "alpha (0-1)": "", "roughness (0-1)": "", "metallic (0-1)": 1, "reflectivity (0-1)": 1, "tex_scale (any number)": "" }, { "name": "BlackMetalRough", "type (PBR, emissive, glass)": "", "base_color (RGB 0-1 / hex)": "(0.1, 0.1, 0.1)", "alpha (0-1)": "", "roughness (0-1)": "", "metallic (0-1)": 1, "reflectivity (0-1)": 1, "tex_scale (any number)": "" }, { "name": "EmissionGreen", "type (PBR, emissive, glass)": "emissive", "base_color (RGB 0-1 / hex)": "(0, 1, 0)", "alpha (0-1)": "", "roughness (0-1)": "", "metallic (0-1)": "", "reflectivity (0-1)": "", "tex_scale (any number)": "" }, { "name": "MetallicRough", "type (PBR, emissive, glass)": "", "base_color (RGB 0-1 / hex)": "(0.7, 0.7, 0.7)", "alpha (0-1)": "", "roughness (0-1)": 0.3, "metallic (0-1)": 0.7, "reflectivity (0-1)": 0.2, "tex_scale (any number)": "" } ]

As visible in the logs, we have defined material such as "default".

We should expect MaterialSlotFiller to automatically assign to any material slot that is named "default"
a material with these parameters:
{
"name": "default",
"type (PBR, emissive, glass)": "PBR",
"base_color (RGB 0-1 / hex)": "(0.5, 0.5, 0.5)",
"alpha (0-1)": 1,
"roughness (0-1)": 1,
"metallic (0-1)": 0,
"reflectivity (0-1)": 0,
"tex_scale (any number)": 1
}

We expect material to be:

  • grey due to base_color set to (0.5, 0.5, 0.5)
  • opaque due to alpha set to 1
  • rough due to roughness set to 1
  • non-metallic due to metallic set to 0
  • non-reflective due to reflectivity set to 0

Adding new materials to Predefined Material Parameters

To add new material to PredefinedMaterialParameters, the only thing we need to do is to extend .json file with
configuration of new materials. We can do it or manually, or by dumping values with python. After saving a file
with set configuration, we may expect MaterialSlotFiller to load predefined materials according to provided
configuration.

Summary

In this section you have learnt:

  • PredefinedMaterialParameters is a .json file used to store configuration of the most commonly used materials.
  • Format in .json file is human-readable and easy to configure.