r.RayTracing.AmbientOcclusion.EnableMaterials

r.RayTracing.AmbientOcclusion.EnableMaterials

#Overview

name: r.RayTracing.AmbientOcclusion.EnableMaterials

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.RayTracing.AmbientOcclusion.EnableMaterials is to control whether materials are enabled for ray-traced ambient occlusion in Unreal Engine 5’s rendering system. This setting is specifically related to the ray tracing subsystem and its implementation of ambient occlusion.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically in the ray tracing ambient occlusion implementation. It’s referenced in the file “RayTracingAmbientOcclusion.cpp”, which suggests it’s a core part of the ray tracing ambient occlusion feature.

The value of this variable is set through a console variable (CVarRayTracingAmbientOcclusionEnableMaterials) with a default value of 0, meaning materials are disabled by default for ray-traced ambient occlusion. This can be changed at runtime through console commands or programmatically.

The associated variable CVarRayTracingAmbientOcclusionEnableMaterials interacts directly with r.RayTracing.AmbientOcclusion.EnableMaterials. It’s used to retrieve the current value of the setting and apply it in the rendering pipeline.

Developers should be aware that enabling materials for ray-traced ambient occlusion can have performance implications. It’s disabled by default, likely for performance reasons, so enabling it should be done with consideration for the performance cost.

Best practices when using this variable include:

  1. Only enable it when necessary for visual quality improvements.
  2. Test thoroughly to ensure performance remains acceptable when enabled.
  3. Consider providing user options to toggle this feature, allowing end-users to balance visual quality and performance.

Regarding the associated variable CVarRayTracingAmbientOcclusionEnableMaterials:

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingAmbientOcclusion.cpp:55

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingAmbientOcclusionEnableMaterials(
	TEXT("r.RayTracing.AmbientOcclusion.EnableMaterials"),
	0,
	TEXT("Enables "),
	ECVF_RenderThreadSafe
);

bool ShouldRenderRayTracingAmbientOcclusion(const FViewInfo& View)

#Associated Variable and Callsites

This variable is associated with another variable named CVarRayTracingAmbientOcclusionEnableMaterials. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingAmbientOcclusion.cpp:54

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingAmbientOcclusionEnableMaterials(
	TEXT("r.RayTracing.AmbientOcclusion.EnableMaterials"),
	0,
	TEXT("Enables "),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingAmbientOcclusion.cpp:173

Scope: file

Source code excerpt:

	FRayTracingAmbientOcclusionRGS::FPermutationDomain PermutationVector;
	PermutationVector.Set<FRayTracingAmbientOcclusionRGS::FEnableTwoSidedGeometryDim>(CVarRayTracingAmbientOcclusionEnableTwoSidedGeometry.GetValueOnRenderThread() != 0);
	PermutationVector.Set<FRayTracingAmbientOcclusionRGS::FEnableMaterialsDim>(CVarRayTracingAmbientOcclusionEnableMaterials.GetValueOnRenderThread() != 0);
	TShaderMapRef<FRayTracingAmbientOcclusionRGS> RayGenerationShader(GetGlobalShaderMap(FeatureLevel), PermutationVector);
	ClearUnusedGraphResources(RayGenerationShader, PassParameters);

	FIntPoint RayTracingResolution = View.ViewRect.Size();
	GraphBuilder.AddPass(
		RDG_EVENT_NAME("AmbientOcclusionRayTracing(SamplePerPixels=%d) %dx%d", RayTracingConfig.RayCountPerPixel, RayTracingResolution.X, RayTracingResolution.Y),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingAmbientOcclusion.cpp:189

Scope (from outer to inner):

file
lambda-function

Source code excerpt:

		// TODO: Provide material support for opacity mask
		FRayTracingPipelineState* Pipeline = View.RayTracingMaterialPipeline;
		if (CVarRayTracingAmbientOcclusionEnableMaterials.GetValueOnRenderThread() == 0)
		{
			// Declare default pipeline
			FRayTracingPipelineStateInitializer Initializer;
			Initializer.MaxPayloadSizeInBytes = GetRayTracingPayloadTypeMaxSize(ERayTracingPayloadType::RayTracingMaterial);
			FRHIRayTracingShader* RayGenShaderTable[] = { RayGenerationShader.GetRayTracingShader() };
			Initializer.SetRayGenShaderTable(RayGenShaderTable);