Skip to main content

RenderEngine

Struct RenderEngine 

Source
pub struct RenderEngine {
Show 30 fields pub instance: Instance, pub adapter: Adapter, pub device: Device, pub queue: Queue, pub surface: Option<Surface<'static>>, pub surface_config: SurfaceConfiguration, pub depth_texture: Texture, pub depth_view: TextureView, pub materials: MaterialRegistry, pub color_maps: ColorMapRegistry, pub matcap_bind_group_layout: BindGroupLayout, pub matcap_textures: HashMap<String, MatcapTextureSet>, pub camera: Camera, pub width: u32, pub height: u32, pub point_pipeline: Option<RenderPipeline>, pub point_bind_group_layout: Option<BindGroupLayout>, pub camera_buffer: Buffer, pub slice_plane_buffer: Buffer, pub slice_plane_bind_group_layout: BindGroupLayout, pub slice_plane_bind_group: BindGroup, pub vector_pipeline: Option<RenderPipeline>, pub vector_bind_group_layout: Option<BindGroupLayout>, pub mesh_pipeline: Option<RenderPipeline>, pub mesh_depth_normal_pipeline: Option<RenderPipeline>, pub curve_network_edge_pipeline: Option<RenderPipeline>, pub curve_network_tube_pipeline: Option<RenderPipeline>, pub curve_network_tube_compute_pipeline: Option<ComputePipeline>, pub simple_mesh_pipeline: Option<RenderPipeline>, pub gridcube_pipeline: Option<RenderPipeline>, /* private fields */
}
Expand description

The main rendering engine backed by wgpu.

Fields§

§instance: Instance

The wgpu instance.

§adapter: Adapter

The wgpu adapter.

§device: Device

The wgpu device.

§queue: Queue

The wgpu queue.

§surface: Option<Surface<'static>>

The render surface (None for headless).

§surface_config: SurfaceConfiguration

Surface configuration.

§depth_texture: Texture

Depth texture.

§depth_view: TextureView

Depth texture view.

§materials: MaterialRegistry

Material registry.

§color_maps: ColorMapRegistry

Color map registry.

§matcap_bind_group_layout: BindGroupLayout

Matcap bind group layout (Group 2: 4 textures + 1 sampler).

§matcap_textures: HashMap<String, MatcapTextureSet>

Matcap texture sets keyed by material name.

§camera: Camera

Main camera.

§width: u32

Current viewport width.

§height: u32

Current viewport height.

§point_pipeline: Option<RenderPipeline>

Point cloud render pipeline.

§point_bind_group_layout: Option<BindGroupLayout>

Point cloud bind group layout.

§camera_buffer: Buffer

Camera uniform buffer.

§slice_plane_buffer: Buffer

Slice plane uniform buffer.

§slice_plane_bind_group_layout: BindGroupLayout

Slice plane bind group layout (shared by all structure shaders).

§slice_plane_bind_group: BindGroup

Slice plane bind group (updated each frame).

§vector_pipeline: Option<RenderPipeline>

Vector arrow render pipeline.

§vector_bind_group_layout: Option<BindGroupLayout>

Vector bind group layout.

§mesh_pipeline: Option<RenderPipeline>

Surface mesh render pipeline (alpha blending, depth write enabled).

§mesh_depth_normal_pipeline: Option<RenderPipeline>

Surface mesh depth/normal-only pipeline (Pretty mode prepass).

§curve_network_edge_pipeline: Option<RenderPipeline>

Curve network edge render pipeline (line rendering).

§curve_network_tube_pipeline: Option<RenderPipeline>

Curve network tube render pipeline (cylinder impostor rendering).

§curve_network_tube_compute_pipeline: Option<ComputePipeline>

Curve network tube compute pipeline (generates bounding box geometry).

§simple_mesh_pipeline: Option<RenderPipeline>

Simple mesh pipeline (for isosurface rendering).

