Skip to content

Rendering ​

Every BasePart and PartBatch under Scene is drawn from Scene.CurrentCamera, with UI surfaces on top. Lights, sky and post effects are on the Lighting page. This page covers models, big batches of boxes, particles and shadows.

Mesh parts ​

A MeshPart draws a 3D model.

luau
local tree = Instance.new("MeshPart")
tree.MeshId = "assets/Tree.glb"
tree.Parent = Scene

MeshId is a path relative to the project folder (see Assets) or an http(s):// URL. Models load in the background through assimp, so glTF/GLB, FBX, OBJ, Collada, 3DS, PLY, STL, .blend and the rest of assimp's formats work. Parts with the same MeshId share one load.

Size. The model is stretched to fill the part's Size, like a Part's box. MeshSize is the model's own size once loaded, and Vector3.zero before that (it doesn't fire Changed). So to keep proportions: part.Size = part.MeshSize * scale once MeshSize isn't zero. With no MeshId the part is drawn as a block. While loading, or after a failed load, it isn't drawn at all, and a warning says why.

Materials. Base colour and its texture are lit like parts. Materials that give roughness and metalness (every glTF material does) also use their metallic-roughness texture, normal map and emissive colour, instead of the part's Material. Other formats use the part's Material. Emissive textures aren't read.

  • Textures named by the model load from next to its file. Embedded textures (common in GLB and FBX) are read too. A model from a URL only gets its embedded ones.
  • TextureId replaces every material's texture, and textures a block-drawn MeshPart once per face. PNG, JPEG, BMP, GIF (first frame), TGA and WebP.
  • Color multiplies everything, which is why a MeshPart starts white.
  • Double-sided materials, like a glTF leaf card, draw both faces. Everything else draws front faces only. Every face casts shadows.

Transparency. Pixels with alpha below one half are cut out, and stay cut out at a distance so foliage doesn't thin away. A part with Transparency between 0 and 1, or a partly transparent material, is blended after every transparent Part, sorted by distance to its centre.

Raycasts. Scene:Raycast hits a loaded model's actual triangles (either face), so rays pass through gaps in its box. Before it loads, or without a MeshId, it's hit as its box. Overlap queries and shape casts always use the box.

Level of detail. A model with enough triangles gets up to four simplified copies as it loads, each about half the last. The renderer draws the coarsest copy that's within a pixel of the full model on screen. RenderFidelity controls it: Automatic (one pixel, the default), Performance (four pixels) or Precise (always full). Raycasts and shadows always use the full model.

Models with bones or animations keep their node hierarchy and skin; see Animation.

Part batches ​

A PartBatch draws many axis-aligned boxes that live only on the GPU, for when you need more boxes than Part instances can handle.

luau
local batch = Instance.new("PartBatch")
batch.Count = 10000
local data = buffer.create(10000 * 10 * 4)
-- per box: position xyz, size xyz, colour rgb (0 to 1), transparency
batch:SetParts(data, 0)
batch.Parent = Scene

Set Count, then write boxes with batch:SetParts(data, first): a buffer of 10 floats (32-bit) per box, starting at box first (from 0). Unwritten boxes aren't drawn, and changing Count clears them all.

Limits:

  • Boxes can't be read back, rotated, saved, cloned, raycast or collided with.
  • Transparent boxes blend in batch order, not sorted.
  • Each written box waits in memory (64 bytes) until the next frame uploads it, and a buffer tops out at 1 GB, so fill a huge batch a chunk per frame.
  • A batch that doesn't fit in free GPU memory isn't drawn, and a message says so. A batch keeps its GPU copy while it exists, even outside Scene.

Particles ​

A ParticleEmitter in a part emits from anywhere inside the part. In an Attachment, it emits from the attachment. Particles are squares facing the camera.

luau
local sparks = Instance.new("ParticleEmitter")
sparks.Rate = 50
sparks.Lifetime = NumberRange.new(0.5, 1)
sparks.Speed = NumberRange.new(8, 12)
sparks.SpreadAngle = Vector2.new(30, 30)
sparks.Acceleration = Vector3.new(0, -30, 0)
sparks.Color = ColorSequence.new(Color.fromRGB(255, 200, 80), Color.fromRGB(255, 60, 0))
sparks.Size = NumberSequence.new(0.4, 0)
sparks.Parent = torch
  • Rate per second while Enabled. Emit(count) adds some at once either way, Clear() removes them.
  • Each particle lives a random time in Lifetime and leaves along EmissionDirection (a face of the parent, Top by default) at a speed in Speed, turned randomly by up to SpreadAngle degrees.
  • Acceleration pulls it. Drag halves its speed that many times a second.
  • Size, Transparency and Color are sequences over its life. Envelopes on Size and Transparency vary them per particle.
  • Rotation and RotSpeed spin it, TimeScale speeds up or slows the whole emitter, and LockedToPart moves particles with the part.
  • LightEmission above 0.5 draws particles as Neon. Texture is stored but not drawn yet.

The simulation runs on the CPU, so GetParticles() returns each particle's Position, Velocity, Age, Lifetime, Rotation, Size, Transparency and Color, for tests or custom drawing.

Shadows ​

The sun (or moon) casts shadows while Lighting.GlobalShadows is true. Shadows in Gamma.json picks how.

ShadowMap (default). Soft shadows from 4 cascaded shadow maps, out to 500 studs, fading at the end. Each cascade is 2048×2048 (ShadowMapSize), so close shadows are sharp and far ones coarse. Lighting.ShadowSoftness widens the edge, from 0 (hard) to 1. Cascades move in whole texels, so edges don't shimmer as the camera moves. Opaque parts, batch boxes and mesh parts all cast; cut-out texture pixels don't. A GPU that can't compare depth textures gets no shadows.

RayTraced. Hard, exact shadows from every opaque Part and MeshPart onto everything, at any distance. Each lit pixel traces a ray through a BVH of the scene in the pixel shader, so it needs no RT hardware and works on every graphics API (it only uses WebGL 2 features, but hasn't been tried on the web yet). These don't cast ray-traced shadows:

  • Parts whose Shape isn't Block
  • PartBatch boxes
  • MeshParts still loading
  • cut-out texture pixels (they shadow as solid)

The scene is re-uploaded only in frames where a part moves, changes or is added, at about 128 bytes a part, so thousands of moving parts cost real CPU time. A ray gives up after 384 steps and counts as lit.

None. No shadows.

In every mode, parts with Transparency above 0 receive shadows but don't cast them.

Apache License 2.0