export const MIN_VIEW_DISTANCE = 2; export const DEFAULT_VIEW_DISTANCE = 3; export const MAX_VIEW_DISTANCE = 64; export const WORLD_MIN_Y = -64; export const WORLD_MAX_Y = 319; export const VIEW_HEIGHT = WORLD_MAX_Y - WORLD_MIN_Y + 1; export const VIEW_BUFFER = 1; export const MAX_VIEW_WIDTH = ((MAX_VIEW_DISTANCE + VIEW_BUFFER) * 2 + 1) * 16; export const MAX_VIEW_CELLS = MAX_VIEW_WIDTH ** 2 * VIEW_HEIGHT; // Lighting uses local windows; raising render distance must not allocate a // multi-gigabyte dense light volume. export const MAX_LIGHT_CELLS = 304 ** 2 * 80; export const MAX_VIEW_COORDINATE = 30_000_000 + (MAX_VIEW_DISTANCE + VIEW_BUFFER) * 16; export function normalizeViewDistance(value) { const distance = Number(value); return Number.isInteger(distance) && distance >= MIN_VIEW_DISTANCE && distance <= MAX_VIEW_DISTANCE ? distance : DEFAULT_VIEW_DISTANCE; } export function viewDistanceProfile(value) { const chunks = normalizeViewDistance(value), width = (chunks * 2 + 1) * 16; const drawRadius = Math.SQRT2 * chunks * 16 + 24; const verticalSections = VIEW_HEIGHT / 16; return { chunks, radius: chunks * 16, width, sections: (chunks * 2 + 1) ** 2 * verticalSections, voxelBytes: width * width * VIEW_HEIGHT * 4, streamWidth: width + VIEW_BUFFER * 32, streamSections: (chunks * 2 + 1 + VIEW_BUFFER * 2) ** 2 * verticalSections, streamVoxelBytes: (width + VIEW_BUFFER * 32) ** 2 * VIEW_HEIGHT * 4, drawRadius, farClip: Math.max(190, drawRadius + 60), fogDistance: 78 * chunks / DEFAULT_VIEW_DISTANCE }; }