§gridcube_pipeline: Option<RenderPipeline>

Gridcube pipeline (for volume grid scalar visualization).

Implementations§

Source§

impl RenderEngine

Source

pub fn assign_pick_range( &mut self, type_name: &str, name: &str, num_elements: u32, ) -> u32

Assigns a contiguous range of global pick indices to a structure.

Returns the global_start index. The structure owns indices [global_start, global_start + num_elements).

Index 0 is reserved as background (no hit), so all ranges start from >= 1.

Source

pub fn remove_pick_range(&mut self, type_name: &str, name: &str)

Removes a structure’s pick range.

The range is freed but the global index counter is not decremented (monotonic allocation — no fragmentation complexity).

Source

pub fn lookup_global_index( &self, global_index: u32, ) -> Option<(&str, &str, u32)>

Looks up which structure owns a global pick index.

Returns (type_name, name, local_element_index) or None if no structure owns this index (background or freed range).

Source

pub fn get_pick_range_start(&self, type_name: &str, name: &str) -> Option<u32>

Gets the global_start for a structure’s pick range, if assigned.

Source

pub fn init_pick_buffers(&mut self, width: u32, height: u32)

Creates or recreates pick buffer textures to match viewport size.

Source

pub fn pick_bind_group_layout(&self) -> &BindGroupLayout

Gets the pick bind group layout.

Source

pub fn point_pick_pipeline(&self) -> &RenderPipeline

Gets the point cloud pick pipeline.

Source

pub fn curve_network_pick_pipeline(&self) -> &RenderPipeline

Gets the curve network pick pipeline.

Source

pub fn init_curve_network_pick_pipeline(&mut self)

Initializes the curve network pick pipeline.

Source

pub fn has_curve_network_pick_pipeline(&self) -> bool

Returns whether the curve network pick pipeline is initialized.

Source

pub fn init_curve_network_tube_pick_pipeline(&mut self)

Initializes the curve network tube pick pipeline (uses ray-cylinder intersection).

Source

pub fn has_curve_network_tube_pick_pipeline(&self) -> bool

Returns whether the curve network tube pick pipeline is initialized.

Source

pub fn curve_network_tube_pick_pipeline(&self) -> &RenderPipeline

Gets the curve network tube pick pipeline.

Source

pub fn curve_network_tube_pick_bind_group_layout(&self) -> &BindGroupLayout

Gets the curve network tube pick bind group layout.

Source

pub fn init_mesh_pick_pipeline(&mut self)

Initializes the mesh pick pipeline for surface meshes.

Source

pub fn has_mesh_pick_pipeline(&self) -> bool

Returns whether the mesh pick pipeline is initialized.

Source

pub fn mesh_pick_pipeline(&self) -> &RenderPipeline

Gets the mesh pick pipeline.

Source

pub fn mesh_pick_bind_group_layout(&self) -> &BindGroupLayout

Gets the mesh pick bind group layout.

Source

pub fn init_gridcube_pick_pipeline(&mut self)

Initializes the gridcube pick pipeline for volume grid instances.

Source

pub fn has_gridcube_pick_pipeline(&self) -> bool

Returns whether the gridcube pick pipeline is initialized.

Source

pub fn gridcube_pick_pipeline(&self) -> &RenderPipeline

Gets the gridcube pick pipeline.

Source

pub fn gridcube_pick_bind_group_layout(&self) -> &BindGroupLayout

Gets the gridcube pick bind group layout.

Source

pub fn pick_at(&self, x: u32, y: u32) -> Option<u32>

Reads the pick buffer at (x, y) and returns the decoded global index.

Returns None if picking system not initialized or coordinates out of bounds. Returns Some(0) for background clicks.

Source

pub fn pick_texture_view(&self) -> Option<&TextureView>

Returns the pick texture view for external rendering.

Source

pub fn pick_depth_view(&self) -> Option<&TextureView>

Returns the pick depth texture view for external rendering.

