Each material has absorption, scattering and transmission properties that affects how energy propagates throughout the environment.
Absorption and scattering affect how much energy a ray loses when reflecting off a surface (for occlusion and reverb), and transmission affects how much energy is lost when rays pass through objects (permeation).
There are [[MaterialType|18 presets]] for common materials like dirt, grass, concrete, metal, cloth. You can customise these and define your own materials.
## Data Structure
The [[MaterialProperties]] class contains all data for one material.
```cs
public class MaterialProperties
{
public float AbsorptionLF;
public float AbsorptionHF;
public float ScatteringLF;
public float ScatteringHF;
public float TransmissionLF;
public float TransmissionHF;
}
```
Materials can be accessed via the [[MaterialSettings|material]] property on a [[RaytracingContextSettings]] object:
```cs
var settings = new RaytracingContextSettings();
var ice = settings.materials.properties[MaterialType.Ice];
ice.AbsorptionLF = 0.5f;
// Create a context
var context = new RaytracingContext(settings);
```
> `settings.materials` is automatically initialised with all 18 default materials
You can also modify materials at runtime:
```cs
var dirt = context.GetMaterial(MaterialType.Dirt);
dirt.ScatteringHF = 0.6f;
```
> You can update materials at any time, but your changes will only apply the next time raytracing occurs (i.e. the current background threads won't receive this change)
## Creating Custom Materials
Create a custom material by adding a new entry to `settings.materials.properties`. Materials cannot be created at runtime.
The first 1000 values (0 to 999) in `MaterialType` are reserved, so set your custom material IDs from 1000 onwards:
```cs
var settings = new RaytracingContextSettings();
// Create a new material type
int alien = 1000;
settings.materials.properties[(MaterialType)alien] = new(0.3f, 0.2f, 0.8f, 0.9f, 40, 60);
// Set an RGB colour for the debug rendering window
settings.materials.colours[(MaterialType)alien] = new Color(255, 0, 255);
// Create a context
var context = new RaytracingContext(settings);
// Create a primitive using the new material type
context.AddPrimitive(new PrismPrimitive()
{
material = (MaterialType)alien
...
});
```
## Validation
Materials will be validated when creating a new [[RaytracingContext]]:
- All absorption/scattering values must be in the range `0-1` (inclusive) and not be `NaN` or `Infinity`
- Transmission values must be in the range `0 - Float.Max` and not be `NaN` or `Infinity`
- All custom materials must have a colour defined
## Default Material Properties
The absorption and scattering properties represent the percentage of energy lost on each bounce. The transmission properties represent how much energy is lost when a ray travels through an object, measured in dB/meter.
|Material|Absorption LF|Absorption HF|Scattering LF|Scattering HF|Transmission LF|Transmission HF|Source|
|---|---|---|---|---|---|---|---|
|Brick|0.02|0.05|0.30|0.50|80|120|[hard_surface](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|
|Cloth|0.31|0.54|0.60|0.80|15|30|[carpet_cotton](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|
|Concrete|0.02|0.10|0.30|0.50|100|150|[Concrete unpainted, rough finish](https://www.acoustic-supplies.com/absorption-coefficient-chart/)|
|Concrete Polished|0.01|0.02|0.05|0.10|110|160|[Concrete sealed or painted](https://www.acoustic-supplies.com/absorption-coefficient-chart/)|
|Dirt|0.13|0.71|0.40|0.60|40|80|[50mm soil depth](https://www.researchgate.net/profile/Hong-Seok-Yang/publication/258455034_Random-Incidence_Absorption_and_Scattering_Coefficients_of_Vegetation/links/5c43281992851c22a3812440/Random-Incidence-Absorption-and-Scattering-Coefficients-of-Vegetation.pdf)|
|Grass|0.03|0.30|0.70|0.90|20|40|[100% density, 200mm depth](https://www.researchgate.net/profile/Hong-Seok-Yang/publication/258455034_Random-Incidence_Absorption_and_Scattering_Coefficients_of_Vegetation/links/5c43281992851c22a3812440/Random-Incidence-Absorption-and-Scattering-Coefficients-of-Vegetation.pdf)|
|Ice|0.008|0.025|0.05|0.10|60|100|Estimated|
|Leaf|0.03|0.14|0.70|0.90|10|25|[60% vegetation coverage](https://www.researchgate.net/profile/Hong-Seok-Yang/publication/258455034_Random-Incidence_Absorption_and_Scattering_Coefficients_of_Vegetation/links/5c43281992851c22a3812440/Random-Incidence-Absorption-and-Scattering-Coefficients-of-Vegetation.pdf)|
|Marble|0.01|0.02|0.05|0.10|120|170|[marble_floor](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|
|Metal|0.05|0.02|0.02|0.05|150|250|[Steel door](https://www.researchgate.net/figure/Material-list-and-sound-absorption-coefficients-Christensen-2002_tbl1_228850689)|
|Mud|0.27|0.56|0.40|0.60|50|90|[150mm soil depth](https://www.researchgate.net/profile/Hong-Seok-Yang/publication/258455034_Random-Incidence_Absorption_and_Scattering_Coefficients_of_Vegetation/links/5c43281992851c22a3812440/Random-Incidence-Absorption-and-Scattering-Coefficients-of-Vegetation.pdf)|
|Rock|0.02|0.02|0.30|0.50|90|130|[limestone_wall](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|
|Sand|0.12|0.60|0.60|0.80|35|70|[Sand (5cm thickness)](https://www.researchgate.net/figure/Reflection-and-absorption-coefficient-of-sand-Sample-thickness-is-equal-to-5-cm_fig1_236663318)|
|Snow|0.12|0.60|0.60|0.80|25|50|Estimated from sand|
|Tree|0.02|0.23|0.20|0.30|35|65|[Vegetation attenuation study](https://www.researchgate.net/publication/271394333_Sound_attenuation_through_absorption_by_vegetation)|
|Wood Indoor|0.06|0.21|0.10|0.20|30|60|[plywood_thin](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|
|Wood Outdoor|0.07|0.12|0.10|0.20|40|70|[wood_16mm](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.materials.database.html)|