Architecture
Architecture
Section titled โArchitectureโStrata is built as a layered architecture, with each layer building on the previous one. This design provides flexibilityโyou can use the high-level components for rapid development, or drop down to lower levels for fine-grained control.
The Layer Model
Section titled โThe Layer Modelโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Layer 4: Game Framework & Presets โโ Ready-to-use configurations, game state, controllers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโ Layer 3: React Three Fiber Components โโ <Water>, <Terrain>, <GrassInstances>, <ProceduralSky> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโ Layer 2: Core Algorithms โโ SDF, Marching Cubes, Noise, Materials โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโ Layer 1: GLSL Shaders โโ Water, Terrain, Sky, Volumetrics, Materials โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโ Layer 0: TypeScript Types & Utilities โโ Type definitions, math utilities, helpers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโLayer 0: Types & Utilities
Section titled โLayer 0: Types & UtilitiesโThe foundation layer provides TypeScript type definitions and utility functions used throughout the library.
import type { BiomeConfig, WaterConfig, SkyConfig, TerrainChunk} from '@strata-game-library/core/types';
import { clamp, lerp, smoothstep, vec3} from '@strata-game-library/core/utils';Layer 1: GLSL Shaders
Section titled โLayer 1: GLSL ShadersโThe shader layer contains all GLSL vertex and fragment shaders. These can be used independently with any Three.js project.
import { waterVertexShader, waterFragmentShader, skyVertexShader, skyFragmentShader} from '@strata-game-library/shaders';
// Use with Three.js ShaderMaterialconst material = new THREE.ShaderMaterial({ vertexShader: waterVertexShader, fragmentShader: waterFragmentShader, uniforms: { uTime: { value: 0 }, uWaterColor: { value: new THREE.Color(0x0077be) }, }});Available shader categories:
- Terrain: Height-based blending, triplanar mapping
- Water: Wave animation, reflections, refractions
- Sky: Atmospheric scattering, sun/moon
- Clouds: Volumetric and layered clouds
- Volumetrics: Fog, god rays, underwater
- Materials: Toon, hologram, dissolve, forcefield, glitch
- Vegetation: Wind animation for grass and trees
Layer 2: Core Algorithms
Section titled โLayer 2: Core AlgorithmsโPure TypeScript implementations of core algorithms with no React dependencies.
SDF (Signed Distance Functions)
Section titled โSDF (Signed Distance Functions)โimport { sdSphere, sdBox, sdCapsule, sdTorus, opUnion, opSubtraction, opSmoothUnion} from '@strata-game-library/core';
// Combine shapesconst scene = opSmoothUnion( sdSphere(point, center, radius), sdBox(point, boxCenter, boxSize), 0.5 // smoothness);Noise Functions
Section titled โNoise Functionsโimport { noise3D, fbm, warpedFbm} from '@strata-game-library/core';
// Generate terrain heightconst height = fbm(x * 0.01, 0, z * 0.01, { octaves: 6, persistence: 0.5, lacunarity: 2.0});Marching Cubes
Section titled โMarching Cubesโimport { marchingCubes, createGeometryFromMarchingCubes, generateTerrainChunk} from '@strata-game-library/core';
// Generate terrain meshconst geometry = generateTerrainChunk({ position: [0, 0, 0], size: 32, resolution: 64, sdfFunction: terrainSDF});Material Creation
Section titled โMaterial Creationโimport { createWaterMaterial, createAdvancedWaterMaterial, createSkyMaterial, createRaymarchingMaterial} from '@strata-game-library/core';
const waterMaterial = createWaterMaterial({ color: new THREE.Color(0x0077be), opacity: 0.8, reflectivity: 0.5});Layer 3: React Components
Section titled โLayer 3: React ComponentsโHigh-level React Three Fiber components that wrap the core algorithms.
Water Components
Section titled โWater Componentsโimport { Water, AdvancedWater } from '@strata-game-library/core';
<Water size={100} depth={20} /><AdvancedWater size={200} waveHeight={2} reflections caustics/>Vegetation Components
Section titled โVegetation Componentsโimport { GrassInstances, TreeInstances, RockInstances, GPUInstancedMesh} from '@strata-game-library/core';
<GrassInstances count={10000} spread={100} /><TreeInstances count={500} spread={200} />Sky Components
Section titled โSky Componentsโimport { ProceduralSky } from '@strata-game-library/core';
<ProceduralSky sunPosition={[100, 50, 100]} turbidity={10} rayleigh={2}/>Volumetric Components
Section titled โVolumetric Componentsโimport { VolumetricEffects, VolumetricFogMesh, UnderwaterOverlay, EnhancedFog} from '@strata-game-library/core';
<VolumetricFogMesh density={0.02} /><UnderwaterOverlay depth={10} />Layer 4: Presets & Game Framework
Section titled โLayer 4: Presets & Game FrameworkโThe highest layer provides ready-to-use configurations and game framework utilities.
Presets
Section titled โPresetsโimport { createTerrainPreset, TerrainBiomes } from '@strata-game-library/presets/terrain';import { createWeatherPreset, WeatherPresets } from '@strata-game-library/presets/weather';import { createWaterPreset, WaterTypes } from '@strata-game-library/presets/water';
const terrain = createTerrainPreset({ biomes: [TerrainBiomes.GRASSLAND, TerrainBiomes.MOUNTAIN], resolution: 128});
const weather = createWeatherPreset(WeatherPresets.RAIN);const water = createWaterPreset(WaterTypes.OCEAN);Game Framework (Coming Soon)
Section titled โGame Framework (Coming Soon)โimport { useGameState, useCharacterController, useInventory} from '@strata-game-library/core/game';Package Structure
Section titled โPackage StructureโStrata is organized as multiple packages for flexibility:
Main Package (@strata-game-library/core)
Section titled โMain Package (@strata-game-library/core)โThe core library with components, algorithms, and utilities:
// Main package - componentsimport { Water, ProceduralSky, Terrain, GrassInstances } from '@strata-game-library/core';
// Subpath: Core algorithmsimport { marchingCubes, noise3D, sdSphere } from '@strata-game-library/core';
// Subpath: Utility functionsimport { clamp, lerp, smoothstep } from '@strata-game-library/core/utils';
// Subpath: TypeScript typesimport type { BiomeConfig, WaterConfig } from '@strata-game-library/core/types';Shaders Package (@strata-game-library/shaders)
Section titled โShaders Package (@strata-game-library/shaders)โStandalone GLSL shaders (works with any Three.js project):
import { waterVertexShader, waterFragmentShader, skyVertexShader, skyFragmentShader} from '@strata-game-library/shaders';Presets Package (@strata-game-library/presets)
Section titled โPresets Package (@strata-game-library/presets)โPre-configured settings (requires @strata-game-library/core):
import { createTerrainPreset, TerrainBiomes } from '@strata-game-library/presets/terrain';import { createWaterPreset, WaterTypes } from '@strata-game-library/presets/water';Mobile Plugins
Section titled โMobile PluginsโPlatform-specific capabilities:
// React Nativeimport { useDevice, useHaptics } from '@strata-game-library/react-native-plugin';
// Capacitor (Web/iOS/Android/Electron)import { useDevice, useInput } from '@strata-game-library/capacitor-plugin/react';Directory Structure
Section titled โDirectory Structureโ@strata-game-library/core/โโโ src/โ โโโ api/ # Public API contractsโ โโโ components/ # React Three Fiber componentsโ โโโ compose/ # Component composition utilitiesโ โโโ core/ # Core algorithms (SDF, noise, marching cubes)โ โโโ game/ # Game framework (coming soon)โ โโโ hooks/ # React hooksโ โโโ presets/ # Pre-configured settingsโ โโโ shaders/ # GLSL shadersโ โโโ types/ # TypeScript type definitionsโ โโโ utils/ # Utility functionsโ โโโ world/ # World generation utilitiesDesign Principles
Section titled โDesign Principlesโ1. Progressive Disclosure
Section titled โ1. Progressive DisclosureโStart with high-level components, drop down to lower layers when needed.
2. Zero Configuration
Section titled โ2. Zero ConfigurationโEverything works out of the box with sensible defaults.
3. Full Customization
Section titled โ3. Full CustomizationโEvery parameter is configurable when you need control.
4. Performance First
Section titled โ4. Performance FirstโGPU-accelerated by default, mobile-optimized.
5. TypeScript Native
Section titled โ5. TypeScript NativeโFull type safety with excellent IDE support.
Next Steps
Section titled โNext Stepsโ- Core Features - Explore all components
- Shaders - Use shaders directly
- Presets - Ready-to-use configurations
- API Reference - Complete API documentation