Source

pub fn begin_pick_pass<'a>( &'a self, encoder: &'a mut CommandEncoder, ) -> Option<RenderPass<'a>>

Begins a pick render pass. Returns the render pass encoder.

The caller is responsible for rendering structures to this pass and then dropping the encoder to finish the pass.

Source§

impl RenderEngine

Source

pub fn shadow_pipeline(&self) -> Option<&RenderPipeline>

Gets the shadow render pipeline.

Source

pub fn shadow_bind_group_layout(&self) -> Option<&BindGroupLayout>

Gets the shadow bind group layout.

Source§

impl RenderEngine

Source

pub fn init_point_pipeline(&mut self)

Initializes the point cloud render pipeline.

Source

pub fn point_bind_group_layout(&self) -> &BindGroupLayout

Gets the point cloud bind group layout.

Source

pub fn init_vector_pipeline(&mut self)

Initializes the vector arrow render pipeline.

Source

pub fn vector_bind_group_layout(&self) -> &BindGroupLayout

Gets the vector bind group layout.

Source

pub fn mesh_bind_group_layout(&self) -> &BindGroupLayout

Gets the mesh bind group layout.

Source

pub fn simple_mesh_bind_group_layout(&self) -> &BindGroupLayout

Gets the simple mesh bind group layout (for isosurface rendering).

Source

pub fn curve_network_edge_bind_group_layout(&self) -> &BindGroupLayout

Gets the curve network edge bind group layout.

Source

pub fn curve_network_tube_bind_group_layout(&self) -> &BindGroupLayout

Gets the curve network tube render bind group layout.

Source

pub fn curve_network_tube_compute_bind_group_layout(&self) -> &BindGroupLayout

Gets the curve network tube compute bind group layout.

Source

pub fn curve_network_tube_compute_pipeline(&self) -> &ComputePipeline

Gets the curve network tube compute pipeline.

Source§

impl RenderEngine

Source

pub fn gridcube_bind_group_layout(&self) -> &BindGroupLayout

Gets the gridcube bind group layout (for volume grid cube rendering).

Source§

impl RenderEngine

Source

pub fn create_screenshot_target(&mut self) -> TextureView

Creates a screenshot texture for capturing frames.

Returns a texture view (HDR format) that can be used as a render target. The pipelines render to HDR format, so we need an HDR texture for rendering, then tone map to the final screenshot texture. After rendering to this view, call apply_screenshot_tone_mapping() then capture_screenshot() to get the pixel data.

Source

pub fn screenshot_texture_view(&self) -> Option<TextureView>

Returns the screenshot texture view (for tone mapping output).

Source

pub fn apply_screenshot_tone_mapping(&mut self, encoder: &mut CommandEncoder)

Applies tone mapping from the screenshot HDR texture to the final screenshot texture.

Source

pub fn screenshot_depth_view(&self) -> &TextureView

Returns the screenshot depth view for rendering.

Source

pub fn capture_screenshot(&mut self) -> Result<Vec<u8>, ScreenshotError>

Captures the screenshot after rendering to the screenshot target.

This method copies the screenshot texture to a buffer and reads it back. Call this after rendering to the view returned by create_screenshot_target().

Returns the raw RGBA pixel data.

Source

pub fn ssaa_factor(&self) -> u32

Returns the current SSAA factor (1 = off, 2 = 2x, 4 = 4x).

Source

pub fn set_ssaa_factor(&mut self, factor: u32)

Sets the SSAA factor and recreates render textures at the new resolution. Valid values are 1 (off), 2 (2x supersampling), or 4 (4x supersampling).

Source

pub fn ensure_depth_peel_pass(&mut self)

Ensures the depth peel pass is initialized and matches render resolution.

Source

pub fn depth_peel_pass(&self) -> Option<&DepthPeelPass>

Returns the depth peel pass, if initialized.

Source

