Intrinsics1 min read

ddy_fine

Computes a fine-grained partial derivative in screen-space y.

Reading Time
1 min
Word Count
161
Sections
11
Try It Live

Test ddy_fine in a live shader

Open the playground, start from a visual preset, and wire ddy_fine into the fragment stage to see how it behaves with real values.

Open Playground

Live Demo

The ddy_fine function computes a high-precision partial derivative in the y direction, using the minimum 2x2 quad for calculation.

Signature

bwsl
ddy_fine :: (T x) -> T {...}

Where T can be float, float2, float3, or float4.

Parameters

ParameterTypeDescription
xTThe value to differentiate

Return Value

Returns the fine-grained rate of change of x in the vertical direction.

Example

bwsl
pipeline SDFShapes {
@fragment_only
fragment {
// Signed distance to circle
float2 centered = input.uv - 0.5;
float sdf = length(centered) - 0.3;
// Use fine derivatives for crisp edges
float gradX = ddx_fine(sdf);
float gradY = ddy_fine(sdf);
float edgeWidth = length(float2(gradX, gradY));
// Smooth anti-aliased edge
float shape = 1.0 - smoothstep(-edgeWidth, edgeWidth, sdf);
output.color = float4(shapeColor * shape, shape);
}
}

Common Use Cases

Vector Graphics

bwsl
// High-quality vector shape rendering
float d = sdfShape(uv);
float aa = length(float2(ddx_fine(d), ddy_fine(d))) * 0.707;
float alpha = smoothstep(aa, -aa, d);

Text Rendering

bwsl
// Sharp text edges
float distance = sample(fontSDF, uv).a;
float edge = 0.5;
float dx = ddx_fine(distance);
float dy = ddy_fine(distance);
float toPixels = 8.0 * rsqrt(dx * dx + dy * dy);
float alpha = saturate((distance - edge) * toPixels + 0.5);

Procedural Patterns

bwsl
// Consistent pattern scale regardless of view
float pattern = sin(worldPos.x * 50.0);
float patternDerivY = ddy_fine(pattern);
float filterWidth = abs(patternDerivY);

UI Elements

bwsl
// Clean UI borders
float border = abs(uv.x - 0.5) - borderWidth;
float aaWidth = max(ddx_fine(border), ddy_fine(border));
float mask = smoothstep(aaWidth, -aaWidth, border);

Use with ddx_fine

When calculating gradient magnitudes, pair ddy_fine with ddx_fine for consistent precision in both directions.

Performance

Fine derivatives may have a slight performance cost compared to coarse derivatives on some hardware. Use only when quality is critical.

Compiled Output

When compiled to GLSL:

Uses the target backend's native fine y-derivative operation when derivative control is available.

When compiled to HLSL:

hlsl
ddy_fine(x)

When compiled to SPIR-V:

Uses OpDPdyFine instruction.

See Also