Hazel

Camera

How cameras work in Renzora: the editor's orbit controller and its viewport cameras, how a game picks its camera, and the per-camera image settings (anti-aliasing, tonemapping, exposure) that are routed onto whatever camera renders.

There are two camera stories. The editor viewport is driven by renzora_camera, an editor-only orbit controller. A game has no controller at all: its cameras are ordinary Bevy cameras saved in the scene, moved by the game's own code. Both receive their effects the same way, through EffectRouting (see Render Pipeline).

The editor orbit controller

# crates/renzora_camera/Cargo.toml
[[package.metadata.renzora.plugin]]
type = "CameraPlugin"
scope = "Editor"

CameraPlugin is Editor-scoped, so it exists only when the editor image is loaded. A game, a server or an export never contains it. The navigation it implements (right-drag look, WASD fly, orbit, pan, scroll dolly, the framing shortcuts) is described for users on Viewport and Shortcuts; this section is the state behind it.

OrbitCameraState

#[derive(Clone, Resource, Reflect, Serialize, Deserialize)]
pub struct OrbitCameraState {
    pub focus: Vec3,     // the point orbited
    pub distance: f32,   // from the focus; zoom keeps it >= 0.1
    pub yaw: f32,        // radians
    pub pitch: f32,      // radians, clamped to -1.5..=1.5
    pub projection_mode: ProjectionMode, // Perspective | Orthographic
}

Defaults: focus zero, distance 4.5, yaw 0.3, pitch 0.4, Perspective.

It is a resource only. A scene saves the orbit as a separate component on the scene camera, renzora_scene_api::SceneCameraOrbit (to_saved / from_saved), so the scene reopens on the view it was saved with. It used to be reflected as a component too, and anything copying entities by reflection inserted it onto a second entity, which Bevy refuses for a resource.

CameraSettings

FieldDefaultMeaning
move_speed10.0Fly speed, units a second. Flying is never scaled by distance.
look_sensitivity0.3Right-drag look
orbit_sensitivity0.5Orbit drag
pan_sensitivity1.0Pan
zoom_sensitivity1.0Scroll dolly
invert_yfalseInvert vertical look
distance_relative_speedtrueScale scroll zoom by the distance to the focus

The viewport header keeps this resource in step with ViewportSettings. Holding Ctrl multiplies movement by 0.25. PivotLock(bool) keeps the orbit anchored on what was focused: zoom then changes only distance, and panning is suppressed. Framing (focus selected, frame all, camera to cursor) turns it on; flying turns it off.

While the pivot is in use, pivot_marker draws it as a ring labelled with its distance, in its own gizmo group (PivotGizmoGroup). ViewportSettings::show_pivot (default true) turns it off.

Projection

The controller writes Bevy's Projection on the focused camera, and only when it differs: a Projection written through a mutable reference is marked changed even when equal, and the viewport reads a changed projection as camera motion, so writing it every frame kept every viewport from idling.

  • Perspective: near 0.01, far 100_000.0, and the field of view of the scene's camera (below), else 45 degrees. The near plane is 0.01 rather than Bevy's 0.1 so small objects seen up close are not sliced; Bevy's 3D depth is reverse-Z with an infinite far plane, so this costs no visible precision.
  • Orthographic: ScalingMode::FixedVertical with viewport_height = 2 * distance * tan(fov / 2), so switching between the two is seamless at the orbit distance and orthographic stays in metres rather than Bevy's default pixel units.

The editor view's field of view follows a scene camera, chosen by ViewportSettings' editor_camera_source:

  • Default (the default): the DefaultCamera, else the first SceneCamera. The editor camera keeps its own position.
  • Selected: the selected scene camera. Selecting one also moves the editor view to its pose.

Multiple viewports

The editor has up to four viewport slots (VIEWPORT_COUNT), each with its own camera and its own orbit (focus, distance, yaw, pitch). The projection mode is shared.