pub fn depth_peel_pass_mut(&mut self) -> Option<&mut DepthPeelPass>

Returns a mutable reference to the depth peel pass, if initialized.

Source

pub fn hdr_view(&self) -> Option<&TextureView>

Returns the HDR texture view for rendering the scene.

Source

pub fn normal_view(&self) -> Option<&TextureView>

Returns the normal G-buffer view if available.

Source

pub fn ssao_noise_view(&self) -> Option<&TextureView>

Returns the SSAO noise texture view if available.

Source

pub fn ssao_output_view(&self) -> Option<&TextureView>

Returns the SSAO output texture view if available.

Source

pub fn ssao_pass(&self) -> Option<&SsaoPass>

Returns the SSAO pass.

Source

pub fn render_ssao( &self, encoder: &mut CommandEncoder, config: &SsaoConfig, ) -> bool

Renders the SSAO pass. Returns true if SSAO was rendered, false if resources are not available.

Source

pub fn tone_map_pass(&self) -> Option<&ToneMapPass>

Returns the tone map pass.

Source

pub fn update_tone_mapping( &self, exposure: f32, white_level: f32, gamma: f32, ssao_enabled: bool, )

Updates tone mapping uniforms.

Source

pub fn render_tone_mapping( &self, encoder: &mut CommandEncoder, output_view: &TextureView, )

Renders the tone mapping pass from HDR to the output view. Uses SSAO texture if available, otherwise uses a default white texture.

When SSAA is enabled (factor > 1):

  1. Downsamples HDR (SSAA res) → intermediate HDR (screen res)
  2. Tone maps intermediate HDR → output LDR (SSAO disabled — resolution mismatch)
Source§

impl RenderEngine

Source

pub fn default_matcap_bind_group(&self) -> &BindGroup

Returns the matcap bind group for the default material (“clay”).

Source

pub fn matcap_bind_group_for(&self, material_name: &str) -> &BindGroup

Returns the matcap bind group for a given material name. Falls back to the default material if the name is not found.

Source

pub fn render_ground_plane( &mut self, encoder: &mut CommandEncoder, surface_view: &TextureView, enabled: bool, scene_center: [f32; 3], scene_min_y: f32, length_scale: f32, height_override: Option<f32>, shadow_darkness: f32, shadow_mode: u32, reflection_intensity: f32, )

Renders the ground plane.

§Arguments
  • encoder - The command encoder
  • view - The render target view
  • enabled - Whether the ground plane is enabled
  • scene_center - Center of the scene bounding box
  • scene_min_y - Minimum Y coordinate of scene bounding box
  • length_scale - Scene length scale
  • height_override - Optional manual height (None = auto below scene)
  • shadow_darkness - Shadow darkness (0.0 = no shadow, 1.0 = full black)
  • shadow_mode - Shadow mode: 0=none, 1=shadow_only, 2=tile_with_shadow
  • reflection_intensity - Reflection intensity (0.0 = opaque, affects transparency)
Source

pub fn render_slice_planes( &mut self, encoder: &mut CommandEncoder, planes: &[SlicePlane], length_scale: f32, )

Renders slice plane visualizations.

Renders enabled slice planes as semi-transparent grids. Should be called after rendering structures, before tone mapping.

Source

pub fn render_slice_planes_with_clear( &mut self, encoder: &mut CommandEncoder, planes: &[SlicePlane], length_scale: f32, clear_color: [f32; 3], )

Renders slice plane visualizations with clearing.

Clears the HDR texture and depth buffer first, then renders slice planes. This should be called BEFORE rendering scene geometry so that geometry can properly occlude the slice planes.

Source

pub fn render_stencil_pass( &mut self, encoder: &mut CommandEncoder, color_view: &TextureView, ground_height: f32, scene_center: [f32; 3], length_scale: f32, )

Renders the ground plane to the stencil buffer for reflection masking.

