A raytracing context is a standalone world, composed of: - many [[raytraced-audio/v110/Primitives|Primitives]] (spheres, prisms, etc) - many [[raytraced-audio/v110/Emitters|Emitters]] (3D positions that cast rays and can be discovered by other emitters) Settings can be customised at any time, either when creating a context or at runtime: ```cs // Customise when creating var context = new RaytracingContext() { WorldPosition = new Vector3F(0), WorldSize = new Vector3F(100), OcclusionRayCount = 500, OcclusionBounceCount = 4, }; // Customise at runtime context.WorldSize = new Vector3F(500); ``` ## Settings List ```cs /// <summary> /// A custom logging callback. Defaults to <see cref="Console.WriteLine()"/> /// </summary> public Action<string> LogCallback; /// <summary> /// Whether to log memory allocation warnings /// </summary> public bool LogMemoryAllocationWarnings; /// <summary> /// The number of work items to split trails across for load balancing. A higher workItemCount helps evenly distribute work across all threads. /// </summary> /// <exception cref="ArgumentException">Thrown when the value is less than 1</exception> public int WorkItemCount; /// <summary> /// The maximum amount of threads that can run at any one time /// </summary> /// <exception cref="ArgumentException">Thrown when the value is less than 1</exception> public int MaximumConcurrencyLevel; /// <summary> /// The maximum number of grouped EAX reverb properties created for all emitters. Higher values increase accuracy but are more expensive to run. /// </summary> /// <exception cref="ArgumentException">Thrown when the value is less than 2</exception> public int MaximumGroupedEAXCount; /// <summary> /// Inverse speed of sound in seconds per meter. Defaults to 1.0f / 343.0f. Affects reverb calculation /// </summary> /// <exception cref="ArgumentException">Thrown when the value contains NaN or Infinity</exception> public float SpeedOfSound; /// <summary> /// Gets meters per world unit. Affects air absorption and reverb calculation. /// <exception cref="ArgumentException">Thrown when the value is less than or equal to 0, or contains NaN or Infinity</exception> /// </summary> public float MetersPerUnit; /// <summary> /// Low-frequency reference (Hz) for air absorption, reverb, and material scattering /// </summary> /// <exception cref="ArgumentException">Thrown when the value is less than or equal to 0, or contains NaN or Infinity</exception> public float ReferenceFrequencyLF; /// <summary> /// High-frequency reference (Hz) for air absorption, reverb, and material scattering /// </summary> /// <exception cref="ArgumentException">Thrown when the value is less than or equal to 0, or contains NaN or Infinity</exception> public float ReferenceFrequencyHF; /// <summary> /// Whether <see cref="Emitter"/>s outside the world have 0 occlusion/permeation energy (true) or maximum energy (false). /// </summary> public bool EmittersOutsideTheWorldAreMuffled; /// <summary> /// Air absorption settings. Set to null to disable air absorption. /// </summary> /// <exception cref="ArgumentException">Thrown when value validation fails</exception> public AirAbsorptionSettings AirAbsorption; /// <summary> /// Custom formulas for calculating EAX properties (diffusion, density, etc). Set to null to use default formulas. /// </summary> public CustomEAXFormulas CustomEAXFormulas; /// <summary> /// The minimum bounds of the world. <br /> /// <see cref="Emitter"/>s outside the world will not be raytraced, and <see cref="Primitive"/>s that are fully outside these bounds will not affect raytracing. /// </summary> /// <exception cref="ArgumentException">Thrown when worldPosition is NaN or Infinity</exception> public Vector3F WorldPosition; /// <summary> /// The size of the world. <br /> /// <see cref="Emitter"/>s outside the world will not be raytraced, and <see cref="Primitive"/>s that are fully outside these bounds will be ignored. /// </summary> /// <exception cref="ArgumentException">Thrown when worldSize is NaN, Infinity, or less than or equal to (0, 0, 0)</exception> public Vector3F WorldSize; /// <summary> /// Gets the properties for a specific material type. You must set context.materialsDirty = true; when editing materials. /// </summary> public MaterialProperties GetMaterial(MaterialType type); // The following settings are only available in debug builds, and only affect rendering /// <summary> /// Whether to render the raytracing scene in a separate window. Only one context can have rendering enabled /// </summary> public bool RenderingEnabled; /// <summary> /// Gets the debug rendering colour for a specific material type /// </summary> public Color GetMaterialColor(MaterialType type); /// <summary> /// Sets the debug rendering colour for a specific material type /// </summary> public void SetMaterialColor(MaterialType type, Color colour); } ``` ## WorkItemCount This setting controls how raytracing work is divided across multiple background threads. If you have 8 threads, it seems logical to split the work into 8 work items (one for each thread). However some threads might finish earlier than others. To prevent threads from idling while other threads work, you can divide the raytracing work into smaller work items. To do this, set `workItemCount` to a number higher than `maximumConcurrencyLevel`. For example, if you have: - `trailRayCount` = 1024 - `workItemCount` = 128 - `maximumConcurrencyLevel` = 8 This means that each work item will contain 1024 / 128 = 8 trails, and the threads have a pool of 128 work items to choose from. ## AirAbsorption There is an in-built air absorption formula based on humidity, temperature and pressure. You can adjust each value via this `airAbsorption` object. You can also provide a custom formula for air absorption. Read more: [[raytraced-audio/v110/Formulas/Air Absorption|Air Absorption]]. ## Materials Customise absorption, scattering and transmission values for existing materials, or create new materials. Read more: [[raytraced-audio/v110/Materials|Materials]] ## CustomEaxFormulas This class provides custom formulas for calculating EAX reverb properties. Read more: [[raytraced-audio/v110/Formulas/Custom EAX Formulas|Custom EAX Formulas]]