menu_bookDocumentation
SceneCamera: World-to-Screen, Screen-to-World, Render Hooks, and Camera Properties
SceneCamera: World-to-Screen, Screen-to-World, and Render Hooks
SceneCamera is the main camera class in s&box. It wraps a native frustum and provides coordinate conversion, render hooks, and rendering to textures.World ↔ Screen Conversion
CSHARP
// World position to screen pixel position
Vector2 screenPos = camera.ToScreen( worldPosition );
// World position to normalized screen coords (0-1)
Vector2 normalized = camera.ToScreenNormal( worldPosition );
// World position to screen, with visibility check
bool visible = camera.ToScreen( worldPosition, out Vector2 screenPos );
// Screen pixel to world ray
Ray ray = camera.GetRay( screenPosition );
// Screen pixel to world ray (with custom screen size)
Ray ray = camera.GetRay( screenPosition, camera.Size );
// Near-plane world position from screen coords
Vector3 worldPos = camera.ToWorld( screenPosition );Camera Properties
CSHARP
camera.Position = Vector3.Zero;
camera.Rotation = Rotation.Identity;
camera.FieldOfView = 70f;
camera.ZNear = 5f;
camera.ZFar = 10000f;
camera.AmbientLightColor = Color.Black; // no ambient
camera.BackgroundColor = Color.Black;
camera.AntiAliasing = true;
camera.EnablePostProcessing = true;Render Hooks
CSHARP
// Called after post-process (overlay pass)
camera.OnRenderOverlay = () =>
{
// Draw UI overlays here
};
// Called during UI pass
camera.OnRenderUI = () =>
{
// Draw UI here
};Render to Texture
CSHARP
// Render to a texture
camera.RenderToTexture( myTexture, size: null, config: default );Tag Filtering
CSHARP
// Only render objects with these tags
camera.RenderTags.Add( "world" );
// Exclude objects with these tags
camera.ExcludeTags.Add( "ui" );Debug Modes
CSHARP
camera.DebugMode = SceneCameraDebugMode.NormalMap;
camera.WireframeMode = true;ZNear/ZFar Guidance
A good ZNear is around 5. Below 1 causes z-fighting artifacts. Balance ZFar with ZNear — shorter ranges give better depth precision.
Was this helpful?