This should be called before rendering reflected geometry. The stencil buffer will have value 1 where the ground plane is visible.

Source

pub fn reflection_pass(&self) -> Option<&ReflectionPass>

Returns the reflection pass.

Source

pub fn update_reflection( &self, reflection_matrix: Mat4, intensity: f32, ground_height: f32, )

Updates reflection uniforms.

Source

pub fn create_reflected_mesh_bind_group( &self, mesh_render_data: &SurfaceMeshRenderData, ) -> Option<BindGroup>

Creates a bind group for reflected mesh rendering.

Source

pub fn render_reflected_mesh( &self, render_pass: &mut RenderPass<'_>, mesh_bind_group: &BindGroup, vertex_count: u32, material_name: &str, )

Renders a single reflected mesh.

Call this for each visible surface mesh after render_stencil_pass.

Source

pub fn create_reflected_point_cloud_bind_group( &self, point_render_data: &PointCloudRenderData, ) -> Option<BindGroup>

Creates a bind group for reflected point cloud rendering.

Source

pub fn render_reflected_point_cloud( &self, render_pass: &mut RenderPass<'_>, point_bind_group: &BindGroup, point_count: u32, material_name: &str, )

Renders a single reflected point cloud.

Source

pub fn create_reflected_curve_network_bind_group( &self, curve_render_data: &CurveNetworkRenderData, ) -> Option<BindGroup>

Creates a bind group for reflected curve network rendering.

Source

pub fn render_reflected_curve_network( &self, render_pass: &mut RenderPass<'_>, curve_bind_group: &BindGroup, curve_render_data: &CurveNetworkRenderData, material_name: &str, )

Renders a single reflected curve network (tube mode).

Source§

impl RenderEngine

Source

pub fn create_normal_texture_with_size(&mut self, width: u32, height: u32)

Creates normal G-buffer texture at specified size.

Source§

impl RenderEngine

Source

pub async fn new_windowed(window: Arc<Window>) -> RenderResult<Self>

Creates a new windowed render engine.

Source

pub async fn new_headless(width: u32, height: u32) -> RenderResult<Self>

Creates a new headless render engine.

Source

pub fn resize(&mut self, width: u32, height: u32)

Resizes the render target.

Source

pub fn update_camera_uniforms(&self)

Updates camera uniforms.

Source

pub fn update_slice_plane_uniforms( &self, planes: impl Iterator<Item = SlicePlaneUniforms>, )

Updates slice plane uniforms from the provided slice plane data.

Takes an iterator of SlicePlaneUniforms and uploads them to the GPU buffer. Up to MAX_SLICE_PLANES planes are used; remaining slots are disabled.

Source

pub fn camera_buffer(&self) -> &Buffer

Gets the camera buffer.

Source

pub fn shadow_map_pass(&self) -> Option<&ShadowMapPass>

Gets the shadow map pass (if initialized).

Source

pub fn depth_view(&self) -> &TextureView

Returns the depth texture view.

Source

pub fn hdr_texture_view(&self) -> Option<&TextureView>

Returns the HDR texture view if available.

Source

pub fn dimensions(&self) -> (u32, u32)

Returns the viewport dimensions.

Source

pub fn render_dimensions(&self) -> (u32, u32)

Returns the render dimensions (accounting for SSAA).

Source

pub fn load_blendable_material( &mut self, name: &str, filenames: [&str; 4], ) -> Result<(), PolyscopeError>

Loads a blendable (4-channel RGB-tintable) material from disk.

Takes 4 image file paths for R, G, B, K matcap channels. Supports HDR, JPEG, PNG, EXR, and other formats via the image crate.

Source

pub fn load_static_material( &mut self, name: &str, filename: &str, ) -> Result<(), PolyscopeError>

Loads a static (single-texture, non-RGB-tintable) material from disk.

The same texture is used for all 4 matcap channels. Supports HDR, JPEG, PNG, EXR, and other formats via the image crate.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,