API reference

SceneMaterial

SceneMaterial

class SceneMaterial
Represents a material used for rendering SceneMeshes. SceneMaterials are created from SceneTextures and can also be generated with custom shaders via SceneMaterial.custom().
SceneMaterial takes image content via SceneTexture and opens up options to modify its display prior to rendering. This includes:
  1. AlphaMode, which is how the renderer handles transparency.
  2. Supplying a shader, default is SceneMaterial.PHYSICALLY_BASED_SHADER
  3. If the default SceneMaterial.PHYSICALLY_BASED_SHADER is used, the inputs to the shader can be modified with functions like SceneMaterial.setRoughness()
  4. If a custom shader is used, the setAttribute() and setTexture() functions exist to update its input.
Example usage: Use a Drawable from the resources directory. Scale the Material by a factor of 5 and add a adjust the roughness.
SceneMaterial(SceneTexture(getDrawable(R.drawable.Grass))).apply {
             setRepeat(5f, 5f, 0f, 0f)
             setRoughness(0.7f)
            }
Example usage: Applying a custom shader named "grassShader" ("grassShader" must exist in shaders directory). Passes in a custom color and Texture to be compute a shader.
customMaterial =
  SceneMaterial.custom(
          "grassShader",
          arrayOf<SceneMaterialAttribute>(
              SceneMaterialAttribute("color", SceneMaterialDataType.Vector4),
              SceneMaterialAttribute("textureA", SceneMaterialDataType.Texture2D),
          ))
      .apply {
        setAttribute("color", Vector4(1f, 0f, 0f, 1f))
        setTexture("textureA", SceneTexture(getDrawable(R.drawable.Grass)))
      }

Constructors

NameSummary
SceneMaterial
constructor(texture: SceneTexture, alphaMode: AlphaMode = AlphaMode.OPAQUE, shader: String = "")

Creates a material with the specified texture and alpha mode.

Types

NameSummary
Companion
object Companion

Properties

NameSummary
handle
var handle: Long
params
var params: Array<SceneMaterialAttribute>?
texture
var texture: SceneTexture?
textures
var textures: <Error class: unknown class>

Functions

NameSummary
destroy
fun destroy()
fun getAttributeIndex(name: String): Int

Gets the index of a named attribute in a custom shader.
setAlbedoColor
fun setAlbedoColor(color: <Error class: unknown class>)

Sets the albedo (base color) for this material.
setAlbedoTexture
fun setAlbedoTexture(texture: SceneTexture?)

Sets the primary albedo (base color) texture for this material.
setAttribute
fun setAttribute(index: Int, v: Vector4)

Sets a Vector4 attribute value by index for a custom shader.



fun setAttribute(index: Int, v: SceneTexture?)

Sets a texture attribute by index for a custom shader.



fun setAttribute(name: String, v: Vector4)

Sets a Vector4 attribute value by name for a custom shader.



fun setAttribute(name: String, v: SceneTexture?)

Sets a texture attribute by name for a custom shader.
setBlendMode
fun setBlendMode(blendMode: BlendMode)

Sets the blend mode for this material. By default, custom materials are opaque.
setColorWrite
fun setColorWrite(mask: Int)

Sets which color channels should be written to the framebuffer. By default, a custom material writes all channels.
setDepthTest
fun setDepthTest(depthTest: DepthTest)

Sets the depth testing function for this material. By default, faces aren’t shaded if occluded by other geometry.
setDepthWrite
fun setDepthWrite(depthWrite: DepthWrite)

Sets whether this material should write to the depth buffer. By default, custom materials write depth.
setMetalRoughness
fun setMetalRoughness(roughness: Float)

Configures the material as metallic with the specified roughness physically-based rendering.
setRepeat
fun setRepeat(scaleX: Float, scaleY: Float, offsetX: Float, offsetY: Float)

This controls how the texture is tiled and positioned on the surface.
setRoughness
fun setRoughness(roughness: Float)

Configures the material as non-metallic with the specified roughness for physically-based rendering.
setRoughnessMetallicness
fun setRoughnessMetallicness(roughness: Float, metallicnesss: Float)

Sets both roughness and metallicness properties for physically-based rendering.
setSidedness
fun setSidedness(sidedness: MaterialSidedness)

Sets whether faces should be rendered on one side, both sides, or neither. By default, only the front faces are rendered.
setSortOrder
fun setSortOrder(sortOrder: SortOrder)

Sets the render sort order for this material. By default, custom materials have opaque sort order.
setStereoMode
fun setStereoMode(mode: StereoMode)

Sets the stereo rendering mode for this material. This can allow you to display sterescopic 3D media.
setTexture
fun setTexture(binding: String, texture: SceneTexture)

Sets the texture for a named attribute in a custom shader.
setUnlit
fun setUnlit(isUnlit: Boolean)

Sets whether this material should be rendered without lighting calculations.

Companion

object Companion

Properties

NameSummary
HOLE_PUNCH_PANEL_SHADER
val HOLE_PUNCH_PANEL_SHADER: String

Shader similar to HOLE_PUNCH_SHADER but instead factors in the transparency of the base color (panel). This shader will likely need to be used if you have transparency in your panel so we don’t have to punch holes on the areas that are transparent. If you are setting this on your panel, you will likely need to use forceSceneTexture = true.
HOLE_PUNCH_SHADER
val HOLE_PUNCH_SHADER: String

Hole punch shader to indescriminately punch holes on the geometry. Hole punching is used to cut out space for layers to be rendered.
PHYSICALLY_BASED_SHADER
val PHYSICALLY_BASED_SHADER: String

Our default physically based renderer. This is complete with lighting and IBL. Has the highest graphical fidelity but is also the most compute intensive
TEXTURED_UNLIT_SHADER
val TEXTURED_UNLIT_SHADER: String
UNLIT_SHADER
val UNLIT_SHADER: String

Functions

NameSummary
custom
fun custom(shader: String, params: Array<SceneMaterialAttribute>, vertexLayout: VertexLayout = VertexLayout.COMPACT): SceneMaterial

Create a custom material with a custom shader and params. Learn more about how to create custom shader materials here: https://developers.meta.com/horizon/documentation/spatial-sdk/spatial-sdk-custom-shaders#custom-materials
depthOnly
fun depthOnly(isPrePass: Boolean): SceneMaterial

Creates a material that only writes to the depth buffer.
passthrough
fun passthrough(): SceneMaterial

Creates a material for rendering passthrough content.