1. Dashboard
  2. Getting Started
  3. GitHub
  4. API
  5. Articles
  6. Level Editor
  7. Members
    1. Recent Activity
    2. Users Online
    3. Staff
    4. Search Members
  8. Forum
  9. Discord
  • Login
  • Register
  • Search
Getting Started
  • Everywhere
  • Getting Started
  • Articles
  • Pages
  • Forum
  • More Options
  1. GFX-Engine
  2. Articles
  3. Getting Started

Meshes, Primitives & Materials

  • Andy
  • January 4, 2026 at 1:02 AM
  • 163 Views
  • 0 Comments

This article explains how geometry, materials, and rendering responsibilities are separated and combined in GFX-Next. It outlines the conceptual boundaries between mesh data, material definitions, and the rendering systems that process them, emphasizing how each concern is kept modular while still working together efficiently. The article discusses how geometry provides the raw structural data, materials define visual appearance and shading behavior, and rendering systems orchestrate the interaction between the two at runtime. It also highlights how this separation improves scalability, enables flexible rendering pipelines, and makes it easier to introduce new material models or rendering techniques without tightly coupling them to scene or asset data.

Contents [hideshow]
  1. Mesh: Pure Geometry Data
  2. Default Material on Meshes
  3. Primitives: Scene-Level Geometry Instances
  4. Material Overrides per Primitive
  5. Rendering Contract
  6. Procedural Mesh Generation
  7. Mesh Sharing & Instancing
  8. Materials as Assets
  9. Transparency & Render Ordering
  10. Ownership Rules (Very Important)
  11. Summary

The goal is to:

  • allow aggressive mesh sharing
  • avoid implicit state
  • support procedural and imported geometry
  • keep rendering explicit and predictable

1. Mesh: Pure Geometry Data

A Mesh represents geometry only.

It contains:

  • vertex data
  • index data
  • bounds (AABB)
  • GPU render data

A mesh does not represent a scene object.

C#
_cubeMesh = assets.Add<Mesh>("CubeMesh", Cube.GetMesh(defaultMaterial));

Meshes are:

  • reusable
  • shareable
  • asset-managed
  • independent of transforms

2. Default Material on Meshes

A mesh may define a default material.

C#
_cubeMesh.Material = defaultMaterial;

This allows:

  • simple use cases without per-object materials
  • safe fallback behavior
  • minimal setup for primitives
  • its an reference only. The material should be an own asset

3. Primitives: Scene-Level Geometry Instances

A Primitive is a GameElement that references a mesh.

C#
var ground = new Primitive("Ground", _cubeMesh);

A primitive:

  • owns a transform
  • participates in scene hierarchy
  • does NOT own geometry
  • does NOT own GPU memory

Multiple primitives may reference the same mesh.


4. Material Overrides per Primitive

Primitives may override the mesh’s default material.

C#
var rightCube = new Primitive("RightCube", _cubeMesh, debugMaterial);

Material resolution order:

  1. Primitive material override
  2. Mesh default material

This allows:

  • one mesh, many visual styles
  • debug rendering
  • editor highlighting
  • instanced variations

5. Rendering Contract

Rendering is handled by the renderer using explicit parameters.

C#
renderer.DrawMesh(transform, mesh, materialOverride);

The renderer:

  • never mutates mesh state
  • never assumes materials
  • resolves material explicitly

This avoids hidden state and side effects.


6. Procedural Mesh Generation

Meshes can be generated procedurally using static factories.

C#
Mesh sphere = Sphere.GetMesh();
Mesh cube = Cube.GetMesh(defaultMaterial);

Procedural meshes:

  • produce CPU-side data
  • can be registered as assets
  • follow the same lifetime rules as imported meshes

This makes primitives and imported models behave identically.


7. Mesh Sharing & Instancing

Meshes are designed to be shared aggressively.

Example:

C#
var leftCube  = new Primitive("LeftCube", _cubeMesh);
var rightCube = new Primitive("RightCube", _cubeMesh);

Benefits:

  • minimal GPU memory usage
  • cache-friendly rendering
  • consistent bounds and collision

For high-volume objects, MeshInstancer is used.

C#
var instancer = new MeshInstancer(_projectileMesh, debugMaterial);

8. Materials as Assets

Materials are assets and are managed by the AssetManager.

C#
_defaultMaterial = assets.Add(new SGMaterial("DefaultMaterial", color));

Materials:

  • manage textures and uniforms
  • can be shared across meshes and primitives
  • are not scene-owned

9. Transparency & Render Ordering

Transparency is determined by the effective material.

C#
public override bool HasTransparency => 
    Material?.IsTransparent ?? Mesh.Material?.IsTransparent ?? false;

This ensures:

  • correct render sorting
  • consistent behavior for overrides
  • predictable blending

10. Ownership Rules (Very Important)

ResourceOwner
MeshAssetManager
MaterialAssetManager
PrimitiveScene
TransformGameElement
GPU buffersAsset

Primitives never dispose meshes or materials.


Summary

The mesh system in GFX-Next is built around:

  • strict separation of geometry and instances
  • explicit material resolution
  • aggressive mesh sharing
  • predictable rendering contracts
  • asset-managed lifetime

This keeps rendering scalable, debuggable, and editor-safe.

  • Previous Article Asset Management & Resource Lifetime
  • Next Article Rendering Pipeline & Post Processing

Categories

  1. Advanced Tutorial 1
  2. Getting Started 8
  3. Default Category 1
  4. Reset Filter

Partner & Supporter

  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™