builtin library

The software rasteriser's own shading helpers — the stages it runs for the engine's materials, the varying slots they read and the surface they fill — for a package that compiles onto them, as flutter3d_app's material language does.

For engine packages; not covered by semver for applications. These follow the engine's shaders and change with them in any release. A library of its own rather than a src/ import, so what another package builds on is in this package's API snapshot and a change to it is seen in review.

The engine's packages ask for each other within one minor ('>=1.0.0 <1.1.0'), so a cpu 1.1 that changes these stages never resolves under an engine package 1.0 compiled onto the stages before them.

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.
CameraVelocityShader
camera_velocity.frag: how far this pixel moved because the camera did.
CausticPhotonShader
caustic_photon.frag: a photon's quad, given back into the atlas.
CausticPhotonVertexShader
caustic_photon.vert: one photon followed through a caster to where it lands, sized by where its neighbours land — the same arithmetic, with the instance index as the texel.
CausticSurfaceShader
caustic_surface.frag: a refracting caster's normal and depth, as the sun sees it — ShadowSettings.caustics.
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.
CpuMeshLayout
Where the engine's vertex attributes and the mesh stage's varyings sit, as float offsets, and how many of each there are. The numbers are cpu_shaders_layout.dart's, which cpu_mesh_layout_test.dart holds them to.
DebugLineShader
debug_line.frag: the colour, unchanged.
DebugLineVertexShader
debug_line.vert: position and colour, through one matrix.
DecalShader
decal.frag: the factor a decal multiplies the scene by, or the term it adds, by params.w.
DepthOfFieldShader
depth_of_field.frag: a thin lens and a gather — gfx-34n.
DepthPredrawShader
depth_predraw.frag: a surface's depth where it covers the pixel, and no colour — A1.2, A1.3.
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.accept is 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.
FullscreenVertexShader
fullscreen.vert.
FxaaShader
fxaa.frag: edges smoothed on the composited picture — gfx-04n.
HighContrastShader
post/high_contrast.frag: flatten, tone, outline, roles.
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.
LensFlareShader
lens_flare.frag.
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.
OutlineMaskShader
post/outline_mask.frag: a marked node, drawn through the velocity vertex stages — v_depth is varying eight — in its outline colour, and nothing behind what the opaque scene drew there.
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
PlanarReflectionShader
planar_reflection.frag: the texel of the reflection under this pixel, by its place in the view, weighted by Schlick's Fresnel and fogged.
ProbePrefilterShader
probe_prefilter.frag.
ReactiveShader
post/reactive.frag: a blended surface, drawn through the velocity vertex stages — v_depth is varying eight.
ReactiveSpriteShader
post/reactive_sprite.frag: a particle or a splat, through particle.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.
RenderTextureEncodeShader
render_texture_encode.frag: the light times the exposure, clipped to one and encoded as sRGB.
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.
ShadowTransmittanceShader
shadow_transmittance.frag: what a see-through caster lets through to the sun — ShadowSettings.translucentCasters.
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.
SkyPhysicalShader
sky_physical.frag: sunlight scattered once by molecules and by haze along the view ray, the disc and the stars through what the air leaves, and the ground below the horizon — P5.
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.
SmaaBlendShader
smaa_blend.frag.
SmaaEdgesShader
smaa_edges.frag.
SmaaWeightsShader
smaa_weights.frag.
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 ReadSurface produces, for the models that need more than the albedo. Mutable, because the GLSL passes it as inout to 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.
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-44n and gfx-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.
shadowSlots → const int
Atlas rows, from kShadowSlots in surface.glsl.
ssaoKernel → const List<List<double>>
The twelve kernel taps of ssao.frag, in the same order.

Properties

