Fable.Ranvier.Wgpu 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Fable.Ranvier.Wgpu --version 0.1.0
                    
NuGet\Install-Package Fable.Ranvier.Wgpu -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fable.Ranvier.Wgpu" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fable.Ranvier.Wgpu" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Fable.Ranvier.Wgpu" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fable.Ranvier.Wgpu --version 0.1.0
                    
#r "nuget: Fable.Ranvier.Wgpu, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fable.Ranvier.Wgpu@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fable.Ranvier.Wgpu&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Fable.Ranvier.Wgpu&version=0.1.0
                    
Install as a Cake Tool

Fable.Ranvier.Wgpu

The Ranvier.Wgpu 3D scene API for the browser. It is compiled to JavaScript with Fickl and draws on WebGPU, or on WebGL2 where a browser has no WebGPU.

Cameras, instances, primitives, the stock shader and shader hooks are the same F# source files as the .NET package's, so a scene written for one runs on the other.

Install

dotnet add package Fable.Ranvier.Wgpu --version 0.1.0
dotnet tool install fickl

Quick start

open System.Numerics
open Fickl.Core
open Ranvier.Wgpu

let draw (canvas: obj) =
    jsAsync {
        let! ctx = WgpuContext.CreateAsync (canvas)
        let mesh = ctx.UploadMesh (Primitives.unitIcosphere 3)
        let batch = ctx.CreateBatch mesh

        batch.SetSingle (
            Instance3D.sphere Vector3.Zero 2.0f (RgbaColor.fromHex "#3b82f6") 0.28f 1u InstanceFlags.None
        )

        let camera = Camera3D.orbit Vector3.Zero 0.6f 0.4f 5.0f 45.0f

        let pass =
            ScenePass.create camera
            |> ScenePass.withClear (RgbaColor.fromHex "#090d16")
            |> ScenePass.withBatches [| batch |]

        ctx.Render pass |> ignore
        let! hit = ctx.PickAsync (ctx.Width / 2, ctx.Height / 2, pass)
        return hit
    }

Compile the project with dotnet fickl <project> --outDir <folder> and load the result as an ES module.

What differs from the .NET package

The browser's graphics APIs are asynchronous, so three members change:

.NET Browser
WgpuContext(...) constructor WgpuContext.CreateAsync(canvas, ?width, ?height, ?customWgsl, ?customGlsl, ?backend)
Pick PickAsync
ValidateWgsl ValidateWgslAsync, and ValidateGlslAsync for WebGL2
  • Render draws to the canvas. ReadPixelsAsync reads the last frame back.
  • There is no RenderInto, RgbaPixels, native backend choice or SDL surface.
  • A Vector3 or Matrix4x4 is a JavaScript object, so assigning one shares it. .NET copies it. Code that changes a field of a vector through one of two names sees the change through both.

Backends

backend is WgpuBrowserBackend.Auto (the default), WebGPU or WebGL2. Auto uses WebGPU when navigator.gpu gives an adapter and WebGL2 otherwise. ctx.BackendName reports which one draws.

A custom shader is given per language: customWgsl for WebGPU and customGlsl (GLSL ES 3.00) for WebGL2. Shaders.composeScene builds WGSL from the six hook points, and GlslShaders.composeScene builds GLSL from the same hook points. A context that lands on a backend whose language it was not given raises an exception; it does not draw the stock shader. A page that should run on both backends passes both.

Requirements

  • Fickl 0.11.0 or later. Earlier releases cannot compile System.Numerics vectors and spans.
  • .NET 10 (net10.0) and FSharp.Core 10.1.401 or later, which ships with .NET SDK 10.0.401.
  • A browser with WebGPU or WebGL2.

Current limits

  • The limits of Ranvier.Wgpu apply: no textures, lines are a one-pixel line list, and discs and blended batches are not depth-sorted.
  • Tested in Chrome on Windows. Firefox, Safari, Linux and macOS are not tested.
  • On WebGL2 through Direct3D 11, two frames of an unchanged scene can differ by one step of 255 in a few pixels where a line lies under a blended mesh.
  • A lost WebGPU device or WebGL context is not recovered.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Fable.Ranvier.Wgpu:

Package Downloads
Fable.Ranvier.D5.Wgpu

Browser/Fable 3D and multi-dimensional visualization scales, axes, encodings, surfaces, volumes and Ranvier reactive GPU sinks over Fable.Ranvier.Wgpu.

Fable.Ranvier.D5.Wgpu.Traced

Browser/Fable 3D and multi-dimensional visualization scales, axes, encodings, surfaces, volumes and Ranvier reactive GPU sinks over Fable.Ranvier.Wgpu.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 13 11/19/2026
0.2.1 118 11/19/2026
0.2.0 111 11/18/2026
0.1.1 72 11/16/2026
0.1.0 73 11/15/2026

Pre-1.0 release. The API may change before 1.0.