Theme:

Material

The global Material class is a custom material class which is used by default within Unia's rendering pipeline.


const props = {
    name: String,
    side: U.FrontSide or U.BackSide or U.DoubleSide,
    opacity : 0-1,
    transparent: true/false,
    roughness: 0-1,
    metalness: 0-1
    lighting: 0-1, // 0 is flat shading, 1 is PBR
    alphaTest: 0-1,
    darkTint: {r: 1, g: 1, b: 1}, // masked materials, AO and cast shadows
    darkTintStrength: 0-2, // default 1
    maskedLightness: 0-2, // neutral extra diffuse light for masked materials, default 0
    maskedHighlightSoftness: 0-1, // roll off bright masked highlights, default 0
    transmissionStrength: 0-2, // static masked foliage backlighting, default 0 (off)
    flipY: true/false, // whether to flip the map side vertical
    map: U.Texture,
    normalMap: U.Texture,
    envMap: U.Texture,
    color: U.Color or hex string e.g. '#FF0F0A'
}

object.material = new Material({color: '#ffaabbcc', lighting: 0.5})

to set make an object use a new material use:

object.setMaterial(someNewMaterial);

to update an material after changing any properties use:

object.material.lighting = 0.75;
object.material.transparent = true;
object.material.opacity = 0.5;
object.material.map = someTexture;

// use:
object.material.update();

Materials are assigned to one of three render passes. alphaTest > 0 takes precedence and selects the masked pass, transparent === true selects the blended transparent pass, and all other materials use the opaque pass. Masked materials write depth and discard samples below the cutoff, which is intended for foliage, grass, hair cards, fences, and similar cutout surfaces. Their alpha cutoff is also applied to static shadows and reflection captures.

Static masked materials (alphaTest > 0) can set darkTint with RGB components from 0 to 1. It defaults to white and colors areas darkened by ambient occlusion or cast shadows. darkTintStrength defaults to 1; higher values can introduce the selected hue into dark areas even if the base texture has little of that color. These controls are available in the material editor.

maskedLightness adds neutral diffuse light to a masked material, regardless of surface normal or sky-light colour. The default 0 preserves existing lighting. The contribution is affected by ambient occlusion and the masked dark tint. maskedHighlightSoftness rolls off bright masked highlights when skyLightBrightness is above 1. It scales RGB channels together to preserve the texture's hue and affects only values near the display limit. Its default 0 leaves existing masked materials unchanged.

alphaTest defaults to 0. Scene serialization always writes a finite value in the 0..1 range, so older materials that do not define it are saved as 0.

Static masked materials can opt into thin-leaf backlighting with transmissionStrength (0..2, default 0). The main masked shader uses leaf albedo and a view-dependent forward-scattering lobe, strongest when viewing a backlit leaf toward the sun. Transmission follows directional sky-light color and brightness, shadow-map visibility when shadows are enabled, and the existing AO attenuation. It needs no additional leaf textures or transparency and does not simulate thickness or multiple scattering. Shadow visibility has the same cascade coverage as masked diffuse lighting; separate reflection-capture shaders do not evaluate transmission. Call material.update() after changing the strength.

For the main batched mesh, side uses the three.js values: 0 (FrontSide, the default), 1 (BackSide), or 2 (DoubleSide). After changing it, call material.update(). Opaque objects are grouped by side and drawn with hardware culling; they share the same vertex and index buffers. Transparent objects retain their depth order and switch pipelines between consecutive groups with different sides. Back faces use inverted shading normals. The same side selection applies to static shadows and reflections. The separate skinned mesh renderer retains its existing side behavior.

You can still use other standard U materials but they will be automatically convered to use this class.

material.planarReflectionId

Set to an ID returned by world.addPlanarReflection(position, options) to sample that world-space plane's reflection. Set to -1 to disable planar sampling. Call material.update() after changing it. An undefined value preserves legacy mesh-based registration. See Lighting for creation, placement, updates and cleanup. This property supports general unmasked mesh materials and is copied when cloning a material.