flutter3d_cpu library
A flutter3d_hardware backend that rasterises in Dart.
Two hardware backends agreeing proves less than it looks like: both are driven by a C API and both rasterise on a GPU, so an assumption shared by graphics hardware would be invisible to the pair of them. This one shares nothing with either — no driver, no shading language, no command buffer.
Whether that was really allowed is what running it answers.
Classes
- BlinnPhongShader
-
blinn_phong.frag: a Phong highlight on top of the albedo. - BloomDownsampleShader
-
bloom_downsample.frag: the thirteen-tap filter, four boxes plus five. - BloomThresholdShader
-
bloom_threshold.frag: what is bright enough to glow. - BloomUpsampleShader
-
bloom_upsample.frag: a 1-2-1 tent over sixteen. - BoundTexture
- A texture with the sampler it was bound with.
- CameraVelocityShader
-
camera_velocity.frag: how far this pixel moved because the camera did. - CompositeShader
-
composite.frag: add the bloom, expose, tone map, encode. - ContactShadowResolveShader
-
contact_shadow_resolve.frag: the march above averaged over one window of the Bayer pattern, depth-aware, for a frame no temporal resolve smooths. - ContactShadowShader
-
contact_shadow.frag: whether the sun reaches this point over the first few centimetres, which is the stretch a shadow map cannot answer for. - CpuComputeBindings
- What a compute stage is handed: its storage buffers and uniform blocks, by the names the GLSL gives them.
- CpuComputeShader
-
A compute stage in Dart, standing in for a
.compshader —H6. - CpuDevice
- The software backend.
- CpuEncoder
-
Records state and rasterises on
draw. - CpuFragmentShader
- Turns interpolated varyings into a colour.
- CpuLoadedShaderLibrary
- A bundle loaded from bytes, on the backend that compiles nothing.
- CpuPipeline
- A vertex and a fragment stage, paired.
- CpuShaderLibrary
- A library of Dart stages, by the names the engine asks for.
- CpuStage
- A stage, which is one or the other.
- CpuTexture
- A texture as this backend holds one: linear float RGBA, row zero at the top.
- CpuVertexShader
- Turns one vertex into a clip position and some varyings.
- CpuVertexShaderByIndex
- A vertex stage that also wants to know which vertex it is running on.
- DebugLineShader
-
debug_line.frag: the colour, unchanged. - DebugLineVertexShader
-
debug_line.vert: position and colour, through one matrix. - DepthOfFieldShader
-
depth_of_field.frag: a thin lens and a gather —gfx-34n. - DepthPyramidShader
-
depth_pyramid.frag: the farthest view depth under each texel's block of the surface buffer, as 24 bits of the far plane, and in alpha whether the whole block was drawn and how near its nearest depth comes to that —C3.HiZOcclusion.acceptis the other end. - DofTileMaxShader
-
dof_tile_max.frag: the largest circle of confusion along one row of a tile —gfx-34n. The columns and the neighbourhood after it are the motion blur's own passes. - EasuShader
-
easu.frag: the edge-adaptive upscale —R5. Mirrors the GLSL tap for tap: twelve taps, the edge's direction and length from the four nearest, an approximated Lanczos-2 stretched along the edge, and the result held between the four nearest. - FieldDecayShader
-
field_decay.frag: every texel times a factor plus a constant —H5. - FragmentContext
- Everything a fragment stage gets that is not a varying or a binding.
- FrameDifference
- What two frames of the same size disagree about.
- FullscreenVertexShader
-
fullscreen.vert. - FxaaShader
-
fxaa.frag: edges smoothed on the composited picture —gfx-04n. - IrradianceConvolveShader
-
probe/irradiance_convolve.frag—L4: one probe's two tiles updated from its capture, everything else copied through. - LambertShader
-
lambert.frag: pure diffuse, the cheapest model that still reads as three-dimensional. - LayoutFetch
- Several buffers, some stepping per vertex and some per instance.
- LightShaftsShader
-
light_shafts.frag: volumetric shafts marched through the shadow map —gfx-33n. - LocalExposureBlurShader
-
local_exposure_blur.frag: the weights blurred along one axis, and on the second run the exposure in stops —R7. - LocalExposureShader
-
local_exposure.frag: how well exposed each place would be at three exposures —R7. - LuminanceShader
-
luminance.frag: the scene's log luminance, sixteen taps per texel, in eight bits. - MeshInstancedVertexShader
-
mesh_skinned.vert: the mesh stage with a joint blend in front of it. - MeshLightmappedVertexShader
-
mesh_lightmapped.vert: the mesh stage reading its colour as a place in the level's lightmap. - MeshSkinnedVertexShader
- MeshVertexShader
-
The mesh vertex stage —
mesh.vert. - MotionBlurShader
-
motion_blur.frag: the gather along each neighbourhood's dominant motion, composited as the time each sample covers the pixel. - MrtProbeShader
-
mrt_probe.frag: two constants into two attachments. - NormalsShader
-
normals.frag: the world normal as colour. - ObjectIdShader
-
object_id.frag: the id the renderer handed this draw, as three bytes. - PackedFetch
- One interleaved buffer, in the order the shader declares its inputs.
- ParticleMeshShader
-
particle_mesh.frag: additive, fogged, shaded by which way a face points. - ParticleMeshVertexShader
-
particle_mesh.vert: one mesh, placed and tinted per instance. - ParticleShader
-
particle.frag: a radial falloff, premultiplied, fogged. - ParticleSixWayShader
-
particle_six_way.frag—N6: smoke lit by the scene's lights through six pictures of itself, blended over what is behind it. - ParticleTexturedShader
-
particle_textured.frag: a sprite, premultiplied, fogged, and mipped. - ParticleVertexShader
-
particle.vert: a billboard corner, and the world position for the fog. - PbrShader
- ProbePrefilterShader
-
probe_prefilter.frag. - ReactiveShader
-
post/reactive.frag: a blended surface, drawn through the velocity vertex stages —v_depthis varying eight. - ReactiveSpriteShader
-
post/reactive_sprite.frag: a particle or a splat, throughparticle.vert— colour in 0..3, the quad's coordinates in 4..5, the world position in 6..8. - ReflectionsShader
-
reflections.frag: screen-space reflections, marched against the surface buffer. - SceneColourCopyShader
-
scene_colour_copy.frag—M3: one level of the copy of the scene the transmissive draws read, the mean of the block of the scene under each texel, taken as the stage takes it — bilinear taps on the corners inside the block, rows outside and columns inside, in the stage's order. - ShaderBindings
-
A map rather than a generated struct, because the binding contract is by
name: the engine writes
bindUniformBlock(shader, 'FragInfo', {...})and a backend looks the members up. A Dart shader does the same lookup. - ShadowCopyShader
-
shadow_copy.frag: one cascade's tile of the static atlas, into colour and depth —S1. - ShadowDepthMaskedShader
-
shadow_depth_masked.frag: window depth, where the caster is opaque enough —gfx-60n. - ShadowDepthShader
-
shadow_depth.frag: window depth into a colour target. - ShadowDistanceMaskedShader
-
shadow_distance_masked.frag: the point-light twin of the above. - ShadowDistanceShader
-
shadow_distance.frag: radial distance from a point light, over its range. - ShadowTileResetShader
-
shadow_tile_reset.frag: one, the far end of the range. - ShadowTileResetVertexShader
-
shadow_tile_reset.vert: the fullscreen triangle, but on the far plane. - SkyCubeShader
-
sky_cube.frag: the same ray, sampled out of a cube map. - SkyCubeVertexShader
-
sky_cube.vert: the same triangle, carrying a tint instead of a preset. - SkyShader
-
sky.frag: the gradient, the scattering lobe and the disc. - SkyVertexShader
-
sky.vert: a full-screen triangle at the far plane, carrying its own data. - SplatHashedShader
-
splat_hashed.frag—N5: the splat kept or dropped whole at a pixel, against noise, and written opaque. - SplatShader
-
splat.frag—gfx-80n. - SsaoBlurShader
-
ssao_blur.frag: the depth-aware smoothing over what SsaoShader drew —gfx-32n. - SsaoShader
-
ssao.frag: how much of the sky a point can see. - Surface
-
What
ReadSurfaceproduces, for the models that need more than the albedo. Mutable, because the GLSL passes it asinoutto every map function and each one modifies a field. A copy-returning version would read better and would be a different program. - TemporalAccumulateShader
-
temporal_accumulate.frag—R3: a noisy effect blended into its own history, clamped to this frame's neighbourhood. - TemporalResolveShader
-
temporal_resolve.frag: this frame blended into the ones before it. - ToonShader
-
toon.frag: the diffuse response quantised into bands, plus a rim term. - UnlitShader
-
unlit.frag: the albedo, written into the HDR target as light. - VelocityInstancedVertexShader
-
velocity_instanced.vert: each instance placed by its transform now (slot 1) and by last frame's (slot 2). - VelocityNeighborMaxShader
-
velocity_neighbor_max.frag: the longest motion in a tile and the eight around it. - VelocityShader
-
post/velocity.frag: the two clip positions, divided here, differenced in UV — for a fragment the scene's surface buffer says is in front. - VelocitySkinnedVertexShader
-
velocity_skinned.vert: skinned by this frame's palette and by last frame's, which arrives as a 4 × 64 float texture of columns. - VelocityTileMaxShader
-
velocity_tile_max.frag: the longest motion along one axis of a tile. - VelocityVertexShader
-
velocity.vert: a moved mesh through this frame's and last frame's matrices. The pipeline's layout declares the position alone. - VertexFetch
- VertexTextureProbeShader
-
probe/vertex_texture.frag: what the vertex stage sampled, unchanged. - VertexTextureProbeVertexShader
-
probe/vertex_texture.vert: sample, and pass what was sampled through. - ViewportShadeShader
-
viewport_shade.frag: shading read out of the surface buffer —gfx-43n,gfx-44nandgfx-45n. - VolumetricFogShader
-
volumetric_fog.frag: in-scatter in rgb, transmittance in alpha. - VolumetricFogUpsampleShader
-
volumetric_fog_upsample.frag: the four nearest fog texels, weighed by their bilinear share and by how near their depth is to the pixel's. - WboitResolveShader
-
wboit_resolve.frag—R8: the weighted average of the transparent layers, covering as much of the pixel as they do together, premultiplied for the source-over it is drawn with. - XrayShader
-
xray.frag: the same albedo, and not one word about the surface.
Constants
-
diskTaps
→ const List<
List< double> > -
The Poisson disk the cube filter rotates, from
PointShadowDiskTap. - kColour → const int
- kExtraLights → const int
-
kExtraLightsinlib/surface.glsl—gfx-74n. - kMapBaseColor → const int
-
The maps a lit material reads, in
kMapBaseColor's order —C8. - kMapEmissive → const int
- kMapMetallicRoughness → const int
- kMapNormal → const int
- kMapOcclusion → const int
- kMaxLights → const int
-
Lights per frame, from
kMaxLightsinsurface.glsl. - kMeshVaryings → const int
- kNormal → const int
- kPosition → const int
- Where each attribute sits in the sixteen floats the engine lays out.
- kTangent → const int
- kTexcoord → const int
-
kUnimplementedCpuFragmentShaders
→ const List<
String> - The fragment half of kUnimplementedCpuVertexShaders.
-
kUnimplementedCpuVertexShaders
→ const List<
String> - The stages that are not written in Dart, by name.
- kVColour → const int
- kVLightmap → const int
- Where the fragment is in the level's lightmap; zero from every stage but the lightmapped one, which reads it out of the colour attribute.
- kVNormal → const int
- kVTangent → const int
- kVUv → const int
- kVWorld → const int
- The varyings this backend's mesh stage carries.
- shadowSlots → const int
-
Atlas rows, from
kShadowSlotsinsurface.glsl. -
ssaoKernel
→ const List<
List< double> > -
The twelve kernel taps of
ssao.frag, in the same order.
Functions
-
accumulateLights(
Surface s, ShaderBindings b, FragmentContext c, {required Vector3 shade(Surface s, LightSample light), required bool shadowed}) → Vector3 -
AccumulateLights, with the model's own response passed in. -
agxSigmoid(
Vector3 colour) → Vector3 -
AgxSigmoidfromcomposite.frag: the log sigmoid, display-encoded out. -
applyCommonMaps(
Surface s, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → void - The three every lit model uses. Metal-rough is separate because only the models that respond to metallic or roughness may sample it.
-
applyEmissiveMap(
Surface s, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → void -
applyFog(
Vector3 colour, Float32List v, ShaderBindings b) → Vector3 -
ApplyFogfromcolor.glsl: fadescolourtoward the fog with distance. -
applyMetallicRoughnessMap(
Surface s, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → void - glTF's ORM packing: roughness in g, metallic in b.
-
applyNormalMap(
Surface s, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → void - Perturbs the normal by the tangent-space map.
-
applyOcclusionMap(
Surface s, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → void -
glTF's
occlusionStrengthlerps between ignoring the map and applying it in full, which is why this is a mix and not a multiply. -
atlasDistance(
ShaderBindings b, double u, double v, double ox, double oy, double tileX, double tileY, double range, double inset) → double -
PointShadowDistance: one comparison against the atlas. -
attenuation(
double distance, double range) → double -
PunctualAttenuation: inverse square with glTF's range window. -
bayerCell(
double x, double y) → double -
BayerCellfromreflections.fragandlight_shafts.frag: one cell of a 4x4 Bayer matrix at window position (x,y), in [0, 1). -
bloomSource(
ShaderBindings b) → ({Vector4 params, BoundTexture source, double tx, double ty})? - What the three bloom stages share: the source texture and its texel size.
-
blueNoise(
ShaderBindings b, double x, double y) → double -
BlueNoisefromlib/blue_noise.glsl—R3: this frame's slice of the engine's blue noise at the pixel (x,y), in [0, 1). -
builtinCpuShaders(
) → Map< String, CpuStage> - Every stage, by the name the engine uses.
-
clusterAt(
ShaderBindings bindings, Vector3 world) → ({double count, double offset}) -
FindCluster: where the entries ofworld's cell start, and how many. -
clustered(
ShaderBindings bindings) → bool -
Clustered—L6. -
clusterRow(
ShaderBindings bindings, Vector3 world, int slot) → int -
ClusterRow: the row entryslotofworld's cell names. -
compareFrames(
Uint8List a, Uint8List b, {int channel = 8, bool alpha = false}) → FrameDifference - Compares two RGBA frames of the same size.
-
contributorLight(
ShaderBindings bindings, int index, Vector3 world) → ({Vector3 radiance, Vector3 toLight}) -
ContributorLight—N6: lightindexasworldreceives it, with no surface to face. A rectangle is read as a point at its centre, as the GLSL reads it. -
contributorLightCount(
ShaderBindings bindings, Vector3 world) → int -
ContributorLightCountfromlib/contributor_lights.glsl—N6: the slots a contributor's draw holds, and the list's tail or the cell's. -
decodeOctahedral(
double ex, double ey) → Vector3 -
DecodeOctahedral, the inverse of what the surface buffer stored. -
differingPixels(
Uint8List a, Uint8List b, {int channel = 8, bool alpha = false}) → int - How many pixels differ, for a caller that only wants the count.
-
encodeOctahedral(
Vector3 n) → Vector2 -
EncodeOctahedralfromcolor.glsl: a unit normal in two channels. -
encodePng(
Uint8List rgba, int width, int height) → Uint8List -
rgbaas a PNG: 8-bit RGBA, one IDAT, rows from the top. -
ensureCpuBackendRegistered(
) → void - Registers CpuDevice as the native fallback opener, once.
-
eyeDistance(
Float32List v, ShaderBindings b) → double -
EyeDistance: how far this fragment is from the camera, in world metres. -
fract(
double x) → double -
inSlots(
ShaderBindings bindings, int row) → bool -
InSlots: whether one of the draw's slots already holds rowrow. -
irradianceEnabled(
ShaderBindings b) → bool - Whether the field is read this draw.
-
lightCount(
ShaderBindings bindings, Vector3 world) → int -
LightCount(): the count lives inframe_params.y, not in a member of its own. Reading a member that does not exist is silent, which is how the first version of this file drew an unlit scene. -
lightListLane(
ShaderBindings bindings, String member, int slot) → double -
LightListLane: one lane of a six-vector table. -
lightListRow(
ShaderBindings bindings, int slot) → double -
LightListRow: which row of the light texture slotslotof the tail reads. -
lightListScale(
ShaderBindings bindings, int slot) → double -
LightListScale: how much of slotslotsurvives the edge fade. -
lightListTexel(
ShaderBindings bindings, int row, int column) → Vector4 -
One texel of the light list, at row
rowand columncolumn. -
mapUv(
int slot, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → ({UvFootprint footprint, double u, double v}) -
MapUv(slot): where mapslotis read, with the footprint there —C8. -
materialLodBias(
ShaderBindings b) → double -
MaterialLodBias(): the bias every material map is read with —R2. -
pixelNoise(
ShaderBindings b, double x, double y) → double -
PixelNoisefromlib/blue_noise.glsl: the blue noise while a temporal resolve runs, bayerCell otherwise. -
pixelRay(
Matrix4 inverse, double u, double v) → ({Vector3 along, Vector3 origin}) -
PixelRay: where the ray throughu,vstarts and which way it goes. -
pointShadowFactor(
ShaderBindings b, Vector3 world, Vector3 normal, int lightIndex, FragmentContext c) → double -
PointShadowFactor: how lit a point is by the light that owns the atlas. -
premultiplies(
ShaderBindings b) → bool -
g_premultiplyasReadSurfacesets it:material2.xbetween -1 and nought, which the engine writes forMaterialAlphaMode.blendalone. -
probeFaceDirection(
int face, double s, double t) → Vector3 -
The direction the texel at (
s,t) offacelooks along, withtmeasured down the face from row zero. -
readSurface(
Float32List v, ShaderBindings bindings, FragmentContext c, {bool transformed = false}) → Surface? -
ReadSurfacefromsurface.glsl. -
rectangleClosestPoint(
Vector3 centre, Vector3 halfWidth, Vector3 halfHeight, Vector3 world, Vector3 mirror) → Vector3 -
RectangleClosestPoint— the representative point for the specular lobe. -
rectangleFormFactor(
List< Vector3> corners, Vector3 n) → double -
RectangleFormFactor—gfx-77n. -
sampleIrradiance(
ShaderBindings b, Vector3 world, Vector3 normal, Vector3 view) → Vector3 -
SampleIrradiance(world, normal, view). -
sampleLight(
ShaderBindings bindings, int index, Surface s) → LightSample? -
SampleLight. -
sampleLightmap(
Float32List v, ShaderBindings b, FragmentContext c) → Vector3 -
SampleLightmap: the baked irradiance at this fragment, RGBM-decoded asrgb × a × 8, or black when the slot holds the renderer's one-texel fallback — which is every material without a map. -
shadowFactor(
Surface s, ShaderBindings b, int lightIndex, double lightNDotL, [FragmentContext? c]) → double -
ShadowFactor: how much of the directional light survives here. -
shadowNoise(
ShaderBindings b, FragmentContext? c) → double -
ShadowNoisefromshadow.glsl—S3: interleaved gradient noise at the pixel, rows counted from the top, stepped by the frame's slice while a resolve runs. -
smoothstep(
double edge0, double edge1, double x) → double -
softParticleFade(
ShaderBindings b, FragmentContext c, double x, double y, double z) → double -
lib/particle_soft.glsl'sSoftParticleFade: how much of a particle fragment at world(x, y, z)is left once it nears the scene the surface buffer holds atc's pixel — one a softness in front or further, nought at it, and one where nothing was drawn. -
splatNoiseOffset(
double identity) → (double, double) -
splat_hashed.frag's offset into the 64 × 64 noise tile for a splat'sidentity, a whole number in[0, 4096): column and row, each whole. -
toLinear(
double c) → double -
sRGB to linear, per
color.glsl. -
tonemapAces(
Vector3 colour) → Vector3 -
TonemapAcesfromcomposite.frag: the Narkowicz fit. -
tonemapAces2(
Vector3 colour) → Vector3 -
The ACES 2.0 SDR tonescale (100 nits), hue held, with a path to white —
what
make_tables.dartbakes intoEngineTables.aces2Display—L2. -
tonemapAgx(
Vector3 colour) → Vector3 -
TonemapAgxfromcomposite.frag: inset, sigmoid, outset, linearise. -
tonemapAgxFull(
Vector3 colour) → Vector3 -
TonemapAgxFullfromcomposite.frag: code 5, now the same transform as tonemapAgx. -
tonemapBy(
Vector3 colour, int curve) → Vector3 -
TonemapByfromcomposite.frag: whichever curve the number names. -
tonemapNeutral(
Vector3 colour) → Vector3 -
The Khronos PBR Neutral tone mapper, from
composite.frag. -
tonemapReinhard(
Vector3 colour) → Vector3 -
TonemapReinhardfromcomposite.frag, extended so white reaches white. -
toSrgb(
double c) → double - Linear to sRGB, the inverse.
-
uvFootprint(
FragmentContext c, {double bias = 0.0}) → UvFootprint - How far the texture coordinate moves per screen pixel, for mip selection.
-
viewDepth(
Float32List v, ShaderBindings b) → double -
ViewDepth: how far this fragment is along the view axis, in world metres. -
vogelDisc(
int i, int n, double turn) → (double, double) -
VogelDiscfromshadow.glsl—S3. -
weightedBlendedWeight(
double alpha, Float32List v, ShaderBindings b) → double -
WeightedBlendedWeightfromcolor.glsl—R8: McGuire and Bavoil's depth weight, timesalpha. -
worldAtDepth(
Matrix4 inverse, Vector3 eye, Vector3 axis, double u, double v, double depth) → Vector3 -
WorldAtDepth/WorldAt: the pointuvis looking at,depthmetres along the view axis. -
writeLit(
FragmentContext c, Float32List v, ShaderBindings b, {required Vector3 colour, required double alpha, required Vector3 normal, required double roughness}) → Vector4 -
WriteSurfacefromcolor.glsl: the lit colour, faded by the fog, written beside the surface geometry. -
writeSurface(
FragmentContext c, Float32List v, ShaderBindings b, Vector3 normal, double roughness) → void -
WriteSurfaceGeometry: the octahedral normal, the roughness, the depth. -
writeWeightedBlended(
FragmentContext c, Float32List v, ShaderBindings b, Vector4 colour) → Vector4 -
WriteWeightedBlendedfromcolor.glsl—R8:colouras it stands unlessFogInfo.forward.wasks for the accumulation target's share (1), the revealage target's (2), or both, the second into attachment one (3).
Typedefs
-
LightSample
= ({List<
Vector3> ? corners, Vector3 direction, Vector3? ltc, double nDotH, double nDotL, Vector3 radiance, double vDotH}) -
What
SampleLightproduces. - UvFootprint = ({double du, double dudx, double dudy, double dv, double dvdx, double dvdy})
- What uvFootprint returns.