shadowTransmittance → Vector3
ShadowFactor: how much of the directional light survives here.
final

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 color) → Vector3
AgxSigmoid from composite.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 color, Float32List v, ShaderBindings b) → Vector3
ApplyFog from color.glsl: fades color toward 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 occlusionStrength lerps 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
BayerCell from reflections.frag and light_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
BlueNoise from lib/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 of world's cell start, and how many.
clustered(ShaderBindings bindings) → bool
Clustered — L6.
clusterRow(ShaderBindings bindings, Vector3 world, int slot) → int
ClusterRow: the row entry slot of world's cell names.
contributorLight(ShaderBindings bindings, int index, Vector3 world) → ({Vector3 radiance, Vector3 toLight})
ContributorLight — N6: light index as world receives 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
ContributorLightCount from lib/contributor_lights.glsl — N6: the slots a contributor's draw holds, and the list's tail or the cell's.
decodeSurfaceNormal(double ex, double ey) → Vector3
DecodeOctahedral, the inverse of what the surface buffer stored.
encodeSurfaceNormal(Vector3 n) → Vector2
EncodeOctahedral from color.glsl: a unit normal in two channels.
eyeDistance(Float32List v, ShaderBindings b) → double
EyeDistance: how far this fragment is from the camera, in world metres.
fogDistance(ShaderBindings b, double x, double y, double z) → double
FogDistance of contributor_eye.glsl: the air between a point and the eye — the distance to it, or the depth from its plane through an orthographic lens.
fract(double x) → double
hashedAlphaNoise(double x, double y, double z, double cutoff) → double
HashedAlphaNoise in surface.glsl and depth_predraw.frag, operation for operation: the noise a hashed alpha is compared with at the scene-space point (x, y, z), counted in sixteenths of a metre from where the world starts. cutoff is the hashed sentinel, -2 less the scene's origin in those cells, each below 128, which the renderer packs.
inSlots(ShaderBindings bindings, int row) → bool
InSlots: whether one of the draw's slots already holds row row.
irradianceEnabled(ShaderBindings b) → bool
Whether the field is read this draw.
lightCount(ShaderBindings bindings, Vector3 world) → int
LightCount(): the count lives in frame_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 slot slot of the tail reads.
lightListScale(ShaderBindings bindings, int slot) → double
LightListScale: how much of slot slot survives the edge fade.
lightListTexel(ShaderBindings bindings, int row, int column) → Vector4
One texel of the light list, at row row and column column.
mapUv(int slot, Float32List v, ShaderBindings b, FragmentContext c, {bool transformed = false}) → ({UvFootprint footprint, double u, double v})
MapUv(slot): where map slot is read, with the footprint there — C8.
materialLodBias(ShaderBindings b) → double
MaterialLodBias(): the bias every material map is read with — R2.
nonFinite(Vector3 c) → bool
NonFinite from surface.glsl: NaN or infinite in any channel.
orthographic(ShaderBindings b) → bool
Orthographic — P7: whether FogInfo.projection.x says the camera projects orthographically. False where the block is not bound, which is what the GLSL's F3D_NO_FOG stages are.
pixelNoise(ShaderBindings b, double x, double y) → double
PixelNoise from lib/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 through u, v starts 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_premultiply as ReadSurface sets it: material2.x between -1 and nought, which the engine writes for MaterialAlphaMode.blend alone.
probeFaceDirection(int face, double s, double t) → Vector3
The direction the texel at (s, t) of face looks along, with t measured down the face from row zero.
readSurface(Float32List v, ShaderBindings bindings, FragmentContext c, {bool transformed = false}) → Surface?
ReadSurface from surface.glsl.
rectangleClosestPoint(Vector3 center, 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 as rgb × 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
shadowNoise(ShaderBindings b, FragmentContext? c) → double
ShadowNoise from shadow.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's SoftParticleFade: how much of a particle fragment at world (x, y, z) is left once it nears the scene the surface buffer holds at c'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's identity, a whole number in [0, 4096): column and row, each whole.
toLinear(double c) → double
sRGB to linear, per color.glsl.
tonemapAces(Vector3 color) → Vector3
TonemapAces from composite.frag: the Narkowicz fit.
tonemapAces2(Vector3 color) → Vector3
The ACES 2.0 SDR tonescale (100 nits), hue held, with a path to white — what make_tables.dart bakes into EngineTables.aces2Display — L2.
tonemapAgx(Vector3 color) → Vector3
TonemapAgx from composite.frag: inset, sigmoid, outset, linearise.
tonemapAgxFull(Vector3 color) → Vector3
TonemapAgxFull from composite.frag: code 5, now the same transform as tonemapAgx.
tonemapBy(Vector3 color, int curve) → Vector3
TonemapBy from composite.frag: whichever curve the number names.
tonemapNeutral(Vector3 color) → Vector3
The Khronos PBR Neutral tone mapper, from composite.frag.
tonemapReinhard(Vector3 color) → Vector3
TonemapReinhard from composite.frag, extended so white reaches white.
toSrgb(double c) → double
Linear to sRGB, the inverse.
towardsEye(Float32List v, ShaderBindings b) → Vector3
TowardsEye — P7: back along the ray that reached this fragment, to the eye through a perspective lens and against the view axis through an orthographic one.
towardsEyeFrom(ShaderBindings b, double x, double y, double z) → Vector3
TowardsEyeFrom of contributor_eye.glsl: the unit direction back along the ray that reached a point, nought at the eye.
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)
VogelDisc from shadow.glsl — S3.
weightedBlendedWeight(double alpha, Float32List v, ShaderBindings b) → double
WeightedBlendedWeight from color.glsl — R8: McGuire and Bavoil's depth weight, times alpha.
worldAtDepth(Matrix4 inverse, Vector3 eye, Vector3 axis, double u, double v, double depth) → Vector3
WorldAtDepth / WorldAt: the point uv is looking at, depth metres along the view axis.
writeDebugView(FragmentContext c, Float32List v, ShaderBindings b, Surface s, Vector3 lit, {bool transformed = false, Vector3? geometric}) → Vector4?
WriteDebugView from surface.glsl — P6: the material channel FragInfo.debug_view asks for, in place of lit, or null when no view is on or the fragment sits left of the split, and the caller writes the light.
writeLit(FragmentContext c, Float32List v, ShaderBindings b, {required Vector3 color, required double alpha, required Vector3 normal, required double roughness, double passThrough = 0.0}) → Vector4
WriteSurface from color.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 color) → Vector4
WriteWeightedBlended from color.glsl — R8: color as it stands unless FogInfo.forward.w asks 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 SampleLight produces.
UvFootprint = ({double du, double dudx, double dudy, double dv, double dvdx, double dvdy})
What uvFootprint returns.