MarkerOn
ViewportCamera(usize)Each slot's 3D camera
EditorCameraThe focused slot's camera only. relocate_editor_camera_marker moves it in PreUpdate, so every With<EditorCamera> system (the controller, gizmos, overlays) works on the focused view.
PrimaryViewportCameraSlot 0, which carries the sky and its environment probe
ViewportCamera2d / EditorCamera2dThe 2D equivalents
SceneCamera, DefaultCameraCameras that belong to the scene (below)

Unfocused slots are driven from their own stored orbit, so the views never converge.

Each viewport camera renders into an offscreen image the viewport panel displays, on render layer 0 only. Gizmos and overlays are drawn by a separate overlay camera per slot into an image laid over it, so a gizmo highlighting under the cursor does not cost a full scene render.

Only slot 0 carries the atmosphere and the sky probe bake (AtmosphereEnvironmentMapLight). A second atmosphere camera is a duplicated bake, and Bevy derives the atmosphere's part of the mesh view layout in two independent places that can disagree on such a camera, which is a wgpu crash. The other slots carry an EnvironmentMapLight from spawn with placeholder maps and zero intensity, which holds the bind group slots, and slot 0's filtered maps and sky are shared to them once ready.

Game cameras

A game's cameras come out of the scene: entities with SceneCamera (and optionally DefaultCamera), both in renzora_scene_api and reached as renzora::SceneCamera / renzora::DefaultCamera. Only the markers and the authored components are saved. When a scene loads, renzora_engine::scene_io::cameras::rehydrate_cameras gives each SceneCamera that lacks one a Camera3d (an authored Camera2d camera stays 2D):

  • In a game, the DefaultCamera is active, or the first scene camera when none is marked; the others are inactive.
  • In the editor every scene camera is inactive: the viewport cameras render.

The active game camera also gets the bundle that cannot be added later: Hdr, NormalPrepass, DepthPrepass, MotionVectorPrepass, the sky probe sized for the quality tier, Msaa::Off and AtmosphereSettings. The reasons are on Render Pipeline, under "Prepasses are fixed at camera spawn".

Effect routing in a game targets the first SceneCamera that is both DefaultCamera and active, else the first active one. To switch cameras at runtime, move is_active:

use bevy::prelude::*;
use renzora::SceneCamera;

fn switch_to(target: Entity, mut cameras: Query<(Entity, &mut Camera), With<SceneCamera>>) {
    for (entity, mut camera) in &mut cameras {
        camera.is_active = entity == target;
    }
}

Render-to-texture and split screen use Bevy's own components: Camera { order, .. }, RenderTarget::Image(...) and Camera.viewport (physical pixel position and size).

Camera presets

A camera can carry CameraPresets { presets: Vec<CameraPreset> }, where CameraPreset is { name, translation, rotation } in world space. The inspector's Camera Presets section captures, previews and deletes them, and they save with the scene. A Rust script moves its camera to one directly:

use bevy::prelude::*;
use renzora::CameraPresets;

fn go_to_preset(name: &str, mut cameras: Query<(&CameraPresets, &mut Transform)>) {
    for (presets, mut transform) in &mut cameras {
        if let Some(p) = presets.get(name) {
            transform.translation = p.translation;
            transform.rotation = p.rotation;
        }
    }
}

get returns the first preset with that name.

Per-camera image settings

The Camera section in the Inspector is owned by renzora_editor_framework, but several of its rows belong to other crates. Each adds its fields with InspectorRegistry::extend("camera", fields), so the section's owner does not depend on them; the fields read and write the crates' own components.

Anti-aliasing

renzora_antialiasing::AntiAliasing is the one anti-aliasing component, authored on the scene camera and routed onto the rendering cameras.

pub struct AntiAliasing {
    pub enabled: bool,                 // default true
    pub method: AntiAliasingMethod,    // Msaa | Fxaa | Smaa | Taa (default) | Dlss
    pub msaa_samples: u32,             // 2, 4 or 8; default 4
    pub fxaa_quality: u32,             // 0 Low .. 4 Extreme; default 2
    pub smaa_quality: u32,             // 0 Low .. 3 Ultra; default 2
    pub dlss_mode: DlssMode,           // default Auto
}

