run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final texture = b.textures['particle_texture'];
var texel = Vector4(1, 1, 1, 1);
if (texture != null) {
// The larger of the two directions per axis. A hardware sampler uses the
// longer side of the whole footprint parallelogram; taking the maximum of
// the axis-aligned components is the same thing for a quad facing the
// camera, which every billboard is by construction.
var du = 0.0;
var dv = 0.0;
final ddx = c.ddx;
final ddy = c.ddy;
if (ddx != null && ddy != null) {
du = math.max(ddx[4].abs(), ddy[4].abs());
dv = math.max(ddx[5].abs(), ddy[5].abs());
}
texel = texture.sample(v[4], v[5], du: du, dv: dv);
}
var fogged = 1.0;
final fog = b.vec4('FogInfo', 'fog', Vector4.zero());
if (fog.w > 0.0) {
final d = fogDistance(b, v[6], v[7], v[8]);
fogged = math.exp(-fog.w * d).clamp(0.0, 1.0);
}
// The texture's alpha is coverage and the particle's is brightness, so the
// two multiply.
final scale =
v[3] *
texel.w *
fogged *
(soft ? softParticleFade(b, c, v[6], v[7], v[8]) : 1.0);
return Vector4(
v[0] * texel.x * scale,
v[1] * texel.y * scale,
v[2] * texel.z * scale,
1.0,
);
}