Skip to content

Materials ​

Materials define how surfaces appear when rendered. GFXLite provides four material types with increasing complexity and realism.

Material Types: Basic, Lambert, Phong, Standard

Basic Material ​

The simplest material - displays a solid color without any lighting calculations.

typescript
import { BasicMaterial, Vector3 } from "gfxlite";

const material = new BasicMaterial({
  color: new Vector3(1, 0, 0), // RGB values from 0 to 1
});

Options ​

PropertyTypeDefaultDescription
colorVector3(1, 1, 1)Base color
opacitynumber1.0Transparency (0-1)
blendModeBlendModeOpaqueBlending mode

Lambert Material ​

Diffuse shading using the Lambertian reflectance model. Reacts to lights but has no specular highlights.

typescript
import { LambertMaterial, Vector3 } from "gfxlite";

const material = new LambertMaterial({
  color: new Vector3(0.2, 0.8, 0.2),
});

Options ​

PropertyTypeDefaultDescription
colorVector3(1, 1, 1)Diffuse color
opacitynumber1.0Transparency
mapTexturenullDiffuse texture

Phong Material ​

Classic Phong shading with diffuse and specular components. Good for shiny surfaces.

typescript
import { PhongMaterial, Vector3 } from "gfxlite";

const material = new PhongMaterial({
  color: new Vector3(0.8, 0.2, 0.2),
  shininess: 64,
});

Options ​

PropertyTypeDefaultDescription
colorVector3(1, 1, 1)Diffuse color
shininessnumber32Specular sharpness
specularVector3(1, 1, 1)Specular color
opacitynumber1.0Transparency
mapTexturenullDiffuse texture

Standard Material ​

A more physically-based material with roughness and metalness parameters.

typescript
import { StandardMaterial, Vector3 } from "gfxlite";

const material = new StandardMaterial({
  color: new Vector3(0.8, 0.6, 0.2),
  roughness: 0.3,
  metalness: 0.8,
});

Options ​

PropertyTypeDefaultDescription
colorVector3(1, 1, 1)Base color
roughnessnumber0.5Surface roughness (0=smooth, 1=rough)
metalnessnumber0.0Metallic factor (0=dielectric, 1=metal)
opacitynumber1.0Transparency
mapTexturenullBase color texture
normalMapTexturenullNormal map texture
roughnessMapTexturenullRoughness texture
metalnessMapTexturenullMetalness texture

Transparency ​

All materials support transparency through the opacity and blendMode properties:

typescript
import { BasicMaterial, BlendMode, Vector3 } from "gfxlite";

// Semi-transparent material
const material = new BasicMaterial({
  color: new Vector3(1, 0, 0),
  opacity: 0.5,
  blendMode: BlendMode.AlphaBlend,
});

// Alpha cutoff (for textures with hard edges)
const foliageMaterial = new BasicMaterial({
  map: leafTexture,
  blendMode: BlendMode.AlphaCutoff,
  alphaCutoff: 0.5,
});

Blend Modes ​

ModeDescription
BlendMode.OpaqueNo transparency (default)
BlendMode.AlphaBlendStandard alpha blending
BlendMode.AlphaCutoffBinary transparency based on alpha threshold

Material Comparison ​

MaterialLightingSpecularPerformanceUse Case
BasicNoNoFastestUI, unlit effects, debugging
LambertYesNoFastMatte surfaces, stylized graphics
PhongYesYesMediumShiny objects, classic 3D look
StandardYesYes (PBR)SlowerRealistic rendering

Released under the MIT License.