Contents

CustomMaterial.SurfaceShader

The custom material’s surface shader function.

Declaration

struct SurfaceShader

Overview

Custom materials work together with a surface shader function to render entities. The CustomMaterial properties related to rendering, such as baseColor and normal, are available in the surface shader function, but RealityKit doesn’t use them directly.

Instead, the material’s surface shader function allows you to calculate or specify all the material parameters that RealityKit uses to render your entity, such as baseColor, normal, and roughness. RealityKit’s fragment shader calls your surface shader function once for each pixel it renders.

Here’s a simple example of a surface shader that sets the entity’s base color:

#include <metal_stdlib>
#include <RealityKit/RealityKit.h>

// Specify the current default namespace as metal so that it's not
// necessary to prefix Metal Standard Library symbols.
using namespace metal;

[[visible]] void mySurfaceShader(realitykit::surface_parameters params)
{
    // Set the base color
    params.surface().set_base_color(half3(1.0, 0.5, 0.5));
}

For more information on creating custom materials and writing shader functions, see Modifying RealityKit rendering using custom materials.

Topics

Creating surface shader objects

Accessing surface shader properties

Initializers

See Also

Shaders