One method runs at a time: they all attack the same edges, and two together blur twice (TAA under FXAA) or fight over one jitter (TAA and DLSS). Each method keeps its own quality, so switching away and back returns to what was set. Off clears enabled rather than removing the component. Sharpening is a separate component, CasSettings, that applies on top of any method.

Some methods cannot run on some cameras, and several of those combinations crash wgpu rather than fail quietly. renzora_antialiasing::compat::blocker is the single rule set, read both by the system that applies the method and by the inspector's warning icons, so the warning and the viewport cannot disagree:

MethodBlocked when the rendering camera
MSAArenders deferred (DeferredPrepass), has SSAO, has the sky (AtmosphereSettings), or has OIT
TAAhas DLSS Ray Reconstruction, or the tier is Low
DLSSruns in a build without DLSS, on hardware or a backend that cannot run it, or already has Ray Reconstruction
FXAA, SMAAnever: they run on the finished image

A blocked method is held off, not forced: the camera renders without anti-aliasing until the obstacle goes, and then the method applies by itself. See DLSS.

Scenes saved with the old per-method components (TaaSettings, FxaaSettings, SmaaSettings) still load: those types stay registered under their old paths, because a scene naming an unregistered type fails to load the entity, and they are folded into one AntiAliasing as they arrive.

Tonemapping and color grading

renzora_tonemapping::TonemappingSettings { mode, ev100, enabled } picks the curve: mode 0 None, 1 Reinhard, 2 Reinhard Luminance, 3 ACES Fitted, 4 AgX (the default), 5 Somewhat Boring, 6 Tony McMapface, 7 Blender Filmic. Mode 0 maps to Bevy's Tonemapping::Linear, not Tonemapping::None: in Bevy 0.20 None also skips color grading and dithering, and "None" here has always meant only "no tone curve".

Every 3D camera also has a Color Grading section, Bevy's ColorGrading, drawn by the tonemapping editor crate.

Exposure

The camera's manual exposure is Bevy's Exposure, the Camera section's EV100. Every 3D SceneCamera is seeded once (renzora_level_presets::seed_camera_effects, marked with CameraEffectsSeeded) with the default image set:

  • Exposure { ev100: 13.5 }, a sunlit exterior under the default 120,000 lux sun
  • AutoExposureSettings on (the type is in renzora_render_api, applied by renzora_auto_exposure)
  • TonemappingSettings on AgX
  • BloomSettings at intensity 0.2, threshold 1.5, so lamps and signs bloom and sunlit walls do not
  • AntiAliasing on TAA

Depth of field, motion blur and sharpening start off and are added per camera.

AutoExposureSettings wraps Bevy's histogram auto exposure:

FieldDefault
speed_brighten, speed_darken3.0, 1.0 stops a second
range_min, range_max-10, 16 EV (wider than Bevy's -8 to 8: a 120,000 lux sun meters above 8)
filter_low, filter_high0.10, 0.90
exponential_transition_distance1.5
keep_dark_strength0.55
keep_dark_pivot_ev2.0
enabledtrue

Bevy's auto exposure always aims for middle grey, which lifts a night scene until it looks like day. The two keep-dark fields build Bevy's exposure compensation curve: flat at and above keep_dark_pivot_ev, so daytime is untouched, and ramping negative below it by keep_dark_strength.

Bevy meters the frame after the manual Exposure has scaled it, so the same settings would mean different things at different EV100 values. They are authored against REFERENCE_EV100 (13.5), and both the range and the curve are shifted by how far the camera's EV100 is from it. That cancels exactly: with auto exposure on, the picture does not depend on the manual value.

The sky and the clear colour

A camera with an enabled atmosphere routed to it clears to black, because the sky is drawn over the clear colour and a grey clear showed through at night as a flat overcast. Only a camera on ClearColorConfig::Default is changed, and turning the sky off restores it. See Sky and Atmosphere.

Related