WebGL / WebGPU Material Generator

Babylon.js PBRMaterial & glTF 2.0 Channel Code Builder

Configure Babylon.js PBRMaterial channel flags without hunting through API docs: toggle packed glTF ORM metallicTexture channels (R:AO, G:Roughness, B:Metallic), DirectX Y-flip, and ClearCoat, then copy clean TypeScript.

100% Local Browser Engine · 0 Bytes Uploaded
Instant Deterministic Output
import { PBRMaterial, Texture, type Scene } from "@babylonjs/core";

export function create_WeatheredBrick(scene: Scene): PBRMaterial {
  const mat = new PBRMaterial("WeatheredBrick", scene);
  mat.albedoTexture = new Texture("/textures/WeatheredBrick_albedo.png", scene);
  mat.bumpTexture = new Texture("/textures/WeatheredBrick_normal.png", scene);
  mat.invertNormalMapX = false;
  mat.invertNormalMapY = false; // Native OpenGL +Y
  mat.metallicTexture = new Texture("/textures/WeatheredBrick_orm.png", scene);
  mat.useAmbientOcclusionFromMetallicTextureRed = true;
  mat.useRoughnessFromMetallicTextureGreen = true;
  mat.useMetallnessFromMetallicTextureBlue = true;
  mat.useRoughnessFromMetallicTextureAlpha = false;
  mat.clearCoat.isEnabled = true;
  mat.clearCoat.intensity = 0.65;
  mat.clearCoat.roughness = 0.12;
  return mat;
}

Essential Babylon.js PBRMaterial ORM channel boolean flags

Babylon.js PropertyValue for glTF ORMChannel Read
useAmbientOcclusionFromMetallicTextureRedtrueRed (R) = Ambient Occlusion
useRoughnessFromMetallicTextureGreentrueGreen (G) = Roughness
useMetallnessFromMetallicTextureBluetrueBlue (B) = Metallic (note double-L spelling)
useRoughnessFromMetallicTextureAlphafalsePrevents Alpha overriding Green

Avoiding the classic Babylon.js metallicTexture spelling & alpha traps

Babylon.js defaults to reading Roughness from Alpha unless useRoughnessFromMetallicTextureAlpha is explicitly set to false, and its legacy property name uses double-L (useMetallnessFromMetallicTextureBlue). Generating exact boilerplate eliminates silent shiny-material bugs.

Handling DirectX vs OpenGL normal maps cleanly in WebGL

glTF 2.0 mandates OpenGL (+Y) normal maps. If an imported asset uses DirectX (-Y) normals, setting mat.invertNormalMapY = true corrects lighting immediately without re-exporting textures.

Frequently asked questions

Why does Babylon.js use bumpTexture for normal maps?

In Babylon.js, PBRMaterial.bumpTexture accepts tangent-space normal maps directly and automatically treats them as normals.

Why does my glTF ORM map look too glossy in Babylon.js?

Check that useRoughnessFromMetallicTextureAlpha is set to false and useRoughnessFromMetallicTextureGreen is true.

Can I pack the ORM texture for Babylon.js here too?

Yes—use our free ORM Channel Packer to combine AO, Roughness, and Metallic into one PNG.

Does Babylon.js support KTX2 GPU-compressed textures?

Yes, pairing packed ORM maps with UASTC KTX2 cuts WebGL/WebGPU VRAM by 75%.

More free local PBR & normal map tools