Fable.Ranvier.Wgpu
0.2.1
See the version list below for details.
dotnet add package Fable.Ranvier.Wgpu --version 0.2.1
NuGet\Install-Package Fable.Ranvier.Wgpu -Version 0.2.1
<PackageReference Include="Fable.Ranvier.Wgpu" Version="0.2.1" />
<PackageVersion Include="Fable.Ranvier.Wgpu" Version="0.2.1" />
<PackageReference Include="Fable.Ranvier.Wgpu" />
paket add Fable.Ranvier.Wgpu --version 0.2.1
#r "nuget: Fable.Ranvier.Wgpu, 0.2.1"
#:package Fable.Ranvier.Wgpu@0.2.1
#addin nuget:?package=Fable.Ranvier.Wgpu&version=0.2.1
#tool nuget:?package=Fable.Ranvier.Wgpu&version=0.2.1
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.2.1
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 |
Renderdraws to the canvas.ReadPixelsAsyncreads the last frame back.- There is no
RenderInto,RgbaPixels, native backend choice or SDL surface. - A
Vector3orMatrix4x4is 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.Numericsvectors and spans. - .NET 10 (
net10.0) andFSharp.Core10.0.100 or later, which ships with the first .NET 10 SDK, so any .NET 10 SDK builds against this package. Version 0.1.0 requiredFSharp.Core10.1.401 (.NET SDK 10.0.401). - A browser with WebGPU or WebGL2.
Current limits
- The limits of
Ranvier.Wgpuapply: 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 | Versions 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. |
-
net10.0
- Fickl.Core (>= 0.11.0)
- FSharp.Core (>= 10.0.100)
NuGet packages (6)
Showing the top 5 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. |
|
|
Fable.Ranvier.D5.Wgpu.View
Browser WebGPU and WebGL2 interactive 3D plot host and multi-pass subplot grid for Fable.Ranvier.D5.Wgpu over Ranvier.View.Dsl. |
|
|
Fable.Ranvier.D5.Wgpu.View.Traced
Browser WebGPU and WebGL2 interactive 3D plot host and multi-pass subplot grid for Fable.Ranvier.D5.Wgpu over Ranvier.View.Dsl. |
|
|
Fable.Ranvier.D5.Graph3D.Wgpu
Browser/Fable adapters and reactive GPU sinks bridging Ranvier.D5.Graph3D layouts to Fable.Ranvier.D5.Wgpu. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Pre-1.0 release. The API may change before 1.0.