Materials
Each material has properties that affect:
- Reverb - rays lose energy on each bounce
- Ray Directions - rays change directions when bouncing
- Permeation - rays lose energy when passing through materials
There are 23 default materials for common materials like dirt, grass, concrete, metal, cloth, etc. You can customise these, as well as define your own materials.
Data Structure
The MaterialProperties class contains all data for one material.
public class MaterialProperties
{
// How much energy is lost on each bounce (0.0 to 1.0)
public float AbsorptionLF;
public float AbsorptionHF;
// Scattering strength. 0.0 has no scattering and 1.0 scatters
// up to 90 degrees from the reflected direction
public float Scattering;
// How much energy is lost in dB/m (0.0 or greater) when a
// ray passes through a primitive
public float TransmissionLF;
public float TransmissionHF;
// Percentage of energy lost when a ray passes through a
// flat primitive (0.0 to 1.0)
public float PlaneTransmissionLF;
public float PlaneTransmissionHF;
}
Materials can be updated via the GetMaterial and AddMaterial functions on a RaytracingContext object.
var dirt = context.GetMaterial(MaterialType.Dirt);
dirt.Scattering = 0.6f;
const int ALIEN = 1000;
var alienProperties = new MaterialProperties(0.5f, 0.6f, 0.7f, 4, 7, 0.1f, 0.2f);
var alienColour = new Color(255, 0, 255);
context.AddMaterial((MaterialType)ALIEN, alienProperties, alienColour);
// Tell the context that materials have been updated/created
context.MaterialsDirty = true;
context.MaterialsDirtymust be set to true after updating materials, and will cause all rays to be re-cast.
Notes:
- The first 1000 values (0 to 999) in
MaterialTypeare reserved, so set your custom material IDs from 1000 onwards - Contexts are automatically initialised with all default materials
- 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)
Validation
Materials will be validated when setting MaterialsDirty to true, and may throw an exception if:
- Any field is
NaNorInfinity - All
Absorption,ScatteringandPlaneTransmissionvalues must be in the range0.0f - 1.0f(inclusive) Transmissionvalues must be in the range0 - Float.Max(inclusive)
Default Material Properties
For every material:
PlaneTransmissionLFdefaults to0.1PlaneTransmissionHFdefaults to0.25
|Material|Absorption LF|Absorption HF|Scattering|Transmission LF|Transmission HF|Source| |---|---|---|---|---|---|---|---| |Brick|0.31|0.52|0.40|80|120|hard_surface| |Cloth|0.72|0.91|0.70|15|30|carpet_cotton| |Concrete|0.31|0.55|0.40|100|150|Concrete unpainted, rough finish| |Concrete Polished|0.06|0.12|0.10|110|160|Concrete sealed or painted| |Dirt|0.48|0.88|0.50|40|80|50mm soil depth| |Glass|0.08|0.12|0.05|60|100|Estimated| |Grass|0.71|0.93|0.80|20|40|100% density, 200mm depth| |Gravel|0.06|0.12|0.70|120|170|Estimated| |Gyprock|0.04|0.08|0.05|30|60|Estimated| |Ice|0.01|0.03|0.01|60|100|Estimated| |Leaf|0.71|0.91|0.80|10|25|60% vegetation coverage| |Marble|0.06|0.12|0.03|120|170|marble_floor| |Metal|0.05|0.02|0.01|150|250|Steel door| |Mud|0.56|0.82|0.50|50|90|150mm soil depth| |Rock|0.31|0.51|0.40|90|130|limestone_wall| |Sand|0.65|0.92|0.70|35|70|Sand (5cm thickness)| |Snow|0.65|0.92|0.70|25|50|Estimated from sand| |Tile|0.06|0.12|0.03|120|170|Estimated| |Tree|0.22|0.46|0.30|35|65|Vegetation attenuation study| |Water|0.06|0.12|0.10|60|100||Estimated| |Wood Indoor|0.12|0.30|0.10|30|60|plywood_thin| |Wood Outdoor|0.16|0.37|0.20|40|70|wood_16mm||