Skip to main content
Version: 0.11.0

UeMaterial

The UeMaterial class defines the visual appearance of a UeMesh, including color, transparency, shading, blending, lighting, and custom shader uniforms and textures.

It supports GPU-side configurations and automatic uniform population for lights and cameras.

Constructor​

new UeMaterial(data = {})

Properties​

PropertyTypeDefaultDescription
isMaterialbooleantrueIdentifies this object as a material
idnumber(auto-generated)Incremental object ID (shared counter with objects)
uuidstring(auto-generated)Resource UUID
typestring"Material"Object type
namestring""Object name (empty string by default)
visiblebooleantrueWhether to use this material (set the shader)
transparentbooleanfalseWhether to enable transparency
opacitynumber1Opacity (used in shaders)
sidenumbercull_counterclockwiseWhich side to render (cull_*)
depthTestbooleantrueEnables depth testing
depthWritebooleantrueEnables writing to depth buffer
depthFuncnumbercmpfunc_lessequalComparison function for depth testing
forceSinglePassbooleanfalsePrevents double-pass rendering for transparent materials
alphaTestnumber0Alpha test reference value
colorWritebooleantrueWhether to write to the color buffer
blendingbooleanfalseWhether to enable blending
blendEquationnumberbm_eq_addBlend equation for color
blendEquationAlphanumberbm_eq_addBlend equation for alpha
blendSrcnumberbm_src_alphaBlend source factor (RGB)
blendDstnumberbm_inv_src_alphaBlend destination factor (RGB)
blendSrcAlphanumberbm_oneBlend source factor (alpha)
blendDstAlphanumberbm_inv_src_alphaBlend destination factor (alpha)
shadershadersh_ue_standardThe shader program to use
uniformsobject{}Custom uniforms to pass to the shader
lightsnumber2Number of supported lights (0 to disable lighting)
shadowQualityenumUE_SHADOW_QUALITY.HIGHShadow quality level for this material (LOW/MEDIUM/HIGH)
texturesobject{map, normalMap, ...}Maps for base color, normal, roughness, etc.
wireframebooleanfalseWhether to render the mesh as wireframe (pr_linelist)
userDatastructA struct where to safely place custom related data for this entity

Textures​

Textures are assigned via the textures object. By default, most textures are undefined. When a texture is undefined, the engine automatically:

  1. Skips binding the texture to the GPU.
  2. Sets a shader flag (e.g., u_ueHasMap) to 0.
  3. The shader uses optimized logic to avoid sampling the texture, using default values instead (e.g., white for the base map, a neutral normal for the normal map).

This approach reduces memory usage and improves GPU performance by avoiding unnecessary texture operations.

  • map: Base diffuse texture.
  • normalMap: Normal mapping.
  • ormMap: Packed texture for Occlusion, Roughness, and Metalness (R=AO, G=Roughness, B=Metalness).
  • emissiveMap: Emissive light contribution.
  • displacementMap: Displacement mapping for height effects.

Each texture must be a UeTexture.

Uniforms​

Uniforms must be defined as objects like:

uniforms: {
myFloat: { type: "float", value: 1.0 },
myVec3: { type: "vec3", value: [1, 0, 0] },
}

Supported types:

  • "float" — single float

  • "vec2" / "vec3" / "vec4"

  • "mat4" — 4x4 matrix (set manually)

  • "array" — float array

  • "buffer" — raw GPU float buffer

Automatically included uniforms:

  • ueModelPosition (only for sprite objects)
  • ueWorldMatrix (Current object's world matrix)
  • sceneData (Array packing ambient light, camera position, and time)
  • materialData (Vec3 packing tone mapping settings)
  • mapFlags (Vec4 packing boolean flags for map, alphaMap, ormMap, normalMap)
  • mapFlags2 (Vec4 packing boolean flags for emissiveMap, displacementMap)
  • boneMatrices / numBones (For mesh skinning)
  • ueDirLight* / uePointLight* / ueSpotLight*
  • ueDirShadowMatrix, ueDirShadowEnabled, ueReceiveShadow
  • ueDirShadowQuality, ueDirShadowTexelSize
  • uePointShadowEnabled, uePointShadowFar, uePointShadowNear, uePointShadowPos
  • ueSpotShadowEnabled, ueSpotShadowMatrix, ueSpotShadowFar, ueSpotShadowNear, ueSpotShadowPos
  • s_dirShadowMap, s_pointShadowMap, s_spotShadowMap

Shadow Quality​

Materials support shadow rendering with configurable quality levels via the shadowQuality property:

material.shadowQuality = UE_SHADOW_QUALITY.HIGH;

Available quality levels:

Quality LevelValueDescriptionSample Count
UE_SHADOW_QUALITY.LOW0Hard shadows, no PCF filtering1 sample
UE_SHADOW_QUALITY.MEDIUM1Soft shadows with light PCF filtering4 samples
UE_SHADOW_QUALITY.HIGH2Very soft shadows with full PCF16 samples

Higher quality settings provide smoother shadow edges but require more GPU samples per pixel.

🧩 Methods

build()

Prepares internal caches of uniforms and samplers for GPU use.

clone()

Returns a deep copy of the material.

toJSON()

Returns an object representing this entity's properties. Not all props may be included.

fromJSON(data, texturesByUUID = {})

Loads material properties from a JSON object. Optionally links textures using texturesByUUID.

Example​

const mat = new UeMaterial({
color: c_red,
transparent: true,
opacity: 0.5,
map: myTexture,
uniforms: {
time: { type: "float", value: 0 }
}
});

🔧 Internal Notes​

  • The build() method is automatically called in the constructor.

  • Uniforms and textures must be named in the shader as u_ + name and s_ + name. This is an opinionated standard in Unique Engine's shaders, but you may want to change it if you prefer.

  • If forceSinglePass is false, transparent objects will be rendered twice to help with depth artifacts.